Skip to content

Commit

Permalink
replace CriteriaNodes to CriterionNodes in NDL parser, model persiste…
Browse files Browse the repository at this point in the history
…nce, samples, and book, while keeping it compatible with old NDL and model files.
  • Loading branch information
Dong Yu committed Dec 3, 2015
1 parent 93a0872 commit d30cf43
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Common/CheckInSuites/MNIST/Example.ndl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ndlFull=[
ErrPredict=ErrorPrediction(labels, Plus2)
FeatureNodes=(features)
LabelNodes=(labels)
CriteriaNodes=(CE)
CriterionNodes=(CE)
EvalNodes=(ErrPredict)
OutputNodes=(Plus2)
]
Expand Down Expand Up @@ -359,6 +359,6 @@ ndlMacroUseMask=[

# rootNodes defined here
OutputNodes=(O)
CriteriaNodes=(CE)
CriterionNodes=(CE)
EvaluationNodes(Err)
]
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ LabelNodes=(labels)

\begin_layout Plain Layout

CriteriaNodes=(CE)
CriterionNodes=(CE)
\end_layout

\begin_layout Plain Layout
Expand Down Expand Up @@ -362,7 +362,7 @@ Variable names may be any alphanumeric sequence that starts with a letter
cannot be used for a variable.
The special node names
\emph on
FeatureNodes, LabelNodes, CriteriaNodes, EvalNodes, OutputNodes
FeatureNodes, LabelNodes, CriterionNodes, EvalNodes, OutputNodes
\emph default
are also reserved and may not be used as variable names.
\end_layout
Expand Down Expand Up @@ -679,7 +679,7 @@ LabelNodes=(labels)

\begin_layout Plain Layout

CriteriaNodes=(CE)
CriterionNodes=(CE)
\end_layout

\begin_layout Plain Layout
Expand Down Expand Up @@ -1258,7 +1258,7 @@ LabelNodes=(labels)

\begin_layout Plain Layout

CriteriaNodes=(CE)
CriterionNodes=(CE)
\end_layout

\begin_layout Plain Layout
Expand Down
4 changes: 2 additions & 2 deletions ExampleSetups/NDLExamples.ndl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ndlFull=[
ErrPredict=ErrorPrediction(labels, Plus2)
FeatureNodes=(features)
LabelNodes=(labels)
CriteriaNodes=(CE)
CriterionNodes=(CE)
EvalNodes=(ErrPredict)
OutputNodes=(Plus2)
]
Expand Down Expand Up @@ -472,6 +472,6 @@ ndlMacroUseMask=[

# rootNodes defined here
OutputNodes=(O)
CriteriaNodes=(CE)
CriterionNodes=(CE)
EvaluationNodes(Err)
]
3 changes: 2 additions & 1 deletion MachineLearning/CNTK/NDLUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ namespace Microsoft { namespace MSR { namespace CNTK {
// handle the alternate way of specifying nodes, the array of nodes method
CheckOutputNodes(script, "FeatureNodes", m_net->FeatureNodes());
CheckOutputNodes(script, "LabelNodes", m_net->LabelNodes());
CheckOutputNodes(script, "CriteriaNodes", m_net->FinalCriterionNodes());
CheckOutputNodes(script, "CriterionNodes", m_net->FinalCriterionNodes());
CheckOutputNodes(script, "CriteriaNodes", m_net->FinalCriterionNodes()); //legacy
CheckOutputNodes(script, "EvalNodes", m_net->EvaluationNodes());
CheckOutputNodes(script, "OutputNodes", m_net->OutputNodes());
}
Expand Down
13 changes: 11 additions & 2 deletions MachineLearning/CNTK/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,24 @@ void TestConfiguration(const ConfigParameters& configBase)
}
}

if (configRoots.Exists("CriteriaNodes"))
if (configRoots.Exists("CriterionNodes"))
{
configNode = configRoots("CriteriaNodes");
configNode = configRoots("CriterionNodes");
for (size_t i=0; i<configNode.size(); i++)
{
std::wstring nodeName = configNode[i];
}
}

if (configRoots.Exists("CriteriaNodes")) //legacy
{
configNode = configRoots("CriteriaNodes");
for (size_t i = 0; i<configNode.size(); i++)
{
std::wstring nodeName = configNode[i];
}
}

