Skip to content

Commit

Permalink
marked CRFNode as #ifdef COMING_SOON
Browse files Browse the repository at this point in the history
  • Loading branch information
frankseide committed Jan 22, 2016
1 parent 198d64d commit b0bbc0c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 31 deletions.
2 changes: 2 additions & 0 deletions Source/CNTK/NetworkDescriptionLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ bool CheckFunction(std::string& p_nodeType, bool* allowUndeterminedVariable)
bool ret = false;
if (EqualInsensitive(nodeType, OperationNameOf(AveragePoolingNode))) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(BatchNormalizationNode))) ret = true;
#ifdef COMING_SOON
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(ConvolutionNode), L"Convolve")) ret = true;
else if (EqualInsensitive(nodeType, OperationNameOf(CosDistanceNode), L"CosDist")) ret = true;
Expand Down
32 changes: 14 additions & 18 deletions Source/CNTK/SimpleNetworkBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,10 +1688,12 @@ shared_ptr<ComputationNode<ElemType>> SimpleNetworkBuilder<ElemType>::AddTrainAn
tinput = builder.Times(matrix, input);
output = builder.Logistic(label, tinput, (trainNodeName == L"") ? L"Logistic" : trainNodeName);
break;
#ifdef COMING_SOON
case TrainingCriterion::CRF:
assert(trans != nullptr);
output = builder.CRF(label, input, trans, (trainNodeName == L"") ? L"CRF" : trainNodeName);
break;
#endif
case TrainingCriterion::ClassCrossEntropyWithSoftmax:
output = builder.ClassCrossEntropyWithSoftmax(label, input, matrix, clspostprob, (trainNodeName == L"") ? L"ClassCrossEntropyWithSoftmax" : trainNodeName);
break;
Expand Down Expand Up @@ -1743,12 +1745,14 @@ shared_ptr<ComputationNode<ElemType>> SimpleNetworkBuilder<ElemType>::AddTrainAn
tinput = builder.Times(matrix, input);
output = builder.ErrorPrediction(label, tinput, (evalNodeName == L"") ? L"EvalErrorPrediction" : evalNodeName);
break;
#ifdef COMING_SOON
case EvalCriterion::CRF:
assert(trans != nullptr);
if (matrix != nullptr && tinput == input)
tinput = builder.Times(matrix, input);
output = builder.CRF(label, tinput, trans, (evalNodeName == L"") ? L"EvalCRF" : evalNodeName);
break;
#endif
default:
LogicError("Unsupported training criterion.");
}
Expand All @@ -1769,14 +1773,10 @@ template class SimpleNetworkBuilder<double>;

TrainingCriterion ParseTrainingCriterionString(wstring s)
{
if (!_wcsicmp(s.c_str(), L"crossEntropyWithSoftmax"))
return TrainingCriterion::CrossEntropyWithSoftmax;
if (!_wcsicmp(s.c_str(), L"sequenceWithSoftmax"))
return TrainingCriterion::SequenceWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"squareError"))
return TrainingCriterion::SquareError;
else if (!_wcsicmp(s.c_str(), L"logistic"))
return TrainingCriterion::Logistic;
if (!_wcsicmp(s.c_str(), L"crossEntropyWithSoftmax")) return TrainingCriterion::CrossEntropyWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"sequenceWithSoftmax")) return TrainingCriterion::SequenceWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"squareError")) return TrainingCriterion::SquareError;
else if (!_wcsicmp(s.c_str(), L"logistic")) return TrainingCriterion::Logistic;
else if (!_wcsicmp(s.c_str(), L"noiseContrastiveEstimation") || !_wcsicmp(s.c_str(), L"noiseContrastiveEstimationNode" /*spelling error, deprecated*/))
return TrainingCriterion::NCECrossEntropyWithSoftmax;
else if (!!_wcsicmp(s.c_str(), L"classCrossEntropyWithSoftmax")) // (twisted logic to keep compiler happy w.r.t. not returning from LogicError)
Expand All @@ -1786,20 +1786,16 @@ TrainingCriterion ParseTrainingCriterionString(wstring s)

