updating sentence boundary mark for Kaldi2Reader, HTKMLFReader and KaldiReader
This commit is contained in:
Родитель
4b9c8b25fc
Коммит
a0bb630616
|
@ -832,13 +832,13 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
{
|
||||
m_sentenceBegin.Resize((size_t)1, (size_t)feat.cols());
|
||||
m_minibatchPackingFlag.resize(feat.cols());
|
||||
m_sentenceBegin.SetValue((ElemType) SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType) SENTENCE_BEGIN);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SENTENCE_END);
|
||||
m_sentenceBegin.SetValue((ElemType) SEQUENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType) SEQUENCE_START);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SEQUENCE_END);
|
||||
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::UtteranceEnd;
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::SequenceEnd;
|
||||
first = false;
|
||||
}
|
||||
|
||||
|
@ -993,12 +993,12 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
m_sentenceBegin.Resize(m_numberOfuttsPerMinibatch, m_mbSize);
|
||||
m_minibatchPackingFlag.resize(m_mbSize);
|
||||
|
||||
//mtSentenceBegin.SetValue((ElemType) SENTENCE_MIDDLE);
|
||||
//mtSentenceBegin.SetValue((ElemType) SEQUENCE_MIDDLE);
|
||||
for (size_t i = 0; i < m_numberOfuttsPerMinibatch; i++)
|
||||
{
|
||||
for (size_t j = 0; j < m_mbSize; j++)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i,j,(ElemType) SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(i,j,(ElemType) SEQUENCE_MIDDLE);
|
||||
}
|
||||
}
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
|
@ -1017,8 +1017,8 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
m_switchFrame[i] = m_mbSize+1;
|
||||
if (m_processedFrame[i] == 1)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SENTENCE_END);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceEnd;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SEQUENCE_END);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceEnd;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1026,8 +1026,8 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
{
|
||||
m_switchFrame[i] = 0;
|
||||
m_sentenceEnd[i] = true;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceStart;
|
||||
|
||||
}
|
||||
actualmbsize[i] = m_mbSize;
|
||||
|
@ -1181,13 +1181,13 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
m_switchFrame[i] = actualmbsize[i];
|
||||
if (actualmbsize[i] < m_mbSize)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i], (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[actualmbsize[i]] = m_minibatchPackingFlag[actualmbsize[i]] | MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i], (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[actualmbsize[i]] = m_minibatchPackingFlag[actualmbsize[i]] | MinibatchPackingFlag::SequenceStart;
|
||||
}
|
||||
if (actualmbsize[i] == m_mbSize)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i]-1, (ElemType)SENTENCE_END);
|
||||
m_minibatchPackingFlag[actualmbsize[i]] = m_minibatchPackingFlag[actualmbsize[i]-1] | MinibatchPackingFlag::UtteranceEnd;
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i]-1, (ElemType)SEQUENCE_END);
|
||||
m_minibatchPackingFlag[actualmbsize[i]] = m_minibatchPackingFlag[actualmbsize[i]-1] | MinibatchPackingFlag::SequenceEnd;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1339,13 +1339,13 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
m_sentenceBegin.Resize((size_t)1, (size_t)feat.cols());
|
||||
m_minibatchPackingFlag.resize((size_t)feat.cols());
|
||||
|
||||
m_sentenceBegin.SetValue((ElemType)SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType)SENTENCE_BEGIN);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SENTENCE_END);
|
||||
m_sentenceBegin.SetValue((ElemType)SEQUENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType)SEQUENCE_START);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SEQUENCE_END);
|
||||
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::UtteranceEnd;
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::SequenceEnd;
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public:
|
|||
/// n_length is the maximum lenght of each stream
|
||||
/// for example, two sentences used in parallel in one minibatch would be
|
||||
/// [2 x 5] if the max length of one of the sentences is 5
|
||||
/// the elements of the matrix is 0, 1, or -1, defined as SENTENCE_BEGIN, SENTENCE_MIDDLE, NO_LABELS in cbasetype.h
|
||||
/// the elements of the matrix is 0, 1, or -1, defined as SEQUENCE_START, SEQUENCE_MIDDLE, NO_LABEL in cbasetype.h
|
||||
/// 0 1 1 0 1
|
||||
/// 1 0 1 0 0
|
||||
/// for two parallel data streams. The first has two sentences, with 0 indicating begining of a sentence
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
vector<MinibatchPackingFlag> m_minibatchPackingFlag;
|
||||
|
||||
/// by default it is false
|
||||
/// if true, reader will set to SENTENCE_MIDDLE for time positions that are orignally correspond to SENTENCE_BEGIN
|
||||
/// if true, reader will set to SEQUENCE_MIDDLE for time positions that are orignally correspond to SEQUENCE_START
|
||||
/// set to true so that a current minibatch can uses state activities from the previous minibatch.
|
||||
/// default will have truncated BPTT, which only does BPTT inside a minibatch
|
||||
|
||||
|
|
|
@ -1194,21 +1194,24 @@ public:
|
|||
/**
|
||||
These macros are used for sentence segmentation information.
|
||||
*/
|
||||
#define SENTENCE_BEGIN ((int) MinibatchPackingFlag::UtteranceStart)
|
||||
#define SENTENCE_MIDDLE ((int) MinibatchPackingFlag::None)
|
||||
#define SENTENCE_END ((int) MinibatchPackingFlag::UtteranceEnd)
|
||||
#define NO_LABELS ((int) MinibatchPackingFlag::NoLabel)
|
||||
#define SEQUENCE_START ((int) MinibatchPackingFlag::SequenceStart)
|
||||
#define SEQUENCE_MIDDLE ((int) MinibatchPackingFlag::None)
|
||||
#define SEQUENCE_END ((int) MinibatchPackingFlag::SequenceEnd)
|
||||
#define NO_INPUT ((int) MinibatchPackingFlag::NoInput)
|
||||
#define NO_LABEL ((int) MinibatchPackingFlag::NoLabel)
|
||||
|
||||
enum class MinibatchPackingFlag : unsigned char
|
||||
{
|
||||
None = 0,
|
||||
UtteranceStart = 1 << 0, //binary 0001
|
||||
UtteranceEnd = 1 << 1, //binary 0010
|
||||
NoLabel = 1 << 2, //binary 0100
|
||||
SequenceStart = 1 << 0, //binary 0001
|
||||
SequenceEnd = 1 << 1, //binary 0010
|
||||
NoFeature = 1 << 2, //binary 0100
|
||||
NoLabel = 1 << 3, //binary 1000
|
||||
|
||||
UtteranceStartOrNoLabel = UtteranceStart | NoLabel,
|
||||
UtteranceEndOrNoLabel = UtteranceEnd | NoLabel,
|
||||
UtteranceStartOrEndOrNoLabel = UtteranceStart | UtteranceEnd | NoLabel,
|
||||
NoInput = NoFeature | NoLabel, //when we refactorize reader, NoInput will no longer needed
|
||||
SequenceStartOrNoInput = SequenceStart | NoInput,
|
||||
SequenceEndOrNoInput = SequenceEnd | NoInput,
|
||||
SequenceStartOrEndOrNoInput = SequenceStart | SequenceEnd | NoInput,
|
||||
};
|
||||
|
||||
inline MinibatchPackingFlag operator| (MinibatchPackingFlag a, MinibatchPackingFlag b)
|
||||
|
|
|
@ -1057,7 +1057,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
{
|
||||
for (size_t j = 0; j < m_currentMBSize; j++)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, j, (ElemType) SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(i, j, (ElemType) SEQUENCE_MIDDLE);
|
||||
}
|
||||
}
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
|
@ -1079,8 +1079,8 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
// Sets the utterance boundary.
|
||||
if (startFrame == 0)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[0] |= MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[0] |= MinibatchPackingFlag::SequenceStart;
|
||||
}
|
||||
|
||||
endFrame = startFrame + m_currentMBSize;
|
||||
|
@ -1106,13 +1106,13 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
if (m_truncated == false)
|
||||
{
|
||||
assert(startFrame == 0);
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[0] |= MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[0] |= MinibatchPackingFlag::SequenceStart;
|
||||
}
|
||||
|
||||
// We have to set the utterance end.
|
||||
m_sentenceBegin.SetValue(i, m_sentenceBegin.GetNumCols() - 1, (ElemType)SENTENCE_END);
|
||||
m_minibatchPackingFlag[m_sentenceBegin.GetNumCols() - 1] |= MinibatchPackingFlag::UtteranceEnd;
|
||||
m_sentenceBegin.SetValue(i, m_sentenceBegin.GetNumCols() - 1, (ElemType)SEQUENCE_END);
|
||||
m_minibatchPackingFlag[m_sentenceBegin.GetNumCols() - 1] |= MinibatchPackingFlag::SequenceEnd;
|
||||
}
|
||||
|
||||
// Now puts the utterance into the minibatch, and loads the
|
||||
|
@ -1139,10 +1139,10 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
{
|
||||
for (size_t k = 0; k < m_currentMBSize; k++)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, k, (ElemType) NO_LABELS);
|
||||
m_sentenceBegin.SetValue(i, k, (ElemType) NO_LABEL);
|
||||
m_minibatchPackingFlag[k] |= MinibatchPackingFlag::NoLabel;
|
||||
|
||||
// Populates <NO_LABELS> with real features, the
|
||||
// Populates <NO_LABEL> with real features, the
|
||||
// following implementation is not efficient...
|
||||
assert(m_toProcess[i] > 0);
|
||||
PopulateUtteranceInMinibatch(matrices, i, 0, 1, m_currentMBSize, k);
|
||||
|
@ -1169,14 +1169,14 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
if (m_truncated == false)
|
||||
{
|
||||
assert(startFrame == 0);
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[0] |= MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[0] |= MinibatchPackingFlag::SequenceStart;
|
||||
}
|
||||
|
||||
// We have to set the utterance end.
|
||||
assert(m_toProcess[i] - startFrame - 1 < m_sentenceBegin.GetNumCols());
|
||||
m_sentenceBegin.SetValue(i, m_toProcess[i] - startFrame - 1, (ElemType)SENTENCE_END);
|
||||
m_minibatchPackingFlag[m_toProcess[i] - startFrame - 1] |= MinibatchPackingFlag::UtteranceEnd;
|
||||
m_sentenceBegin.SetValue(i, m_toProcess[i] - startFrame - 1, (ElemType)SEQUENCE_END);
|
||||
m_minibatchPackingFlag[m_toProcess[i] - startFrame - 1] |= MinibatchPackingFlag::SequenceEnd;
|
||||
}
|
||||
endFrame = m_toProcess[i];
|
||||
size_t currentMBFilled = endFrame - startFrame;
|
||||
|
@ -1191,10 +1191,10 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
{
|
||||
// Sets the utterance boundary.
|
||||
assert(currentMBFilled + m_toProcess[i] <= m_sentenceBegin.GetNumCols());
|
||||
m_sentenceBegin.SetValue(i, currentMBFilled, (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[currentMBFilled] |= MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, currentMBFilled + m_toProcess[i] - 1, (ElemType)SENTENCE_END);
|
||||
m_minibatchPackingFlag[currentMBFilled + m_toProcess[i] - 1] |= MinibatchPackingFlag::UtteranceEnd;
|
||||
m_sentenceBegin.SetValue(i, currentMBFilled, (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[currentMBFilled] |= MinibatchPackingFlag::SequenceStart;
|
||||
m_sentenceBegin.SetValue(i, currentMBFilled + m_toProcess[i] - 1, (ElemType)SEQUENCE_END);
|
||||
m_minibatchPackingFlag[currentMBFilled + m_toProcess[i] - 1] |= MinibatchPackingFlag::SequenceEnd;
|
||||
populateSucc = PopulateUtteranceInMinibatch(matrices, i, 0, m_toProcess[i], m_currentMBSize, currentMBFilled);
|
||||
if (m_doSeqTrain && populateSucc) { m_minibatchUttInfo[i].push_back(m_uttInfo[i][0]); }
|
||||
assert(m_processedFrame[i] == 0);
|
||||
|
@ -1212,18 +1212,18 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
m_processedFrame[i] += m_currentMBSize - currentMBFilled;
|
||||
if (currentMBFilled < m_currentMBSize)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, currentMBFilled, (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[currentMBFilled] |= MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, currentMBFilled, (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[currentMBFilled] |= MinibatchPackingFlag::SequenceStart;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t k = currentMBFilled; k < m_currentMBSize; k++)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, k, (ElemType) NO_LABELS);
|
||||
m_sentenceBegin.SetValue(i, k, (ElemType) NO_LABEL);
|
||||
m_minibatchPackingFlag[k] |= MinibatchPackingFlag::NoLabel;
|
||||
|
||||
// Populates <NO_LABELS> with real features, the
|
||||
// Populates <NO_LABEL> with real features, the
|
||||
// following implementation is not efficient...
|
||||
assert(m_toProcess[i] > 0);
|
||||
PopulateUtteranceInMinibatch(matrices, i, 0, 1, m_currentMBSize, k);
|
||||
|
@ -1511,13 +1511,13 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
{
|
||||
m_sentenceBegin.Resize((size_t)1, (size_t)feat.cols());
|
||||
m_minibatchPackingFlag.resize(feat.cols());
|
||||
m_sentenceBegin.SetValue((ElemType) SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType) SENTENCE_BEGIN);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SENTENCE_END);
|
||||
m_sentenceBegin.SetValue((ElemType) SEQUENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType) SEQUENCE_START);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SEQUENCE_END);
|
||||
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::UtteranceEnd;
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::SequenceEnd;
|
||||
first = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ public:
|
|||
/// n_length is the maximum lenght of each stream
|
||||
/// for example, two sentences used in parallel in one minibatch would be
|
||||
/// [2 x 5] if the max length of one of the sentences is 5
|
||||
/// the elements of the matrix is 0, 1, or -1, defined as SENTENCE_BEGIN, SENTENCE_MIDDLE, NO_LABELS in cbasetype.h
|
||||
/// the elements of the matrix is 0, 1, or -1, defined as SEQUENCE_START, SEQUENCE_MIDDLE, NO_LABEL in cbasetype.h
|
||||
/// 0 1 1 0 1
|
||||
/// 1 0 1 0 0
|
||||
/// for two parallel data streams. The first has two sentences, with 0 indicating begining of a sentence
|
||||
|
@ -166,7 +166,7 @@ public:
|
|||
vector<MinibatchPackingFlag> m_minibatchPackingFlag;
|
||||
|
||||
/// by default it is false
|
||||
/// if true, reader will set to SENTENCE_MIDDLE for time positions that are orignally correspond to SENTENCE_BEGIN
|
||||
/// if true, reader will set to SEQUENCE_MIDDLE for time positions that are orignally correspond to SEQUENCE_START
|
||||
/// set to true so that a current minibatch can uses state activities from the previous minibatch.
|
||||
/// default will have truncated BPTT, which only does BPTT inside a minibatch
|
||||
|
||||
|
|
|
@ -235,12 +235,12 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
size_t numFrames = 0;
|
||||
for (size_t j = 0; j < sentenceBegin.GetNumCols(); ++j)
|
||||
{
|
||||
if (((size_t)sentenceBegin(i, j) & NO_LABELS) == NO_LABELS)
|
||||
if (((size_t)sentenceBegin(i, j) & NO_LABEL) == NO_LABEL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
numFrames += 1;
|
||||
if ((((size_t)sentenceBegin(i, j) & SENTENCE_END) == SENTENCE_END)
|
||||
if ((((size_t)sentenceBegin(i, j) & SEQUENCE_END) == SEQUENCE_END)
|
||||
|| j == sentenceBegin.GetNumCols() - 1)
|
||||
{
|
||||
size_t uttIndex = (*uttInfoInMinibatch)[i].size();
|
||||
|
|
|
@ -1194,21 +1194,24 @@ public:
|
|||
/**
|
||||
These macros are used for sentence segmentation information.
|
||||
*/
|
||||
#define SENTENCE_BEGIN ((int) MinibatchPackingFlag::UtteranceStart)
|
||||
#define SENTENCE_MIDDLE ((int) MinibatchPackingFlag::None)
|
||||
#define SENTENCE_END ((int) MinibatchPackingFlag::UtteranceEnd)
|
||||
#define NO_LABELS ((int) MinibatchPackingFlag::NoLabel)
|
||||
#define SEQUENCE_START ((int) MinibatchPackingFlag::SequenceStart)
|
||||
#define SEQUENCE_MIDDLE ((int) MinibatchPackingFlag::None)
|
||||
#define SEQUENCE_END ((int) MinibatchPackingFlag::SequenceEnd)
|
||||
#define NO_INPUT ((int) MinibatchPackingFlag::NoInput)
|
||||
#define NO_LABEL ((int) MinibatchPackingFlag::NoLabel)
|
||||
|
||||
enum class MinibatchPackingFlag : unsigned char
|
||||
{
|
||||
None = 0,
|
||||
UtteranceStart = 1 << 0, //binary 0001
|
||||
UtteranceEnd = 1 << 1, //binary 0010
|
||||
NoLabel = 1 << 2, //binary 0100
|
||||
SequenceStart = 1 << 0, //binary 0001
|
||||
SequenceEnd = 1 << 1, //binary 0010
|
||||
NoFeature = 1 << 2, //binary 0100
|
||||
NoLabel = 1 << 3, //binary 1000
|
||||
|
||||
UtteranceStartOrNoLabel = UtteranceStart | NoLabel,
|
||||
UtteranceEndOrNoLabel = UtteranceEnd | NoLabel,
|
||||
UtteranceStartOrEndOrNoLabel = UtteranceStart | UtteranceEnd | NoLabel,
|
||||
NoInput = NoFeature | NoLabel, //when we refactorize reader, NoInput will no longer needed
|
||||
SequenceStartOrNoInput = SequenceStart | NoInput,
|
||||
SequenceEndOrNoInput = SequenceEnd | NoInput,
|
||||
SequenceStartOrEndOrNoInput = SequenceStart | SequenceEnd | NoInput,
|
||||
};
|
||||
|
||||
inline MinibatchPackingFlag operator| (MinibatchPackingFlag a, MinibatchPackingFlag b)
|
||||
|
|
|
@ -795,13 +795,13 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
{
|
||||
m_sentenceBegin.Resize((size_t)1, (size_t)feat.cols());
|
||||
m_minibatchPackingFlag.resize(feat.cols());
|
||||
m_sentenceBegin.SetValue((ElemType) SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType) SENTENCE_BEGIN);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SENTENCE_END);
|
||||
m_sentenceBegin.SetValue((ElemType) SEQUENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType) SEQUENCE_START);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SEQUENCE_END);
|
||||
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::UtteranceEnd;
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::SequenceEnd;
|
||||
first = false;
|
||||
}
|
||||
|
||||
|
@ -957,12 +957,12 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
m_sentenceBegin.Resize(m_numberOfuttsPerMinibatch, m_mbSize);
|
||||
m_minibatchPackingFlag.resize(m_mbSize);
|
||||
|
||||
//mtSentenceBegin.SetValue((ElemType) SENTENCE_MIDDLE);
|
||||
//mtSentenceBegin.SetValue((ElemType) SEQUENCE_MIDDLE);
|
||||
for (size_t i = 0; i < m_numberOfuttsPerMinibatch; i++)
|
||||
{
|
||||
for (size_t j = 0; j < m_mbSize; j++)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i,j,(ElemType) SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(i,j,(ElemType) SEQUENCE_MIDDLE);
|
||||
}
|
||||
}
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
|
@ -982,16 +982,16 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
m_switchFrame[i] = m_mbSize+1;
|
||||
if (m_processedFrame[i] == 1)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SENTENCE_END);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceEnd;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SEQUENCE_END);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceEnd;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_switchFrame[i] = 0;
|
||||
m_sentenceEnd[i] = true;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, 0, (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceStart;
|
||||
}
|
||||
actualmbsize[i] = m_mbSize;
|
||||
endFr = startFr + actualmbsize[i];
|
||||
|
@ -1145,13 +1145,13 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
|
||||
if (actualmbsize[i] < m_mbSize)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i], (ElemType)SENTENCE_BEGIN);
|
||||
m_minibatchPackingFlag[actualmbsize[i]] = m_minibatchPackingFlag[actualmbsize[i]] | MinibatchPackingFlag::UtteranceStart;
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i], (ElemType)SEQUENCE_START);
|
||||
m_minibatchPackingFlag[actualmbsize[i]] = m_minibatchPackingFlag[actualmbsize[i]] | MinibatchPackingFlag::SequenceStart;
|
||||
}
|
||||
if (actualmbsize[i] == m_mbSize)
|
||||
{
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i]-1, (ElemType)SENTENCE_END);
|
||||
m_minibatchPackingFlag[actualmbsize[i]-1] = m_minibatchPackingFlag[actualmbsize[i]] | MinibatchPackingFlag::UtteranceEnd;
|
||||
m_sentenceBegin.SetValue(i, actualmbsize[i]-1, (ElemType)SEQUENCE_END);
|
||||
m_minibatchPackingFlag[actualmbsize[i]-1] = m_minibatchPackingFlag[actualmbsize[i]] | MinibatchPackingFlag::SequenceEnd;
|
||||
}
|
||||
|
||||
startFr = m_switchFrame[i];
|
||||
|
@ -1303,13 +1303,13 @@ the first row is 0/1 bit for wether corresponding frame has sentence beginining/
|
|||
m_sentenceBegin.Resize((size_t)1, (size_t)feat.cols());
|
||||
m_minibatchPackingFlag.resize((size_t)feat.cols());
|
||||
|
||||
m_sentenceBegin.SetValue((ElemType)SENTENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType)SENTENCE_BEGIN);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SENTENCE_END);
|
||||
m_sentenceBegin.SetValue((ElemType)SEQUENCE_MIDDLE);
|
||||
m_sentenceBegin.SetValue(0, 0, (ElemType)SEQUENCE_START);
|
||||
m_sentenceBegin.SetValue(0, (size_t)feat.cols()-1, (ElemType) SEQUENCE_END);
|
||||
|
||||
std::fill(m_minibatchPackingFlag.begin(), m_minibatchPackingFlag.end(), MinibatchPackingFlag::None);
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::UtteranceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::UtteranceEnd;
|
||||
m_minibatchPackingFlag[0] = MinibatchPackingFlag::SequenceStart;
|
||||
m_minibatchPackingFlag[(size_t)feat.cols()-1] = MinibatchPackingFlag::SequenceEnd;
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
/// n_length is the maximum lenght of each stream
|
||||
/// for example, two sentences used in parallel in one minibatch would be
|
||||
/// [2 x 5] if the max length of one of the sentences is 5
|
||||
/// the elements of the matrix is 0, 1, or -1, defined as SENTENCE_BEGIN, SENTENCE_MIDDLE, NO_LABELS in cbasetype.h
|
||||
/// the elements of the matrix is 0, 1, or -1, defined as SEQUENCE_START, SEQUENCE_MIDDLE, NO_LABEL in cbasetype.h
|
||||
/// 0 1 1 0 1
|
||||
/// 1 0 1 0 0
|
||||
/// for two parallel data streams. The first has two sentences, with 0 indicating begining of a sentence
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
vector<MinibatchPackingFlag> m_minibatchPackingFlag;
|
||||
|
||||
/// by default it is false
|
||||
/// if true, reader will set to SENTENCE_MIDDLE for time positions that are orignally correspond to SENTENCE_BEGIN
|
||||
/// if true, reader will set to SEQUENCE_MIDDLE for time positions that are orignally correspond to SEQUENCE_START
|
||||
/// set to true so that a current minibatch can uses state activities from the previous minibatch.
|
||||
/// default will have truncated BPTT, which only does BPTT inside a minibatch
|
||||
|
||||
|
|
|
@ -1194,21 +1194,24 @@ public:
|
|||
/**
|
||||
These macros are used for sentence segmentation information.
|
||||
*/
|
||||
#define SENTENCE_BEGIN ((int) MinibatchPackingFlag::UtteranceStart)
|
||||
#define SENTENCE_MIDDLE ((int) MinibatchPackingFlag::None)
|
||||
#define SENTENCE_END ((int) MinibatchPackingFlag::UtteranceEnd)
|
||||
#define NO_LABELS ((int) MinibatchPackingFlag::NoLabel)
|
||||
#define SEQUENCE_START ((int) MinibatchPackingFlag::SequenceStart)
|
||||
#define SEQUENCE_MIDDLE ((int) MinibatchPackingFlag::None)
|
||||
#define SEQUENCE_END ((int) MinibatchPackingFlag::SequenceEnd)
|
||||
#define NO_INPUT ((int) MinibatchPackingFlag::NoInput)
|
||||
#define NO_LABEL ((int) MinibatchPackingFlag::NoLabel)
|
||||
|
||||
enum class MinibatchPackingFlag : unsigned char
|
||||
{
|
||||
None = 0,
|
||||
UtteranceStart = 1 << 0, //binary 0001
|
||||
UtteranceEnd = 1 << 1, //binary 0010
|
||||
NoLabel = 1 << 2, //binary 0100
|
||||
SequenceStart = 1 << 0, //binary 0001
|
||||
SequenceEnd = 1 << 1, //binary 0010
|
||||
NoFeature = 1 << 2, //binary 0100
|
||||
NoLabel = 1 << 3, //binary 1000
|
||||
|
||||
UtteranceStartOrNoLabel = UtteranceStart | NoLabel,
|
||||
UtteranceEndOrNoLabel = UtteranceEnd | NoLabel,
|
||||
UtteranceStartOrEndOrNoLabel = UtteranceStart | UtteranceEnd | NoLabel,
|
||||
NoInput = NoFeature | NoLabel, //when we refactorize reader, NoInput will no longer needed
|
||||
SequenceStartOrNoInput = SequenceStart | NoInput,
|
||||
SequenceEndOrNoInput = SequenceEnd | NoInput,
|
||||
SequenceStartOrEndOrNoInput = SequenceStart | SequenceEnd | NoInput,
|
||||
};
|
||||
|
||||
inline MinibatchPackingFlag operator| (MinibatchPackingFlag a, MinibatchPackingFlag b)
|
||||
|
|
Загрузка…
Ссылка в новой задаче