if (configRoots.Exists("NodesReqMultiSeqHandling"))
{
configNode = configRoots("NodesReqMultiSeqHandling");
Expand Down
84 changes: 49 additions & 35 deletions MachineLearning/CNTKComputationNetworkLib/ComputationNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ namespace Microsoft { namespace MSR { namespace CNTK {
fstream << m_labels[i]->NodeName();
fstream.PutMarker(FileMarker::fileMarkerEndSection, L"ELabelNodes");

fstream.PutMarker(FileMarker::fileMarkerBeginSection, L"BCriteriaNodes");
fstream.PutMarker(FileMarker::fileMarkerBeginSection, L"BCriterionNodes");
fstream << m_finalCriteria.size();
for (size_t i = 0; i < m_finalCriteria.size(); i++)
fstream << m_finalCriteria[i]->NodeName();
fstream.PutMarker(FileMarker::fileMarkerEndSection, L"ECriteriaNodes");
fstream.PutMarker(FileMarker::fileMarkerEndSection, L"ECriterionNodes");

fstream.PutMarker(FileMarker::fileMarkerBeginSection, L"BEvalNodes");
fstream << m_evalNodes.size();
Expand Down Expand Up @@ -323,64 +323,78 @@ namespace Microsoft { namespace MSR { namespace CNTK {
wstring nodeName;
size_t num;

fstream.GetMarker(FileMarker::fileMarkerBeginSection, L"BFeatureNodes");
fstream >> num;

for (size_t i = 0; i < num; i++)
if (fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BFeatureNodes"))
{
fstream >> nodeName;
m_features.push_back(GetNodeFromName(nodeName));
}
fstream >> num;

fstream.GetMarker(FileMarker::fileMarkerEndSection, L"EFeatureNodes");
for (size_t i = 0; i < num; i++)
{
fstream >> nodeName;
m_features.push_back(GetNodeFromName(nodeName));
}

fstream.GetMarker(FileMarker::fileMarkerEndSection, L"EFeatureNodes");
}

fstream.GetMarker(FileMarker::fileMarkerBeginSection, L"BLabelNodes");
fstream >> num;
for (size_t i = 0; i < num; i++)
if (fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BLabelNodes"))
{
fstream >> nodeName;
m_labels.push_back(GetNodeFromName(nodeName));
fstream >> num;
for (size_t i = 0; i < num; i++)
{
fstream >> nodeName;
m_labels.push_back(GetNodeFromName(nodeName));
}
}

fstream.GetMarker(FileMarker::fileMarkerEndSection, L"ELabelNodes");

fstream.GetMarker(FileMarker::fileMarkerBeginSection, L"BCriteriaNodes");
fstream >> num;
for (size_t i = 0; i < num; i++)
if (fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BCriterionNodes") ||
fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BCriteriaNodes" /*legacy*/))
{
fstream >> nodeName;
m_finalCriteria.push_back(GetNodeFromName(nodeName));
}
fstream >> num;
for (size_t i = 0; i < num; i++)
{
fstream >> nodeName;
m_finalCriteria.push_back(GetNodeFromName(nodeName));
}

fstream.GetMarker(FileMarker::fileMarkerEndSection, L"ECriteriaNodes");
if (!fstream.TryGetMarker(FileMarker::fileMarkerEndSection, L"ECriteriaNodes" /*legacy*/))
{
fstream.GetMarker(FileMarker::fileMarkerEndSection, L"ECriterionNodes"); //check legacy first so err msg will use new name
}
}

// TODO: this section is defunct
if (fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BNodesReqMultiSeqHandling"))
{
fprintf(stderr, "WARNING: Ignoring defunct 'BNodesReqMultiSeqHandling' section in input file.\n");
fstream >> num;
for (size_t i = 0; i<num; i++)
for (size_t i = 0; i < num; i++)
fstream >> nodeName;
fstream.GetMarker(FileMarker::fileMarkerEndSection, L"ENodesReqMultiSeqHandling");
}

fstream.GetMarker(FileMarker::fileMarkerBeginSection, L"BEvalNodes");
fstream >> num;
for (size_t i = 0; i < num; i++)
if (fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BEvalNodes"))
{
fstream >> nodeName;
m_evalNodes.push_back(GetNodeFromName(nodeName));
fstream >> num;
for (size_t i = 0; i < num; i++)
{
fstream >> nodeName;
m_evalNodes.push_back(GetNodeFromName(nodeName));
}
fstream.GetMarker(FileMarker::fileMarkerEndSection, L"EEvalNodes");
}
fstream.GetMarker(FileMarker::fileMarkerEndSection, L"EEvalNodes");

fstream.GetMarker(FileMarker::fileMarkerBeginSection, L"BOutputNodes");
fstream >> num;
for (size_t i = 0; i < num; i++)
if (fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BOutputNodes"))
{
fstream >> nodeName;
m_outputNodes.push_back(GetNodeFromName(nodeName));
fstream >> num;
for (size_t i = 0; i < num; i++)
{
fstream >> nodeName;
m_outputNodes.push_back(GetNodeFromName(nodeName));
}
fstream.GetMarker(FileMarker::fileMarkerEndSection, L"EOutputNodes");
}
fstream.GetMarker(FileMarker::fileMarkerEndSection, L"EOutputNodes");

if (fstream.TryGetMarker(FileMarker::fileMarkerBeginSection, L"BPairNodes"))
{
Expand Down

0 comments on commit d30cf43

Please sign in to comment.