EvalCriterion ParseEvalCriterionString(wstring s)
{
if (!_wcsicmp(s.c_str(), L"errorPrediction"))
return EvalCriterion::ErrorPrediction;
else if (!_wcsicmp(s.c_str(), L"crossEntropyWithSoftmax"))
return EvalCriterion::CrossEntropyWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"sequenceWithSoftmax"))
return EvalCriterion::SequenceWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"classCrossEntropyWithSoftmax"))
return EvalCriterion::ClassCrossEntropyWithSoftmax;
if (!_wcsicmp(s.c_str(), L"errorPrediction")) return EvalCriterion::ErrorPrediction;
else if (!_wcsicmp(s.c_str(), L"crossEntropyWithSoftmax")) return EvalCriterion::CrossEntropyWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"sequenceWithSoftmax")) return EvalCriterion::SequenceWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"classCrossEntropyWithSoftmax")) return EvalCriterion::ClassCrossEntropyWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"logistic")) return EvalCriterion::Logistic;
else if (!_wcsicmp(s.c_str(), L"noiseContrastiveEstimation") || !_wcsicmp(s.c_str(), L"noiseContrastiveEstimationNode" /*spelling error, deprecated*/))
return EvalCriterion::NCECrossEntropyWithSoftmax;
else if (!_wcsicmp(s.c_str(), L"logistic"))
return EvalCriterion::Logistic;
else if (!!_wcsicmp(s.c_str(), L"squareError"))
LogicError("evalCriterion: Invalid trainingCriterion value. Valid values are (errorPrediction | crossEntropyWithSoftmax | squareError | logistic | sequenceWithSoftmax)");
return EvalCriterion::SquareError;
}

} } }
4 changes: 0 additions & 4 deletions Source/Common/Include/Sequences.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,6 @@ typedef MBLayout::MBLayoutPtr MBLayoutPtr;
// TODO: This will in the future be able to hold sub-ranges for nested loops as well.
// -----------------------------------------------------------------------

// TODO: We should also have a FrameRange that selects all frames of a single sequence. Currently now possible since that would require Matrix::RowSlice()
// - likewise, LSTMNode does its own iteration, hence needs access to GetNumParallelSequences() or NumCols() in the whole-batch iterator
// BUGBUG: These nodes are currently broken and will need to be fixed:
// - CRFNode does not support > 1 parallel sequence
class FrameRange
{
public: // TODO: make private (currently used from masking and DataFor) ; TODO: rename all members with m_ prefix
Expand Down
2 changes: 2 additions & 0 deletions Source/ComputationNetworkLib/ComputationNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ bool ComputationNetwork::IsTypicalCriterionNode(ComputationNodeBasePtr nodePtr)
nodePtr->OperationName() == OperationNameOf(CrossEntropyNode) ||
nodePtr->OperationName() == OperationNameOf(ClassBasedCrossEntropyWithSoftmaxNode) ||
nodePtr->OperationName() == OperationNameOf(ErrorPredictionNode) ||
#ifdef COMING_SOON
nodePtr->OperationName() == OperationNameOf(CRFNode) ||
#endif
nodePtr->OperationName() == OperationNameOf(DummyCriterionNode))
return true;

Expand Down
7 changes: 1 addition & 6 deletions Source/ComputationNetworkLib/ComputationNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,5 @@ typedef ComputationNetwork::ComputationNetworkPtr ComputationNetworkPtr;
// - code prettification:
// - sort all node implementations' methods into the same order; esp, ForwardProp() comes before partial
// - sort important nodes first; move unused/experimental nodes into source files named accordingly
// - finish the job:
// - everywhere complete folding ForwardPropS() into ForwardProp(FrameRange()), same for partial
// - revise node constructors, merge by means of default parameters
// - known issues that need actual test cases to be fixed:
// - CRFNode::BackpropTo() fails for >1 parallel sequence due to DataFor() not being able to return whole sequences
// - implement reading of MB Layout in Binary, DSSM, and LivbSVM readers --is DSSM already done?

} } }
10 changes: 8 additions & 2 deletions Source/ComputationNetworkLib/ComputationNetworkBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ template <class ElemType, class... _Types>
static shared_ptr<ComputationNode<ElemType>> CreateStandardNode(const std::wstring& nodeType, _Types&&... _Args)
{
// please keep this table sorted
if (nodeType == OperationNameOf(CRFNode)) return New<CRFNode<ElemType>>(forward<_Types>(_Args)...);
else if (nodeType == OperationNameOf(ClassBasedCrossEntropyWithSoftmaxNode))return New<ClassBasedCrossEntropyWithSoftmaxNode<ElemType>>(forward<_Types>(_Args)...);
#ifdef COMING_SOON
if (nodeType == OperationNameOf(CRFNode)) return New<CRFNode<ElemType>>(forward<_Types>(_Args)...);
else
#endif
if (nodeType == OperationNameOf(ClassBasedCrossEntropyWithSoftmaxNode))return New<ClassBasedCrossEntropyWithSoftmaxNode<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)...);
Expand Down Expand Up @@ -346,6 +349,7 @@ shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::Class
return net.AddNodeToNetAndAttachInputs(New<ClassBasedCrossEntropyWithSoftmaxNode<ElemType>>(net.GetDeviceId(), nodeName), label, prediction, input_weight, cls_log_post_prob);
}

