Merge branch 'myseq' of //vilfblgpu011/d/users/erw/src/cntk into myseq
This commit is contained in:
Коммит
bc3b96e79a
|
@ -40,14 +40,14 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
Base(deviceId, name)
|
||||
{
|
||||
m_parameterUpdateRequired = true;
|
||||
m_valueSharable = false;
|
||||
this->m_valueSharable = false;
|
||||
m_sampleLayout = ImageLayoutWHC(1, SIZE_MAX, 1);
|
||||
}
|
||||
LearnableParameter(DEVICEID_TYPE deviceId, const wstring & name, size_t rows, size_t cols) :
|
||||
Base(deviceId, name)
|
||||
{
|
||||
m_parameterUpdateRequired = true;
|
||||
m_valueSharable = false;
|
||||
this->m_valueSharable = false;
|
||||
m_sampleLayout = ImageLayoutWHC(1, rows, 1);
|
||||
// TODO: Is ^^ this a wise choice? These are often weight matrices, where rows, not columns, are multiplied with input vectors.
|
||||
CreateMatrixIfNull(m_value);
|
||||
|
@ -245,7 +245,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
SetDims(rows, cols);
|
||||
UpdateFunctionValuesSize(); // we must allocate the matrix so that the readers get objects with valid row dimensions (some readers expect that)
|
||||
m_parameterUpdateRequired = false;
|
||||
m_valueSharable = false;
|
||||
this->m_valueSharable = false;
|
||||
}
|
||||
protected:
|
||||
InputValueBase(DEVICEID_TYPE deviceId, const wstring & name, bool isSparse) :
|
||||
|
|
|
@ -1292,8 +1292,11 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
}
|
||||
else if (inputIndex == 1)
|
||||
{
|
||||
BackpropToRight(*m_softmaxOfRight, Input(0)->Value(), Input(inputIndex)->Gradient(),
|
||||
Gradient(), *m_gammaFromLattice, m_fsSmoothingWeight, m_frameDropThreshold);
|
||||
FrameRange fr(Input(0)->GetMBLayout());
|
||||
BackpropToRight(*m_softmaxOfRight, Input(0)->Value(), Input(inputIndex)->Gradient(),
|
||||
Gradient(), *m_gammaFromLattice, m_fsSmoothingWeight, m_frameDropThreshold);
|
||||
MaskMissingColumnsToZero(Input(inputIndex)->Gradient(), Input(0)->GetMBLayout(), fr);
|
||||
|
||||
#ifdef _DEBUG
|
||||
Input(inputIndex)->InvalidateMissingGradientColumns(FrameRange(Input(inputIndex)->GetMBLayout()));
|
||||
#endif
|
||||
|
@ -1433,6 +1436,16 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
RequestMatrixFromPool(m_softmaxOfRight, matrixPool);
|
||||
RequestMatrixFromPool(m_gammaFromLattice, matrixPool);
|
||||
}
|
||||
|
||||
//request matrices needed to do node function value evaluation
|
||||
virtual void ReleaseMatricesAfterBackprop(MatrixPool& matrixPool)
|
||||
{
|
||||
Base::ReleaseMatricesAfterForwardProp(matrixPool);
|
||||
ReleaseMatrixToPool(m_logSoftmaxOfRight, matrixPool);
|
||||
ReleaseMatrixToPool(m_softmaxOfRight, matrixPool);
|
||||
ReleaseMatrixToPool(m_gammaFromLattice, matrixPool);
|
||||
}
|
||||
|
||||
// TODO: method names should be CamelCase
|
||||
std::vector<shared_ptr<const msra::dbn::latticepair>> * getLatticePtr()
|
||||
{
|
||||
|
|
|
@ -356,26 +356,39 @@ struct latticefunctionskernels
|
|||
const size_t te = ts + numframes; // end time of current unit
|
||||
|
||||
size_t state1step0to1 = te; // inflection point from state 0 to 1, record in state 1
|
||||
size_t state1stepm1to1 = te;
|
||||
size_t state2step0to1 = te; // inflection point from state 0 to 1, record in state 2
|
||||
size_t state2stepm1to1 = te; // inflection point from state 0 to 1, record in state 2
|
||||
size_t state2step1to2 = te; // inflection point from state 1 to 2, record in state 2
|
||||
size_t state2step0to2 = te;
|
||||
|
||||
//now we only support transition from -1 to 0 or 2 for sil
|
||||
float pathscore0 = fwscore ; // log pp in state 0
|
||||
float pathscore1 = LOGZERO; // log pp in state 1
|
||||
float pathscore2 = LOGZERO; // log pp in state 2
|
||||
if(isSil)
|
||||
pathscore2 = fwscore;
|
||||
float pathscore0 = fwscore; // log pp in state 0
|
||||
float pathscore1 = fwscore; // log pp in state 1
|
||||
float pathscore2 = fwscore; // log pp in state 2
|
||||
|
||||
|
||||
|
||||
// first frame
|
||||
if (ts != te) // for t = ts, initialization
|
||||
{
|
||||
if (isSil) //for sil, -1 to 2 and -1 to 0 is permitted
|
||||
/* if (isSil) //for sil, -1 to 2 and -1 to 0 is permitted
|
||||
{
|
||||
pathscore0 += getlogtransp(transP,-1,0) + logLLs(senoneid0,ts);
|
||||
pathscore2 += getlogtransp(transP,-1,2) + logLLs(senoneid2,ts);
|
||||
}
|
||||
else //for others, only -1 to 0 is permitted
|
||||
pathscore0 += logLLs(senoneid0,ts); // Note: no need to incorporate LLs for state [1] and [2] because the path log LLs are LOGZERO anyway
|
||||
else //for others, only -1 to 0 is permitted
|
||||
{
|
||||
pathscore0 += getlogtransp(transP, -1, 0) + logLLs(senoneid0, ts);
|
||||
pathscore1 += getlogtransp(transP, -1, 1) + logLLs(senoneid1, ts);
|
||||
|
||||
}*/
|
||||
pathscore2 += getlogtransp(transP, -1, 2) + logLLs(senoneid2, ts);
|
||||
pathscore1 += getlogtransp(transP, -1, 1) + logLLs(senoneid1, ts);
|
||||
state1stepm1to1 = ts;
|
||||
pathscore0 += getlogtransp(transP, -1, 0) + logLLs(senoneid0, ts);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -399,17 +412,22 @@ struct latticefunctionskernels
|
|||
{
|
||||
pathscore2 = pathscore12;
|
||||
state2step0to1 = state1step0to1; // record the inflection point
|
||||
state2stepm1to1 = state1stepm1to1;
|
||||
state2step1to2 = t; // record the inflection point
|
||||
state2step0to2 = te;
|
||||
if (isSil)
|
||||
backptrmatrix (2, t-ts-1) = 1;
|
||||
}
|
||||
if (isSil) // only silence have path from 0 to 2
|
||||
//if (isSil) // only silence have path from 0 to 2
|
||||
{
|
||||
const float pathscore02 = pathscore0 + getlogtransp(transP,0,2); // log pp from state 0 to 2
|
||||
if (pathscore02 >= pathscore2) // if state 0->2
|
||||
{
|
||||
pathscore2 = pathscore02;
|
||||
backptrmatrix (2, t-ts-1) = 0;
|
||||
if (isSil)
|
||||
backptrmatrix (2, t-ts-1) = 0;
|
||||
state2step0to2 = t;
|
||||
state2step1to2 = te;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,9 +440,11 @@ struct latticefunctionskernels
|
|||
{
|
||||
pathscore1 = pathscore01;
|
||||
state1step0to1 = t; // record the inflection point
|
||||
state1stepm1to1 = te;
|
||||
if (isSil)
|
||||
backptrmatrix (1, t-ts-1) = 0;
|
||||
}
|
||||
|
||||
if (isSil) // only silence have path from 2 to 1
|
||||
{
|
||||
const float pathscore21 = pathscore2last + getlogtransp(transP,2,1);
|
||||
|
@ -495,19 +515,35 @@ struct latticefunctionskernels
|
|||
|
||||
if (!isSil)
|
||||
{
|
||||
state2step0to1 += alignindex - ts; // convert to align measure
|
||||
state2step1to2 += alignindex - ts;
|
||||
for (size_t t = alignindex; t < alignindex + numframes; t++) // set the final alignment
|
||||
{
|
||||
size_t senoneid;
|
||||
if (t < state2step0to1) // in state 0
|
||||
senoneid = senoneid0;
|
||||
else if(t < state2step1to2) // in state 1
|
||||
senoneid = senoneid1;
|
||||
else // in state 2
|
||||
senoneid = senoneid2;
|
||||
alignresult[t] = (unsigned short) senoneid;
|
||||
}
|
||||
if (state2step0to2 < te) //from 0 to 2
|
||||
{
|
||||
state2step0to2 += alignindex - ts;
|
||||
for (size_t t = alignindex; t < alignindex + numframes; t++) // set the final alignment
|
||||
{
|
||||
size_t senoneid;
|
||||
if (t < state2step0to2) // in state 0
|
||||
senoneid = senoneid0;
|
||||
else // in state 2
|
||||
senoneid = senoneid2;
|
||||
alignresult[t] = (unsigned short)senoneid;
|
||||
}
|
||||
}
|
||||
else //from 1 to 2
|
||||
{
|
||||
state2step0to1 += alignindex - ts; // convert to align measure
|
||||
state2step1to2 += alignindex - ts;
|
||||
for (size_t t = alignindex; t < alignindex + numframes; t++) // set the final alignment
|
||||
{
|
||||
size_t senoneid;
|
||||
if (state2step0to1 <alignindex - ts + te && t < state2step0to1)
|
||||
senoneid = senoneid0;
|
||||
else if(t < state2step1to2) // in state 1
|
||||
senoneid = senoneid1;
|
||||
else // in state 2
|
||||
senoneid = senoneid2;
|
||||
alignresult[t] = (unsigned short) senoneid;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // for silence
|
||||
{
|
||||
|
|
|
@ -264,7 +264,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
expand_wildcards(thisLattice(L"numLatTocFile"), paths);
|
||||
latticetocs.first.insert(latticetocs.first.end(), paths.begin(), paths.end());
|
||||
}
|
||||
RootPathInLatticeTocs = thisLattice(L"prefixPathInToc",L"");
|
||||
RootPathInLatticeTocs =(wstring) thisLattice(L"prefixPathInToc",L"");
|
||||
}
|
||||
|
||||
//get HMM related file names
|
||||
|
@ -955,7 +955,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
{
|
||||
size_t framenum = m_numFramesToProcess[i];
|
||||
fprintf(stderr, "WARNING: mismatched number of frames filled in the reader: %d in data vs %d in lattices. Ignoring this utterance %ls\n",
|
||||
framenum, m_latticeBufferMultiUtt[i]->getnumframes(), m_latticeBufferMultiUtt[i]->getkey().c_str());
|
||||
(int)framenum, (int)m_latticeBufferMultiUtt[i]->getnumframes(), m_latticeBufferMultiUtt[i]->getkey().c_str());
|
||||
ReNewBufferForMultiIO(i);
|
||||
needRenew = m_numFramesToProcess[i] > 0 && m_latticeBufferMultiUtt[i] && m_latticeBufferMultiUtt[i]->getnumframes() != m_numFramesToProcess[i];
|
||||
}
|
||||
|
@ -1006,7 +1006,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
|
|||
// the filled number of frames is inconsistent with the number frames in lattices (though it rarely occurs)
|
||||
// This is just a stopgap, to be removed after the bugs are found and fixed
|
||||
fprintf(stderr, "WARNING: mismatched number of frames filled in the reader: %d in data vs %d in lattices. Ignoring this utterance %ls\n",
|
||||
framenum, m_latticeBufferMultiUtt[src]->getnumframes(), m_latticeBufferMultiUtt[src]->getkey().c_str());
|
||||
(int)framenum, (int)m_latticeBufferMultiUtt[src]->getnumframes(), m_latticeBufferMultiUtt[src]->getkey().c_str());
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace msra { namespace lattices {
|
|||
GammaCalculation() : cpumode(false)
|
||||
{
|
||||
initialmark = false;
|
||||
lmf = 14.0f; // Note that 9 was best for Fisher --these should best be configurable
|
||||
lmf = 7.0f; // Note that 9 was best for Fisher --these should best be configurable
|
||||
wp = 0.0f;
|
||||
amf = 14.0f;
|
||||
amf = 7.0f;
|
||||
boostmmifactor = 0.0f;
|
||||
seqsMBRmode = false;
|
||||
}
|
||||
|
|
|
@ -438,6 +438,7 @@ template<typename FLOAT> static bool islogzero (FLOAT v) { return v < LOGZERO/2;
|
|||
LogicError("invalid backpointer resulting in state index out of range");
|
||||
|
||||
int bp = (int) backpointers(j,t); // save the backpointer before overwriting it (gammas and backpointers are aliases of each other)
|
||||
//thisedgealignmentsj[t] = (unsigned short)hmm.getsenoneid(j - js);
|
||||
if (!returnsenoneids) // return binary gammas (for MMI; this mode is compatible with softalignmode)
|
||||
for (size_t i = js; i < je; i++)
|
||||
loggammas(i,t) = ((int) i == j) ? 0.0f : LOGZERO;
|
||||
|
|
Загрузка…
Ссылка в новой задаче