text
stringlengths 0
2.2M
|
---|
uttInfoInMinibatch->clear();
|
uttInfoInMinibatch->resize(uttInfo.size());
|
for (size_t i = 0; i < uttInfo.size(); ++i)
|
{
|
size_t startFrameIndexInMinibatch = 0;
|
size_t numFrames = 0;
|
for (size_t j = 0; j < pMBLayout->GetNumTimeSteps(); ++j)
|
{
|
/* if (pMBLayout->Is(i, j, MinibatchPackingFlags::NoLabel))
|
{
|
continue;
|
}*/
|
FrameRange fr(pMBLayout, j);
|
if (pMBLayout->IsGap(fr.Sequence(i)))
|
{
|
continue;
|
}
|
numFrames += 1;
|
if (pMBLayout->IsBeyondStartOrEnd(fr.WithTimeOffset((ptrdiff_t) 1).Sequence(i)) || j == pMBLayout->GetNumTimeSteps() - 1)
|
{
|
size_t uttIndex = (*uttInfoInMinibatch)[i].size();
|
wstring uttID = uttInfo[i][uttIndex].first;
|
(*uttInfoInMinibatch)[i].push_back(
|
make_pair(uttID, make_pair(startFrameIndexInMinibatch,
|
numFrames)));
|
startFrameIndexInMinibatch = j + 1;
|
numFrames = 0;
|
}
|
}
|
assert(uttInfo[i].size() == (*uttInfoInMinibatch)[i].size());
|
}
|
}
|
// Suppose we have a, b, c 3 streams, the <logLikelihoodIn> is the in the
|
// following format:
|
// 1: a11 b11 c11 a12 b12 c12...
|
// 2: a21 b21 c21 a22 b22 c22...
|
// 3: a31 b31 c31 a32 b32 c32...
|
template <class ElemType>
|
bool UtteranceDerivativeBuffer<ElemType>::SetLikelihood(
|
const std::vector<std::vector<std::pair<wstring, size_t>>>& uttInfo,
|
const Matrix<ElemType>& logLikelihoodIn,
|
const MBLayoutPtr pMBLayout)
|
{
|
assert(m_needLikelihood == true);
|
assert(m_epochEnd == false);
|
if (m_dimension == 0)
|
{
|
m_dimension = logLikelihoodIn.GetNumRows();
|
}
|
assert(m_dimension == logLikelihoodIn.GetNumRows());
|
std::vector<std::vector<
|
std::pair<wstring, std::pair<size_t, size_t>>>> uttInfoInMinibatch;
|
ProcessUttInfo(uttInfo, pMBLayout, &uttInfoInMinibatch);
|
// Checks if we need to move data to CPU.
|
Matrix<ElemType> logLikelihood = logLikelihoodIn.DeepClone();
|
if (logLikelihood.GetDeviceId() >= 0)
|
{
|
logLikelihood.TransferFromDeviceToDevice(
|
logLikelihood.GetDeviceId(), CPUDEVICE, true, false, false);
|
}
|
size_t currentMBSize = pMBLayout->GetNumTimeSteps();
|
for (size_t i = 0; i < uttInfo.size(); ++i)
|
{
|
assert(uttInfo[i].size() == uttInfoInMinibatch[i].size());
|
for (size_t j = 0; j < uttInfo[i].size(); ++j)
|
{
|
wstring uttID = uttInfo[i][j].first;
|
if (m_uttPool.find(uttID) == m_uttPool.end())
|
{
|
UtteranceDerivativeUnit tmpUttUnit;
|
tmpUttUnit.hasDerivative = false;
|
tmpUttUnit.uttLength = uttInfo[i][j].second;
|
tmpUttUnit.progress = 0;
|
tmpUttUnit.streamID = i;
|
tmpUttUnit.logLikelihood.Resize(logLikelihood.GetNumRows(),
|
tmpUttUnit.uttLength);
|
m_uttPool[uttID] = std::move(tmpUttUnit);
|
}
|
// Sets the likelihood and computes derivatives.
|
assert(m_uttPool.find(uttID) != m_uttPool.end());
|
if (m_uttPool[uttID].hasDerivative == false)
|
{
|
assert(uttID == uttInfoInMinibatch[i][j].first);
|
size_t startFrame = uttInfoInMinibatch[i][j].second.first;
|
size_t numFrames = uttInfoInMinibatch[i][j].second.second;
|
assert(m_uttPool[uttID].progress + numFrames <= m_uttPool[uttID].uttLength);
|
// Sets the likelihood.
|
for (size_t k = 0; k < numFrames; ++k)
|
{
|
m_uttPool[uttID].logLikelihood.SetColumn(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.