/// <summary> /// Compute the output of bottom layer /// </summary> /// <param name="sequence"></param> /// <param name="forwardLayer"></param> /// <param name="backwardLayer"></param> /// <returns></returns> private void ComputeBottomLayer(Sequence sequence, SimpleLayer forwardLayer, SimpleLayer backwardLayer, RunningMode runningMode) { var numStates = sequence.States.Length; //Computing forward RNN forwardLayer.Reset(); for (var curState = 0; curState < numStates; curState++) { var state = sequence.States[curState]; forwardLayer.ForwardPass(state.SparseFeature, state.DenseFeature.CopyTo()); forwardCellList[0][curState] = forwardLayer.CopyNeuronTo(forwardCellList[0][curState]); } //Computing backward RNN backwardLayer.Reset(); for (var curState = numStates - 1; curState >= 0; curState--) { var state = sequence.States[curState]; backwardLayer.ForwardPass(state.SparseFeature, state.DenseFeature.CopyTo()); backwardCellList[0][curState] = backwardLayer.CopyNeuronTo(backwardCellList[0][curState]); } //Merge forward and backward MergeForwardBackwardLayers(numStates, forwardLayer.LayerSize, 0); }
private void ComputeMiddleLayers(Sequence pSequence, SimpleLayer forwardLayer, SimpleLayer backwardLayer, RunningMode runningMode, int layerIdx) { var numStates = pSequence.States.Length; float[][] lastLayerOutputs = layersOutput[layerIdx - 1]; //Computing forward RNN forwardLayer.Reset(); for (var curState = 0; curState < numStates; curState++) { var state = pSequence.States[curState]; forwardLayer.ForwardPass(state.SparseFeature, lastLayerOutputs[curState]); forwardCellList[layerIdx][curState] = forwardLayer.CopyNeuronTo(forwardCellList[layerIdx][curState]); } //Computing backward RNN backwardLayer.Reset(); for (var curState = numStates - 1; curState >= 0; curState--) { var state = pSequence.States[curState]; backwardLayer.ForwardPass(state.SparseFeature, lastLayerOutputs[curState]); backwardCellList[layerIdx][curState] = backwardLayer.CopyNeuronTo(backwardCellList[layerIdx][curState]); } //Merge forward and backward MergeForwardBackwardLayers(numStates, forwardLayer.LayerSize, layerIdx); }