30#ifndef TMVA_DNN_LSTM_LAYER
31#define TMVA_DNN_LSTM_LAYER
57template<
typename Architecture_t>
63 using Matrix_t =
typename Architecture_t::Matrix_t;
64 using Scalar_t =
typename Architecture_t::Scalar_t;
65 using Tensor_t =
typename Architecture_t::Tensor_t;
204 void Print()
const override;
342template <
typename Architecture_t>
351 {
stateSize,
stateSize,
stateSize,
stateSize}, {1, 1, 1, 1}, batchSize, (
returnSequence) ?
timeSteps : 1,
357 fWeightsInputGateState(
this->GetWeightsAt(4)), fInputGateBias(
this->GetBiasesAt(0)),
358 fWeightsForgetGate(
this->GetWeightsAt(1)), fWeightsForgetGateState(
this->GetWeightsAt(5)),
359 fForgetGateBias(
this->GetBiasesAt(1)), fWeightsCandidate(
this->GetWeightsAt(2)),
360 fWeightsCandidateState(
this->GetWeightsAt(6)), fCandidateBias(
this->GetBiasesAt(2)),
361 fWeightsOutputGate(
this->GetWeightsAt(3)), fWeightsOutputGateState(
this->GetWeightsAt(7)),
362 fOutputGateBias(
this->GetBiasesAt(3)), fWeightsInputGradients(
this->GetWeightGradientsAt(0)),
363 fWeightsInputStateGradients(
this->GetWeightGradientsAt(4)), fInputBiasGradients(
this->GetBiasGradientsAt(0)),
364 fWeightsForgetGradients(
this->GetWeightGradientsAt(1)),
365 fWeightsForgetStateGradients(
this->GetWeightGradientsAt(5)), fForgetBiasGradients(
this->GetBiasGradientsAt(1)),
366 fWeightsCandidateGradients(
this->GetWeightGradientsAt(2)),
367 fWeightsCandidateStateGradients(
this->GetWeightGradientsAt(6)),
368 fCandidateBiasGradients(
this->GetBiasGradientsAt(2)), fWeightsOutputGradients(
this->GetWeightGradientsAt(3)),
369 fWeightsOutputStateGradients(
this->GetWeightGradientsAt(7)), fOutputBiasGradients(
this->GetBiasGradientsAt(3))
382 Architecture_t::InitializeLSTMTensors(
this);
386template <
typename Architecture_t>
389 fStateSize(
layer.fStateSize),
390 fCellSize(
layer.fCellSize),
391 fTimeSteps(
layer.fTimeSteps),
392 fRememberState(
layer.fRememberState),
393 fReturnSequence(
layer.fReturnSequence),
394 fF1(
layer.GetActivationFunctionF1()),
395 fF2(
layer.GetActivationFunctionF2()),
396 fInputValue(
layer.GetBatchSize(),
layer.GetStateSize()),
397 fCandidateValue(
layer.GetBatchSize(),
layer.GetStateSize()),
398 fForgetValue(
layer.GetBatchSize(),
layer.GetStateSize()),
399 fOutputValue(
layer.GetBatchSize(),
layer.GetStateSize()),
400 fState(
layer.GetBatchSize(),
layer.GetStateSize()),
401 fCell(
layer.GetBatchSize(),
layer.GetCellSize()),
402 fWeightsInputGate(
this->GetWeightsAt(0)),
403 fWeightsInputGateState(
this->GetWeightsAt(4)),
404 fInputGateBias(
this->GetBiasesAt(0)),
405 fWeightsForgetGate(
this->GetWeightsAt(1)),
406 fWeightsForgetGateState(
this->GetWeightsAt(5)),
407 fForgetGateBias(
this->GetBiasesAt(1)),
408 fWeightsCandidate(
this->GetWeightsAt(2)),
409 fWeightsCandidateState(
this->GetWeightsAt(6)),
410 fCandidateBias(
this->GetBiasesAt(2)),
411 fWeightsOutputGate(
this->GetWeightsAt(3)),
412 fWeightsOutputGateState(
this->GetWeightsAt(7)),
413 fOutputGateBias(
this->GetBiasesAt(3)),
414 fWeightsInputGradients(
this->GetWeightGradientsAt(0)),
415 fWeightsInputStateGradients(
this->GetWeightGradientsAt(4)),
416 fInputBiasGradients(
this->GetBiasGradientsAt(0)),
417 fWeightsForgetGradients(
this->GetWeightGradientsAt(1)),
418 fWeightsForgetStateGradients(
this->GetWeightGradientsAt(5)),
419 fForgetBiasGradients(
this->GetBiasGradientsAt(1)),
420 fWeightsCandidateGradients(
this->GetWeightGradientsAt(2)),
421 fWeightsCandidateStateGradients(
this->GetWeightGradientsAt(6)),
422 fCandidateBiasGradients(
this->GetBiasGradientsAt(2)),
423 fWeightsOutputGradients(
this->GetWeightGradientsAt(3)),
424 fWeightsOutputStateGradients(
this->GetWeightGradientsAt(7)),
425 fOutputBiasGradients(
this->GetBiasGradientsAt(3))
466 Architecture_t::InitializeLSTMTensors(
this);
470template <
typename Architecture_t>
475 Architecture_t::InitializeLSTMDescriptors(fDescriptors,
this);
476 Architecture_t::InitializeLSTMWorkspace(fWorkspace, fDescriptors,
this);
480template <
typename Architecture_t>
489 Architecture_t::MultiplyTranspose(
tmpState, fState, fWeightsInputGateState);
490 Architecture_t::MultiplyTranspose(fInputValue,
input, fWeightsInputGate);
491 Architecture_t::ScaleAdd(fInputValue,
tmpState);
492 Architecture_t::AddRowWise(fInputValue, fInputGateBias);
493 DNN::evaluateDerivativeMatrix<Architecture_t>(
di, fInp, fInputValue);
494 DNN::evaluateMatrix<Architecture_t>(fInputValue, fInp);
498template <
typename Architecture_t>
507 Architecture_t::MultiplyTranspose(
tmpState, fState, fWeightsForgetGateState);
508 Architecture_t::MultiplyTranspose(fForgetValue,
input, fWeightsForgetGate);
509 Architecture_t::ScaleAdd(fForgetValue,
tmpState);
510 Architecture_t::AddRowWise(fForgetValue, fForgetGateBias);
511 DNN::evaluateDerivativeMatrix<Architecture_t>(df,
fFor, fForgetValue);
512 DNN::evaluateMatrix<Architecture_t>(fForgetValue,
fFor);
516template <
typename Architecture_t>
525 Architecture_t::MultiplyTranspose(
tmpState, fState, fWeightsCandidateState);
526 Architecture_t::MultiplyTranspose(fCandidateValue,
input, fWeightsCandidate);
527 Architecture_t::ScaleAdd(fCandidateValue,
tmpState);
528 Architecture_t::AddRowWise(fCandidateValue, fCandidateBias);
529 DNN::evaluateDerivativeMatrix<Architecture_t>(
dc, fCan, fCandidateValue);
530 DNN::evaluateMatrix<Architecture_t>(fCandidateValue, fCan);
534template <
typename Architecture_t>
543 Architecture_t::MultiplyTranspose(
tmpState, fState, fWeightsOutputGateState);
544 Architecture_t::MultiplyTranspose(fOutputValue,
input, fWeightsOutputGate);
545 Architecture_t::ScaleAdd(fOutputValue,
tmpState);
546 Architecture_t::AddRowWise(fOutputValue, fOutputGateBias);
547 DNN::evaluateDerivativeMatrix<Architecture_t>(
dout, fOut, fOutputValue);
548 DNN::evaluateMatrix<Architecture_t>(fOutputValue, fOut);
554template <
typename Architecture_t>
560 if (Architecture_t::IsCudnn()) {
567 Architecture_t::Rearrange(
x,
input);
570 const auto &weights = this->GetWeightsTensor();
575 auto &
hx = this->fState;
577 auto &
cx = this->fCell;
579 auto &
hy = this->fState;
580 auto &
cy = this->fCell;
587 if (fReturnSequence) {
588 Architecture_t::Rearrange(this->GetOutput(),
y);
591 Tensor_t tmp = (
y.At(
y.GetShape()[0] - 1)).Reshape({
y.GetShape()[1], 1,
y.GetShape()[2]});
592 Architecture_t::Copy(this->GetOutput(),
tmp);
605 Tensor_t arrInput( fTimeSteps, this->GetBatchSize(), this->GetInputWidth());
613 if (!this->fRememberState) {
619 for (
size_t t = 0; t < fTimeSteps; ++t) {
623 ForgetGate(
arrInputMt, fDerivativesForget[t]);
624 CandidateValue(
arrInputMt, fDerivativesCandidate[t]);
625 OutputGate(
arrInputMt, fDerivativesOutput[t]);
627 Architecture_t::Copy(this->GetInputGateTensorAt(t), fInputValue);
628 Architecture_t::Copy(this->GetForgetGateTensorAt(t), fForgetValue);
629 Architecture_t::Copy(this->GetCandidateGateTensorAt(t), fCandidateValue);
630 Architecture_t::Copy(this->GetOutputGateTensorAt(t), fOutputValue);
632 CellForward(fInputValue, fForgetValue, fCandidateValue, fOutputValue);
635 Architecture_t::Copy(this->GetCellTensorAt(t), fCell);
640 Architecture_t::Rearrange(this->GetOutput(),
arrOutput);
646 tmp =
tmp.Reshape( {
tmp.GetShape()[0],
tmp.GetShape()[1], 1});
648 assert(
tmp.GetShape()[0] ==
this->GetOutput().GetShape()[2]);
649 Architecture_t::Rearrange(this->GetOutput(),
tmp);
656template <
typename Architecture_t>
667 Matrix_t cache(fCell.GetNrows(), fCell.GetNcols());
668 Architecture_t::Copy(cache, fCell);
672 DNN::evaluateMatrix<Architecture_t>(cache,
fAT);
677 Architecture_t::Copy(fState, cache);
682template <
typename Architecture_t>
689 if (Architecture_t::IsCudnn()) {
701 if (!fReturnSequence) {
704 Architecture_t::InitializeZero(
dy);
712 Architecture_t::Copy(
tmp2, this->GetActivationGradients());
714 Architecture_t::Rearrange(
y, this->GetOutput());
715 Architecture_t::Rearrange(
dy, this->GetActivationGradients());
721 const auto &weights = this->GetWeightsTensor();
728 auto &
hx = this->GetState();
729 auto &
cx = this->GetCell();
740 Architecture_t::RNNBackward(
x,
hx,
cx,
y,
dy,
dhy,
dcy, weights,
dx,
dhx,
dcx,
weightGradients,
rnnDesc,
rnnWork);
788 if (fReturnSequence) {
789 Architecture_t::Rearrange(
arr_output, this->GetOutput());
790 Architecture_t::Rearrange(
arr_actgradients, this->GetActivationGradients());
800 Architecture_t::Rearrange(
tmp_grad, this->GetActivationGradients());
807 fWeightsInputGradients.Zero();
808 fWeightsInputStateGradients.Zero();
809 fInputBiasGradients.Zero();
812 fWeightsForgetGradients.Zero();
813 fWeightsForgetStateGradients.Zero();
814 fForgetBiasGradients.Zero();
817 fWeightsCandidateGradients.Zero();
818 fWeightsCandidateStateGradients.Zero();
819 fCandidateBiasGradients.Zero();
822 fWeightsOutputGradients.Zero();
823 fWeightsOutputStateGradients.Zero();
824 fOutputBiasGradients.Zero();
827 for (
size_t t = fTimeSteps; t > 0; t--) {
837 this->GetInputGateTensorAt(t-1), this->GetForgetGateTensorAt(t-1),
838 this->GetCandidateGateTensorAt(t-1), this->GetOutputGateTensorAt(t-1),
840 fDerivativesInput[t-1], fDerivativesForget[t-1],
841 fDerivativesCandidate[t-1], fDerivativesOutput[t-1], t-1);
848 this->GetInputGateTensorAt(t-1), this->GetForgetGateTensorAt(t-1),
849 this->GetCandidateGateTensorAt(t-1), this->GetOutputGateTensorAt(t-1),
851 fDerivativesInput[t-1], fDerivativesForget[t-1],
852 fDerivativesCandidate[t-1], fDerivativesOutput[t-1], t-1);
864template <
typename Architecture_t>
882 DNN::evaluateDerivativeMatrix<Architecture_t>(
cell_gradient,
fAT, this->GetCellTensorAt(t));
885 Matrix_t cell_tanh(this->GetCellTensorAt(t).GetNrows(), this->GetCellTensorAt(t).GetNcols());
886 Architecture_t::Copy(
cell_tanh, this->GetCellTensorAt(t));
890 fWeightsInputGradients, fWeightsForgetGradients, fWeightsCandidateGradients,
891 fWeightsOutputGradients, fWeightsInputStateGradients, fWeightsForgetStateGradients,
892 fWeightsCandidateStateGradients, fWeightsOutputStateGradients, fInputBiasGradients, fForgetBiasGradients,
893 fCandidateBiasGradients, fOutputBiasGradients,
di, df,
dc,
dout,
896 fWeightsInputGate, fWeightsForgetGate, fWeightsCandidate, fWeightsOutputGate,
897 fWeightsInputGateState, fWeightsForgetGateState, fWeightsCandidateState,
903template <
typename Architecture_t>
912template<
typename Architecture_t>
916 std::cout <<
" LSTM Layer: \t ";
917 std::cout <<
" (NInput = " << this->GetInputSize();
918 std::cout <<
", NState = " << this->GetStateSize();
919 std::cout <<
", NTime = " << this->GetTimeSteps() <<
" )";
920 std::cout <<
"\tOutput = ( " << this->GetOutput().GetFirstSize() <<
" , " << this->GetOutput()[0].GetNrows() <<
" , " << this->GetOutput()[0].GetNcols() <<
" )\n";
924template <
typename Architecture_t>
939 this->WriteMatrixToXML(
layerxml,
"InputWeights", this->GetWeightsAt(0));
940 this->WriteMatrixToXML(
layerxml,
"InputStateWeights", this->GetWeightsAt(1));
941 this->WriteMatrixToXML(
layerxml,
"InputBiases", this->GetBiasesAt(0));
942 this->WriteMatrixToXML(
layerxml,
"ForgetWeights", this->GetWeightsAt(2));
943 this->WriteMatrixToXML(
layerxml,
"ForgetStateWeights", this->GetWeightsAt(3));
944 this->WriteMatrixToXML(
layerxml,
"ForgetBiases", this->GetBiasesAt(1));
945 this->WriteMatrixToXML(
layerxml,
"CandidateWeights", this->GetWeightsAt(4));
946 this->WriteMatrixToXML(
layerxml,
"CandidateStateWeights", this->GetWeightsAt(5));
947 this->WriteMatrixToXML(
layerxml,
"CandidateBiases", this->GetBiasesAt(2));
948 this->WriteMatrixToXML(
layerxml,
"OuputWeights", this->GetWeightsAt(6));
949 this->WriteMatrixToXML(
layerxml,
"OutputStateWeights", this->GetWeightsAt(7));
950 this->WriteMatrixToXML(
layerxml,
"OutputBiases", this->GetBiasesAt(3));
954template <
typename Architecture_t>
959 this->ReadMatrixXML(parent,
"InputWeights", this->GetWeightsAt(0));
960 this->ReadMatrixXML(parent,
"InputStateWeights", this->GetWeightsAt(1));
961 this->ReadMatrixXML(parent,
"InputBiases", this->GetBiasesAt(0));
962 this->ReadMatrixXML(parent,
"ForgetWeights", this->GetWeightsAt(2));
963 this->ReadMatrixXML(parent,
"ForgetStateWeights", this->GetWeightsAt(3));
964 this->ReadMatrixXML(parent,
"ForgetBiases", this->GetBiasesAt(1));
965 this->ReadMatrixXML(parent,
"CandidateWeights", this->GetWeightsAt(4));
966 this->ReadMatrixXML(parent,
"CandidateStateWeights", this->GetWeightsAt(5));
967 this->ReadMatrixXML(parent,
"CandidateBiases", this->GetBiasesAt(2));
968 this->ReadMatrixXML(parent,
"OuputWeights", this->GetWeightsAt(6));
969 this->ReadMatrixXML(parent,
"OutputStateWeights", this->GetWeightsAt(7));
970 this->ReadMatrixXML(parent,
"OutputBiases", this->GetBiasesAt(3));
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
void InputGate(const Matrix_t &input, Matrix_t &di)
Decides the values we'll update (NN with Sigmoid)
const Matrix_t & GetForgetGateTensorAt(size_t i) const
Matrix_t & GetWeightsOutputGateState()
const std::vector< Matrix_t > & GetOutputGateTensor() const
Tensor_t fWeightsTensor
Tensor for all weights.
const std::vector< Matrix_t > & GetInputGateTensor() const
std::vector< Matrix_t > & GetDerivativesOutput()
const Matrix_t & GetWeigthsForgetStateGradients() const
Matrix_t & GetWeightsForgetGate()
typename Architecture_t::Matrix_t Matrix_t
Matrix_t & GetCandidateGateTensorAt(size_t i)
void InitState(DNN::EInitialization m=DNN::EInitialization::kZero)
Initialize the hidden state and cell state method.
Matrix_t & fWeightsCandidateGradients
Gradients w.r.t the candidate gate - input weights.
const Matrix_t & GetOutputGateBias() const
Matrix_t & GetWeightsCandidateStateGradients()
Matrix_t & GetWeightsInputGate()
Matrix_t & GetWeightsInputGateState()
const std::vector< Matrix_t > & GetCandidateGateTensor() const
const Matrix_t & GetInputGateTensorAt(size_t i) const
std::vector< Matrix_t > & GetForgetGateTensor()
std::vector< Matrix_t > cell_value
cell value for every time step
void Backward(Tensor_t &gradients_backward, const Tensor_t &activations_backward) override
Backpropagates the error.
Matrix_t & fWeightsOutputGradients
Gradients w.r.t the output gate - input weights.
Matrix_t & GetOutputGateBias()
Matrix_t & fOutputBiasGradients
Gradients w.r.t the output gate - bias weights.
void Initialize() override
Initialize the weights according to the given initialization method.
DNN::EActivationFunction fF1
Activation function: sigmoid.
Tensor_t fDy
cached activation gradient (input of backward) as T x B x S
Matrix_t & fWeightsOutputGate
Output Gate weights for input, fWeights[6].
Matrix_t & GetForgetGateBias()
Matrix_t & fWeightsCandidateStateGradients
Gradients w.r.t the candidate gate - hidden state weights.
const Matrix_t & GetInputGateBias() const
typename Architecture_t::Scalar_t Scalar_t
size_t GetInputSize() const
Getters.
Matrix_t & GetForgetGateTensorAt(size_t i)
const Matrix_t & GetOutputGateTensorAt(size_t i) const
const Matrix_t & GetCellTensorAt(size_t i) const
Tensor_t fX
cached input tensor as T x B x I
DNN::EActivationFunction GetActivationFunctionF2() const
Matrix_t & GetCellTensorAt(size_t i)
Matrix_t & fWeightsInputStateGradients
Gradients w.r.t the input gate - hidden state weights.
void CellForward(Matrix_t &inputGateValues, const Matrix_t &forgetGateValues, const Matrix_t &candidateValues, const Matrix_t &outputGateValues)
Forward for a single cell (time unit)
Matrix_t & CellBackward(Matrix_t &state_gradients_backward, Matrix_t &cell_gradients_backward, const Matrix_t &precStateActivations, const Matrix_t &precCellActivations, const Matrix_t &input_gate, const Matrix_t &forget_gate, const Matrix_t &candidate_gate, const Matrix_t &output_gate, const Matrix_t &input, Matrix_t &input_gradient, Matrix_t &di, Matrix_t &df, Matrix_t &dc, Matrix_t &dout, size_t t)
Backward for a single time unit a the corresponding call to Forward(...).
const Matrix_t & GetWeightsInputStateGradients() const
std::vector< Matrix_t > fDerivativesOutput
First fDerivatives of the activations output gate.
size_t GetStateSize() const
void ReadWeightsFromXML(void *parent) override
Read the information and the weights about the layer from XML node.
Matrix_t & fWeightsForgetGateState
Forget Gate weights for prev state, fWeights[3].
Matrix_t & fOutputGateBias
Output Gate bias.
std::vector< Matrix_t > fDerivativesCandidate
First fDerivatives of the activations candidate gate.
const Matrix_t & GetInputDerivativesAt(size_t i) const
Matrix_t & fWeightsForgetGate
Forget Gate weights for input, fWeights[2].
Matrix_t & fWeightsInputGradients
Gradients w.r.t the input gate - input weights.
typename Architecture_t::Tensor_t Tensor_t
const std::vector< Matrix_t > & GetDerivativesInput() const
Matrix_t & GetWeightsCandidate()
Matrix_t & fForgetGateBias
Forget Gate bias.
Matrix_t & GetWeightsInputGradients()
Matrix_t & GetCandidateBiasGradients()
Matrix_t & GetWeightsOutputGradients()
Matrix_t & fCandidateBias
Candidate Gate bias.
Matrix_t fCandidateValue
Computed candidate values.
Tensor_t & GetWeightGradientsTensor()
bool DoesRememberState() const
const Matrix_t & GetWeightsOutputGradients() const
typename Architecture_t::RecurrentDescriptor_t LayerDescriptor_t
const Matrix_t & GetWeightsInputGradients() const
Matrix_t & GetWeightsCandidateState()
Matrix_t & GetInputBiasGradients()
const Matrix_t & GetInputBiasGradients() const
size_t GetTimeSteps() const
DNN::EActivationFunction fF2
Activation function: tanh.
void AddWeightsXMLTo(void *parent) override
Writes the information and the weights about the layer in an XML node.
Matrix_t & fInputBiasGradients
Gradients w.r.t the input gate - bias weights.
Matrix_t & GetWeightsOutputStateGradients()
Matrix_t & fWeightsCandidateState
Candidate Gate weights for prev state, fWeights[5].
Matrix_t & GetForgetGateValue()
std::vector< Matrix_t > fDerivativesForget
First fDerivatives of the activations forget gate.
const Tensor_t & GetWeightGradientsTensor() const
Matrix_t & GetForgetDerivativesAt(size_t i)
const Matrix_t & GetWeightsInputGateState() const
Matrix_t & GetWeightsInputStateGradients()
typename Architecture_t::DropoutDescriptor_t HelperDescriptor_t
Matrix_t & fForgetBiasGradients
Gradients w.r.t the forget gate - bias weights.
const Matrix_t & GetCandidateBias() const
std::vector< Matrix_t > output_gate_value
output gate value for every time step
const std::vector< Matrix_t > & GetDerivativesCandidate() const
size_t fStateSize
Hidden state size for LSTM.
void CandidateValue(const Matrix_t &input, Matrix_t &dc)
Decides the new candidate values (NN with Tanh)
std::vector< Matrix_t > fDerivativesInput
First fDerivatives of the activations input gate.
const Matrix_t & GetWeightsForgetGateState() const
Matrix_t & GetWeightsForgetGateState()
const Matrix_t & GetWeightsInputGate() const
const Matrix_t & GetInputGateValue() const
void Update(const Scalar_t learningRate)
bool DoesReturnSequence() const
Tensor_t fDx
cached gradient on the input (output of backward) as T x B x I
typename Architecture_t::RNNWorkspace_t RNNWorkspace_t
Matrix_t & GetOutputGateValue()
TBasicLSTMLayer(size_t batchSize, size_t stateSize, size_t inputSize, size_t timeSteps, bool rememberState=false, bool returnSequence=false, DNN::EActivationFunction f1=DNN::EActivationFunction::kSigmoid, DNN::EActivationFunction f2=DNN::EActivationFunction::kTanh, bool training=true, DNN::EInitialization fA=DNN::EInitialization::kZero)
Constructor.
Matrix_t & GetWeightsForgetStateGradients()
const Matrix_t & GetOutputBiasGradients() const
typename Architecture_t::TensorDescriptor_t TensorDescriptor_t
const Matrix_t & GetWeightsOutputStateGradients() const
Matrix_t & fWeightsOutputStateGradients
Gradients w.r.t the output gate - hidden state weights.
bool fReturnSequence
Return in output full sequence or just last element.
Matrix_t & GetWeightsForgetGradients()
Matrix_t & GetWeightsCandidateGradients()
void Forward(Tensor_t &input, bool isTraining=true) override
Computes the next hidden state and next cell state with given input matrix.
const Matrix_t & GetWeightsForgetGradients() const
Matrix_t fCell
Cell state of LSTM.
std::vector< Matrix_t > & GetDerivativesCandidate()
const Matrix_t & GetForgetBiasGradients() const
std::vector< Matrix_t > & GetOutputGateTensor()
Matrix_t & GetCandidateValue()
const Matrix_t & GetForgetDerivativesAt(size_t i) const
Matrix_t fState
Hidden state of LSTM.
void OutputGate(const Matrix_t &input, Matrix_t &dout)
Computes output values (NN with Sigmoid)
const Matrix_t & GetForgetGateValue() const
std::vector< Matrix_t > candidate_gate_value
candidate gate value for every time step
Matrix_t & GetInputGateValue()
const Matrix_t & GetState() const
const Matrix_t & GetWeightsCandidateState() const
Matrix_t & GetCandidateBias()
const std::vector< Matrix_t > & GetForgetGateTensor() const
const std::vector< Matrix_t > & GetDerivativesOutput() const
const std::vector< Matrix_t > & GetCellTensor() const
const Tensor_t & GetWeightsTensor() const
Matrix_t & fWeightsInputGate
Input Gate weights for input, fWeights[0].
std::vector< Matrix_t > & GetCandidateGateTensor()
const Matrix_t & GetOutputDerivativesAt(size_t i) const
const Matrix_t & GetCell() const
Matrix_t & fWeightsForgetStateGradients
Gradients w.r.t the forget gate - hidden state weights.
const Matrix_t & GetCandidateGateTensorAt(size_t i) const
Matrix_t fOutputValue
Computed output gate values.
size_t fCellSize
Cell state size of LSTM.
Matrix_t & GetOutputDerivativesAt(size_t i)
Matrix_t & GetInputGateTensorAt(size_t i)
std::vector< Matrix_t > & GetDerivativesInput()
Matrix_t & fWeightsOutputGateState
Output Gate weights for prev state, fWeights[7].
const std::vector< Matrix_t > & GetDerivativesForget() const
Matrix_t & GetForgetBiasGradients()
const Matrix_t & GetForgetGateBias() const
const Matrix_t & GetCandidateDerivativesAt(size_t i) const
Matrix_t & GetInputGateBias()
Matrix_t & GetOutputGateTensorAt(size_t i)
size_t fTimeSteps
Timesteps for LSTM.
const Matrix_t & GetCandidateBiasGradients() const
const Matrix_t & GetCandidateValue() const
typename Architecture_t::FilterDescriptor_t WeightsDescriptor_t
Matrix_t & fInputGateBias
Input Gate bias.
const Matrix_t & GetWeightsForgetGate() const
std::vector< Matrix_t > input_gate_value
input gate value for every time step
const Matrix_t & GetWeightsCandidateStateGradients() const
Tensor_t & GetWeightsTensor()
Matrix_t & fWeightsForgetGradients
Gradients w.r.t the forget gate - input weights.
std::vector< Matrix_t > & GetDerivativesForget()
const Matrix_t & GetWeightsOutputGate() const
void ForgetGate(const Matrix_t &input, Matrix_t &df)
Forgets the past values (NN with Sigmoid)
std::vector< Matrix_t > & GetInputGateTensor()
Matrix_t & GetOutputBiasGradients()
void Print() const override
Prints the info about the layer.
const Matrix_t & GetOutputGateValue() const
const Matrix_t & GetWeightsOutputGateState() const
Matrix_t & GetCandidateDerivativesAt(size_t i)
Matrix_t fInputValue
Computed input gate values.
Matrix_t & GetWeightsOutputGate()
const Matrix_t & GetWeightsCandidate() const
const Matrix_t & GetWeightsCandidateGradients() const
Tensor_t fWeightGradientsTensor
Tensor for all weight gradients.
Matrix_t & GetInputDerivativesAt(size_t i)
typename Architecture_t::RNNDescriptors_t RNNDescriptors_t
DNN::EActivationFunction GetActivationFunctionF1() const
Tensor_t fY
cached output tensor as T x B x S
std::vector< Matrix_t > forget_gate_value
forget gate value for every time step
Matrix_t & fWeightsCandidate
Candidate Gate weights for input, fWeights[4].
bool fRememberState
Remember state in next pass.
Matrix_t & fWeightsInputGateState
Input Gate weights for prev state, fWeights[1].
TDescriptors * fDescriptors
Keeps all the RNN descriptors.
std::vector< Matrix_t > & GetCellTensor()
size_t GetCellSize() const
Matrix_t & fCandidateBiasGradients
Gradients w.r.t the candidate gate - bias weights.
Matrix_t fForgetValue
Computed forget gate values.
Generic General Layer class.
virtual void Initialize()
Initialize the weights and biases according to the given initialization method.
size_t GetInputWidth() const
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=nullptr)
create new child element for parent node
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
EActivationFunction
Enum that represents layer activation functions.
create variable transformations