#ifdef COMING_SOON
template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::CRF(const ComputationNodePtr label,
const ComputationNodePtr postDepScore,
Expand All @@ -354,6 +358,7 @@ shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::CRF(c
{
return net.AddNodeToNetAndAttachInputs(New<CRFNode<ElemType>>(net.GetDeviceId(), nodeName), label, postDepScore, transition_score);
}
#endif

template <class ElemType>
shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::DummyCriterion(const ComputationNodePtr objectives, const ComputationNodePtr derivatives, const ComputationNodePtr prediction, const std::wstring nodeName)
Expand Down Expand Up @@ -605,4 +610,5 @@ shared_ptr<ComputationNode<ElemType>> ComputationNetworkBuilder<ElemType>::Batch

template class ComputationNetworkBuilder<float>;
template class ComputationNetworkBuilder<double>;

} } }
2 changes: 2 additions & 0 deletions Source/ComputationNetworkLib/ComputationNetworkBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class ComputationNetworkBuilder
ComputationNodePtr AveragePooling(const ComputationNodePtr inputValues,
const size_t windowWidth, const size_t windowHeight, const size_t horizontalSubsample, const size_t verticalSubsample, ImageLayoutKind imageLayoutKind,
const std::wstring nodeName = L"");
#ifdef COMING_SOON
ComputationNodePtr CRF(const ComputationNodePtr label, const ComputationNodePtr postDepScore, const ComputationNodePtr transition_score, const std::wstring nodeName = L"");
#endif
ComputationNodePtr ClassCrossEntropyWithSoftmax(const ComputationNodePtr label, const ComputationNodePtr prediction, const ComputationNodePtr input_weight, const ComputationNodePtr cls_log_post_prob, const std::wstring nodeName = L"");
ComputationNodePtr Cos(const ComputationNodePtr a, const std::wstring nodeName = L"");
ComputationNodePtr CosDistance(const ComputationNodePtr a, const ComputationNodePtr b, const std::wstring nodeName = L"");
Expand Down
2 changes: 1 addition & 1 deletion Source/ComputationNetworkLib/ComputationNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ inline shared_ptr<C> New(_Types&&... _Args)

// =======================================================================
// ComputationNodeNonLooping -- abstract base class for computation nodes that do not implement eval/partial for individual frames
// Such as CRFNode, LSTMNode, ParallelNode, SequenceDecoderNode, TimeReverseNode (BatchModeNode), and TransposeNode.
// Such as CRFNode, SequenceDecoderNode, and training criteria.
// =======================================================================

// This will provide default implementations for those two functions that will fail at runtime with a meaningful error.
Expand Down
4 changes: 4 additions & 0 deletions Source/ComputationNetworkLib/TrainingNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,8 @@ class ClassBasedCrossEntropyWithSoftmaxNode : public ComputationNodeNonLooping /
template class ClassBasedCrossEntropyWithSoftmaxNode<float>;
template class ClassBasedCrossEntropyWithSoftmaxNode<double>;

#ifdef COMING_SOON

// -----------------------------------------------------------------------
// CRFNode (labels, position_dependent_scores, transition_scores)
// - labels: output label vector of [0:T-1]
Expand Down Expand Up @@ -1315,6 +1317,8 @@ class CRFNode : public ComputationNodeNonLooping /*ComputationNode*/<ElemType>,
int mEndLbl;
};

#endif

// -----------------------------------------------------------------------
// LogisticNode (labels, prediction, weight)
// calculates: -sum(left * log(right) + (1-left)*log(1-right)) (optionally * weight)
Expand Down

0 comments on commit b0bbc0c

Please sign in to comment.