Added second bs implementation of sampled softmax not exposing the sampling nodes

This commit is contained in:
Thilo Will 2016-10-06 14:04:26 +02:00
Родитель 488d51b929
Коммит 665cfb269e
2 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -508,6 +508,23 @@ CNTK2 = [
ce = logSum - zT
}.ce
CrossEntropyWithSampledSoftmax2(
hiddenLayer /* Vector of dimension nHidden */,
labels /* One-hot for the true class (labels). Dimension: nClasses */,
weights /* nClasses * nHidden */,
bias /* Biases for logit computation. Dimension nClasses */,
numSamples /* number of random samples to be used */,
samplingWeights /* Sparse matrix of dimension nClasses * nSamples */,
sampleWithReplacement = true /* boolean parameter specifiying if sampling with replacment should be used */
) =
{
samples = CNTK2.GetRandomSample (samplingWeights, numSamples, sampleWithReplacement)
inclusionProbs = CNTK2.GetInclusionFrequency(samplingWeights, numSamples, sampleWithReplacement)
logPrior = Log(inclusionProbs)
ce = CNTK2.CrossEntropyWithSampledSoftmax(hiddenLayer, labels, samples, weights, bias, logPrior)
}.ce
// 12. Comparison nodes
Less(_, y, tag='') = new ComputationNode [ operation = 'Less' ; inputs = _AsNodes (_ : y) /*plus the function args*/ ]

Просмотреть файл

@ -103,6 +103,8 @@ void RandomSampleNode<ElemType>::ForwardPropNonLooping()
Matrix<ElemType>& valueMatrix = ValueAsMatrix();
valueMatrix.TransferToDeviceIfNotThere(CPUDEVICE, /*ismoved =*/ true/*means: BOTH state not ok */, /*emptyTransfer =*/ true, /*updatePreferredDevice =*/ false);
valueMatrix.SetDevice(CPUDEVICE);
//BUGBUG: matrix type should be configured during validation
valueMatrix.SwitchToMatrixType(SPARSE, matrixFormatSparseCSC, false);
valueMatrix.Reset();
@ -186,6 +188,7 @@ void RandomSampleInclusionFrequencyNode<ElemType>::ForwardPropNonLooping()
valueMatrix.TransferToDeviceIfNotThere(CPUDEVICE, /*ismoved =*/ true/*means: BOTH state not ok */, /*emptyTransfer =*/ true, /*updatePreferredDevice =*/ false);
valueMatrix.SetDevice(CPUDEVICE);
//BUGBUG: matrix type should be configured during validation
valueMatrix.SwitchToMatrixType(DENSE, matrixFormatDense, false);
double sumOfWeights = m_samplingWeightsPrefixSum.back();
const Matrix<ElemType>& samplingWeights = Input(0)->ValueAsMatrix();