/// <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, ILayer forwardLayer, ILayer 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()); 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()); backwardLayer.CopyNeuronTo(backwardCellList[0][curState]); } //Merge forward and backward MergeForwardBackwardLayers(numStates, forwardLayer.LayerSize, 0); }
private void ComputeMiddleLayers(Sequence pSequence, ILayer forwardLayer, ILayer 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]); 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]); backwardLayer.CopyNeuronTo(backwardCellList[layerIdx][curState]); } //Merge forward and backward MergeForwardBackwardLayers(numStates, forwardLayer.LayerSize, layerIdx); }