Skip to content

Commit

Permalink
move GetNumSamplesWithLabel from node to network.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dong Yu committed Aug 4, 2015
1 parent ee05ee3 commit 2a1c90d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
39 changes: 39 additions & 0 deletions MachineLearning/CNTK/ComputationNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,45 @@ class ComputationNetwork
}
}

//this is a temp solution since some nodes such as plus can be just aggregate of two scalar values
//in which case the packing info is not available (and not meaningful) for them
size_t GetNumSamplesWithLabel(const size_t numAllSamples)
{
if (!m_SentenceBoundary.IsEmpty() &&
!m_minibatchPackingFlag.size() == 0)
{
size_t numTimeSteps = m_SentenceBoundary.GetNumCols();
size_t numSequences = m_SentenceBoundary.GetNumRows();

if (m_minibatchPackingFlag.size() != numTimeSteps)
{
LogicError("GetNumSamplesWithLabel(): m_minibatchPackingFlag should have one element for each timestep of all streams.Check feature reader. ");
}

size_t numSamplesWithoutLabel = 0;

for (size_t j = 0; j < numTimeSteps; j++)
{
if (m_minibatchPackingFlag[j] & MinibatchPackingFlag::NoLabel)
{
for (int i = 0; i < numSequences; i++)
{
if ((int)(m_SentenceBoundary(i, j)) & NO_LABEL)
{
numSamplesWithoutLabel++;
}
}
}
}

return numTimeSteps*numSequences - numSamplesWithoutLabel;
}
else
{
return numAllSamples;
}
}

// Read a matrix stored in text format from 'filePath' (whitespace-separated columns, newline-separated rows),
// and return a flat array containing the contents of this file in column-major format.
// filePath: path to file containing matrix in text format.
Expand Down
2 changes: 2 additions & 0 deletions MachineLearning/CNTK/ComputationNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
return processedExistsNoLabelorFeatureMissing;
}

/*
virtual size_t GetNumSamplesWithLabel(const size_t numAllSamples)
{
if (m_sentenceSeg != nullptr &&
Expand Down Expand Up @@ -344,6 +345,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
return numAllSamples;
}
}
*/

void SetLoopId(const int id)
{
Expand Down
2 changes: 1 addition & 1 deletion MachineLearning/CNTK/SGD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ class SGD : ComputationNetworkHelper<ElemType>
//for now since we share the same label masking flag we call this on the training
//criterion node ony. Later, when we apply different labels on different nodes
//we need to add code to call this function multiple times, one for each criteria node
size_t numSamplesWithLabel = (*criterionNodes)[0]->GetNumSamplesWithLabel(actualMBSize);
size_t numSamplesWithLabel = net.GetNumSamplesWithLabel(actualMBSize);

std::vector<ElemType> mbEvalErrors(numEvalNodes, 0);
for (size_t i = 0; i < numEvalNodes; i++)
Expand Down
2 changes: 1 addition & 1 deletion MachineLearning/CNTK/SimpleEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace Microsoft {
//for now since we share the same label masking flag we call this on one node only
//Later, when we apply different labels on different nodes
//we need to add code to call this function multiple times, one for each criteria node
size_t numSamplesWithLabel = evalNodes[0]->GetNumSamplesWithLabel(actualMBSize);
size_t numSamplesWithLabel = m_net.GetNumSamplesWithLabel(actualMBSize);
for (int i = 0; i<evalNodes.size(); i++)
{
m_net.Evaluate(evalNodes[i]);
Expand Down

0 comments on commit 2a1c90d

Please sign in to comment.