text
stringlengths 0
2.2M
|
---|
logLikelihood.ColumnSlice(
|
(startFrame + k) * m_numUttsPerMinibatch + i, 1),
|
m_uttPool[uttID].progress + k);
|
}
|
m_uttPool[uttID].progress += numFrames;
|
if (m_uttPool[uttID].progress == m_uttPool[uttID].uttLength)
|
{
|
m_derivativeInterface->ComputeDerivative(
|
uttID,
|
m_uttPool[uttID].logLikelihood,
|
&m_uttPool[uttID].derivative,
|
&m_uttPool[uttID].objective);
|
m_uttPool[uttID].hasDerivative = true;
|
m_uttPool[uttID].progress = 0;
|
m_uttReady[m_uttPool[uttID].streamID] = true;
|
}
|
}
|
}
|
}
|
// Checks if we are ready to provide derivatives.
|
m_needLikelihood = false;
|
for (size_t i = 0; i < m_uttReady.size(); ++i)
|
{
|
if (m_uttReady[i] == false)
|
{
|
m_needLikelihood = true;
|
break;
|
}
|
}
|
}
|
// Suppose we have a, b, c 3 streams, the <derivativesOut> should be 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>::GetDerivative(
|
const std::vector<std::vector<std::pair<wstring, size_t>>>& uttInfo,
|
const MBLayoutPtr pMBLayout,
|
Matrix<ElemType>* derivativesOut)
|
{
|
assert(derivativesOut != NULL);
|
assert(m_needLikelihood == false);
|
std::vector<std::vector<
|
std::pair<wstring, std::pair<size_t, size_t>>>> uttInfoInMinibatch;
|
ProcessUttInfo(uttInfo, pMBLayout, &uttInfoInMinibatch);
|
m_currentObj = 0;
|
Matrix<ElemType> derivatives(CPUDEVICE);
|
derivatives.Resize(m_dimension, pMBLayout->GetNumCols());
|
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;
|
// Checks if we have derivatives.
|
if (m_uttPool.find(uttID) == m_uttPool.end() || (m_uttPool.find(uttID) != m_uttPool.end() && m_uttPool[uttID].hasDerivative == false))
|
{
|
RuntimeError("Derivatives are not ready for utterance:"
|
" %S\n",
|
uttID.c_str());
|
}
|
// Assign the derivatives.
|
assert(uttID == uttInfoInMinibatch[i][j].first);
|
size_t startFrame = uttInfoInMinibatch[i][j].second.first;
|
size_t startFrameInUtt = m_uttPool[uttID].progress;
|
size_t numFrames = uttInfoInMinibatch[i][j].second.second;
|
for (size_t k = 0; k < numFrames; ++k)
|
{
|
derivatives.SetColumn(
|
m_uttPool[uttID].derivative.ColumnSlice(
|
startFrameInUtt + k, 1),
|
(startFrame + k) * m_numUttsPerMinibatch + i);
|
}
|
m_currentObj += m_uttPool[uttID].objective * numFrames / m_uttPool[uttID].uttLength;
|
m_uttPool[uttID].progress += numFrames;
|
assert(m_uttPool[uttID].progress <= m_uttPool[uttID].uttLength);
|
if (m_uttPool[uttID].progress == m_uttPool[uttID].uttLength)
|
{
|
m_uttPool.erase(uttID);
|
}
|
}
|
}
|
// Checks if we need to move data to GPU.
|
if (derivativesOut->GetDeviceId() >= 0)
|
{
|
derivatives.TransferFromDeviceToDevice(
|
CPUDEVICE, derivativesOut->GetDeviceId(), true, false, false);
|
}
|
derivativesOut->SetValue(derivatives);
|
// Keeps the utterance information so we can check next time when we
|
// gives the objectives.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.