Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Microsoft/CNTK into fseid…
Browse files Browse the repository at this point in the history
…e/seq2seqsample
  • Loading branch information
U-FAREAST\fseide committed Jun 2, 2016
2 parents 27c1636 + e718790 commit a287438
Show file tree
Hide file tree
Showing 30 changed files with 415 additions and 268 deletions.
12 changes: 6 additions & 6 deletions Source/ActionsLib/NetworkDescriptionLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ bool CheckFunction(std::string& p_nodeType, bool* allowUndeterminedVariable)
else if (EqualInsensitive(nodeType, OperationNameOf(CRFNode), L"CRF")) ret = true;
#endif
else if (EqualInsensitive(nodeType, OperationNameOf(ClassBasedCrossEntropyWithSoftmaxNode), L"CBCEWithSM")) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ComparisonEqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ComparisonGreaterEqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ComparisonGreaterNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ComparisonLessEqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ComparsionLessNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ComparisonNotEqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(EqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(GreaterEqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(GreaterNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(LessEqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(LessNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(NotEqualNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ClipNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(ConvolutionNode), L"Convolve")) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(PoolingNode))) ret = true;
Expand Down
5 changes: 4 additions & 1 deletion Source/ActionsLib/TrainActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ template <class C>
shared_ptr<C> CreateObject(const ConfigParameters& config, const wchar_t* id)
{
ConfigParameters readerConfig(config(id));
readerConfig.Insert("traceLevel", config(L"traceLevel", "0")); // TODO: fix this by adding it to all config blocks. Easy to fix in BS as 'config with [ traceLevel = 0 ]'.
if (!readerConfig.ExistsCurrent("traceLevel")) // do not overwrite "traceLevel" if it's already present
{
readerConfig.Insert("traceLevel", config(L"traceLevel", "0")); // TODO: fix this by adding it to all config blocks. Easy to fix in BS as 'config with [ traceLevel = 0 ]'.
}
return make_shared<C>(readerConfig); // old CNTK config specifies a dictionary which then must be explicitly instantiated
}

Expand Down
4 changes: 1 addition & 3 deletions Source/CNTK/CNTK.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
<ClInclude Include="..\Common\Include\Basics.h" />
<ClInclude Include="..\Common\Include\BestGpu.h" />
<ClInclude Include="..\Common\Include\DataReader.h" />
<ClInclude Include="..\Common\Include\CompositeDataReader.h" />
<ClInclude Include="..\Common\Include\ExceptionWithCallStack.h" />
<ClInclude Include="..\Common\Include\StringUtil.h" />
<ClInclude Include="..\Common\Include\TensorShape.h" />
Expand All @@ -165,6 +164,7 @@
<ClInclude Include="..\Math\Matrix.h" />
<ClInclude Include="..\ComputationNetworkLib\PreComputeNodes.h" />
<ClInclude Include="..\ComputationNetworkLib\MatrixPool.h" />
<ClInclude Include="..\Readers\CompositeDataReader\CompositeDataReader.h" />
<ClInclude Include="..\Readers\ReaderLib\BlockRandomizer.h" />
<ClInclude Include="..\Readers\ReaderLib\Bundler.h" />
<ClInclude Include="..\Readers\ReaderLib\ChunkRandomizer.h" />
Expand All @@ -173,12 +173,10 @@
<ClInclude Include="..\Readers\ReaderLib\NoRandomizer.h" />
<ClInclude Include="..\Readers\ReaderLib\Packer.h" />
<ClInclude Include="..\Readers\ReaderLib\Reader.h" />
<ClInclude Include="..\Readers\ReaderLib\SampleModePacker.h" />
<ClInclude Include="..\Readers\ReaderLib\SequencePacker.h" />
<ClInclude Include="..\Readers\ReaderLib\SequenceRandomizer.h" />
<ClInclude Include="..\Readers\ReaderLib\StringToIdMap.h" />
<ClInclude Include="..\Readers\ReaderLib\Transformer.h" />
<ClInclude Include="..\Readers\ReaderLib\TransformerBase.h" />
<ClInclude Include="..\SGDLib\DataReaderHelpers.h" />
<ClInclude Include="..\SGDLib\SGD.h" />
<ClInclude Include="..\SGDLib\SimpleEvaluator.h" />
Expand Down
6 changes: 0 additions & 6 deletions Source/CNTK/CNTK.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@
<ClInclude Include="..\Readers\ReaderLib\Reader.h">
<Filter>from ReaderLib</Filter>
</ClInclude>
<ClInclude Include="..\Readers\ReaderLib\SampleModePacker.h">
<Filter>from ReaderLib</Filter>
</ClInclude>
<ClInclude Include="..\Readers\ReaderLib\SequencePacker.h">
<Filter>from ReaderLib</Filter>
</ClInclude>
Expand All @@ -208,9 +205,6 @@
<ClInclude Include="..\Readers\ReaderLib\Transformer.h">
<Filter>from ReaderLib</Filter>
</ClInclude>
<ClInclude Include="..\Readers\ReaderLib\TransformerBase.h">
<Filter>from ReaderLib</Filter>
</ClInclude>
<ClInclude Include="..\Common\Include\CompositeDataReader.h">
<Filter>Common\Include</Filter>
</ClInclude>
Expand Down
26 changes: 13 additions & 13 deletions Source/ComputationNetworkLib/ComputationNetworkBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ static shared_ptr<ComputationNode<ElemType>> CreateStandardNode(const std::wstri
if (nodeType == OperationNameOf(AbsNode)) return New<AbsNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ClassBasedCrossEntropyWithSoftmaxNode))return New<ClassBasedCrossEntropyWithSoftmaxNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ClipNode)) return New<ClipNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ComparisonEqualNode)) return New<ComparisonEqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ComparisonGreaterEqualNode)) return New<ComparisonGreaterEqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ComparisonGreaterNode)) return New<ComparisonGreaterNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ComparisonLessEqualNode)) return New<ComparisonLessEqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ComparsionLessNode)) return New<ComparsionLessNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ComparisonNotEqualNode)) return New<ComparisonNotEqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(CosDistanceNode)) return New<CosDistanceNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(EqualNode)) return New<EqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(GreaterEqualNode)) return New<GreaterEqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(GreaterNode)) return New<GreaterNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(LessEqualNode)) return New<LessEqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(LessNode)) return New<LessNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(NotEqualNode)) return New<NotEqualNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(CosDistanceNode)) return New<CosDistanceNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(CosDistanceWithNegativeSamplesNode)) return New<CosDistanceWithNegativeSamplesNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(CosineNode)) return New<CosineNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(CrossEntropyNode)) return New<CrossEntropyNode<ElemType>>(forward<_Types>(_Args)...);
Expand Down Expand Up @@ -646,37 +646,37 @@ shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::Plus(
template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::Less(const ComputationNodePtr a, const ComputationNodePtr b, const std::wstring nodeName)
{
return net.AddNodeToNetAndAttachInputs(New<ComparsionLessNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
return net.AddNodeToNetAndAttachInputs(New<LessNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
}

template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::Equal(const ComputationNodePtr a, const ComputationNodePtr b, const std::wstring nodeName)
{
return net.AddNodeToNetAndAttachInputs(New<ComparisonEqualNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
return net.AddNodeToNetAndAttachInputs(New<EqualNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
}

template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::Greater(const ComputationNodePtr a, const ComputationNodePtr b, const std::wstring nodeName)
{
return net.AddNodeToNetAndAttachInputs(New<ComparisonGreaterNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
return net.AddNodeToNetAndAttachInputs(New<GreaterNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
}

template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::GreaterEqual(const ComputationNodePtr a, const ComputationNodePtr b, const std::wstring nodeName)
{
return net.AddNodeToNetAndAttachInputs(New<ComparsionLessNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
return net.AddNodeToNetAndAttachInputs(New<LessNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
}

template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::NotEqual(const ComputationNodePtr a, const ComputationNodePtr b, const std::wstring nodeName)
{
return net.AddNodeToNetAndAttachInputs(New<ComparisonEqualNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
return net.AddNodeToNetAndAttachInputs(New<EqualNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
}

template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::LessEqual(const ComputationNodePtr a, const ComputationNodePtr b, const std::wstring nodeName)
{
return net.AddNodeToNetAndAttachInputs(New<ComparisonGreaterNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
return net.AddNodeToNetAndAttachInputs(New<GreaterNode<ElemType>>(net.GetDeviceId(), nodeName), { a, b });
}

template <class ElemType>
Expand Down
32 changes: 16 additions & 16 deletions Source/ComputationNetworkLib/NonlinearityNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,20 +578,20 @@ class ComparisonNode : public BinaryElementWiseNode<ElemType>
// Index corresponds to different comparison operations.
const static int index = 1 + compType + 3 * polarity;

// The operations are indexed in the same order they appear in enum ElementWiseOperator: "Less", "Equal", "Greater", "GreaterEqual", "NotEqual", "LessEqual".
// This ordering is checked below:
static_assert(1 == ElementWiseOperator::opEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opEQ has wrong value relative to ElementWiseOperator::opLess");
static_assert(2 == ElementWiseOperator::opGreater - ElementWiseOperator::opLess, "ElementWiseOperator::opGT has wrong value relative to ElementWiseOperator::opLess");
static_assert(3 == ElementWiseOperator::opGreaterEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opGE has wrong value relative to ElementWiseOperator::opLess");
static_assert(4 == ElementWiseOperator::opNotEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opNE has wrong value relative to ElementWiseOperator::opLess");
static_assert(5 == ElementWiseOperator::opLessEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opLE has wrong value relative to ElementWiseOperator::opLess");
// The operations are indexed in the same order they appear in enum ElementWiseOperator: "Less", "Equal", "Greater", "GreaterEqual", "NotEqual", "LessEqual".
// This ordering is checked below:
static_assert(1 == ElementWiseOperator::opEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opEqual has wrong value relative to ElementWiseOperator::opLess");
static_assert(2 == ElementWiseOperator::opGreater - ElementWiseOperator::opLess, "ElementWiseOperator::opGreater has wrong value relative to ElementWiseOperator::opLess");
static_assert(3 == ElementWiseOperator::opGreaterEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opGreaterEqual has wrong value relative to ElementWiseOperator::opLess");
static_assert(4 == ElementWiseOperator::opNotEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opNotEqual has wrong value relative to ElementWiseOperator::opLess");
static_assert(5 == ElementWiseOperator::opLessEqual - ElementWiseOperator::opLess, "ElementWiseOperator::opLessEqual has wrong value relative to ElementWiseOperator::opLess");

public:
typedef BinaryElementWiseNode<ElemType> Base; UsingBinaryElementwiseNodeBaseMembers;

static const std::wstring TypeName()
{
const wchar_t* names[] = { L"Less", L"Equal", L"Greater", L"GreaterEqual", L"NotEqual", L"LessEqual" };
const wchar_t* names[] = { L"Less", L"Equal", L"Greater", L"GreaterEqual", L"NotEqual", L"LessEqual" };
return names[index];
}

Expand Down Expand Up @@ -634,17 +634,17 @@ public: \
DeclareConstructorFromConfigWithNumInputs(ClassName); \
ClassName(DEVICEID_TYPE deviceId, const wstring& name) \
: Base(deviceId, name) \
{ \
} \
{ \
} \
}; \
\
template class ClassName<float>; \
template class ClassName<double>;

DefineComparisonNode(ComparsionLessNode, -1, 0)
DefineComparisonNode(ComparisonEqualNode, 0, 0)
DefineComparisonNode(ComparisonGreaterNode, 1, 0)
DefineComparisonNode(ComparisonGreaterEqualNode, -1, 1)
DefineComparisonNode(ComparisonNotEqualNode, 0, 1)
DefineComparisonNode(ComparisonLessEqualNode, 1, 1)
DefineComparisonNode(LessNode, -1, 0)
DefineComparisonNode(EqualNode, 0, 0)
DefineComparisonNode(GreaterNode, 1, 0)
DefineComparisonNode(GreaterEqualNode, -1, 1)
DefineComparisonNode(NotEqualNode, 0, 1)
DefineComparisonNode(LessEqualNode, 1, 1)
}}}
4 changes: 3 additions & 1 deletion Source/Readers/CNTKTextFormatReader/TextConfigHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ TextConfigHelper::TextConfigHelper(const ConfigParameters& config)

m_filepath = msra::strfun::utf16(config(L"file"));

// EvalActions inserts randomize = "none" into the reader config in DoWriteOutoput.
wstring randomizeString = config(L"randomize", wstring());
if (!_wcsicmp(randomizeString.c_str(), L"none")) // TODO: don't support case-insensitive option strings in the new reader
{
// "none" is only accepted to be backwards-compatible (DoWriteOutput() in EvalActions.cpp
// inserts this magic constant into the reader config to prevent it from shuffling the input).
// In user-defined configurations, 'randomize' should be a boolean.
m_randomizationWindow = randomizeNone;
}
else
Expand Down
5 changes: 3 additions & 2 deletions Source/Readers/CNTKTextFormatReader/TextParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,9 @@ bool TextParser<ElemType>::TryGetInputId(size_t& id, size_t& bytesToRead)
if (ShouldWarn())
{
fprintf(stderr,
"WARNING: Invalid input name ('%s') %ls.\n",
name.c_str(), GetFileInfo().c_str());
"WARNING: Invalid input ('%s') %ls. "
"Input name '%s' was not specified in the reader config section.\n",
name.c_str(), GetFileInfo().c_str(), name.c_str());
}
}
else if (ShouldWarn())
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ WARNING: Maximum per-input number of samples for sequence (id = 2) at offset 452
INFO: Finished loading sequence (id = 2) at offset 452 in the input file (invalid_input.txt), successfully read 14 out of expected 14 rows.
WARNING: Input name prefix ('|') is followed by an invalid character (' ') at offset 472 in the input file (invalid_input.txt).
WARNING: Input name prefix ('|') is followed by an invalid character (' ') at offset 503 in the input file (invalid_input.txt).
WARNING: Invalid input name ('C') at offset 569 in the input file (invalid_input.txt).
WARNING: Invalid input ('C') at offset 569 in the input file (invalid_input.txt). Input name 'C' was not specified in the reader config section.
WARNING: Empty input row at offset 575 in the input file (invalid_input.txt).
WARNING: Could not read a row (# 9) while loading sequence (id = 3) at offset 575 in the input file (invalid_input.txt).
WARNING: Exhausted all input expected for the current sequence (id = 3) at offset 575 in the input file (invalid_input.txt), but only read 8 out of 9 expected rows.
Expand Down
10 changes: 5 additions & 5 deletions contrib/Python/cntk/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def _parse_result_output(output):
continue
else:
data = LocalExecutionContext._sanitized_asarray(
data).reshape(shape, order='F')
data).reshape(shape, order='C')

tensor_seq.append(data)

Expand Down Expand Up @@ -755,12 +755,12 @@ def eval(self, node, input_map=None, backward_pass=False, input_name=None):
action_name = action_name)

out_name = os.path.join(self.directory, CNTK_OUTPUT_FILENAME + '.')
node.tag = orig_node_tag
if backward_pass:
n = input_name.name if isinstance(
input_name, ComputationNode) else input_name
n = input_name.name if isinstance(input_name, ComputationNode)\
else input_name
out_name += n + '.grad'
else:
node.tag = orig_node_tag
else:
out_name += node.name

result_content = open(out_name).read()
Expand Down
Loading

0 comments on commit a287438

Please sign in to comment.