Class ov::op::v0::LSTMCell#

class LSTMCell : public ov::op::util::RNNCellBase#

Class for single lstm cell node.

See also

LSTMSequence, RNNCell, GRUCell

Note

Following implementation supports:

Note

It calculates following equations:

        it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi)
        ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf)
        ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc)
        Ct = ft (.) Ct-1 + it (.) ct
        ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo)
        Ht = ot (.) h(Ct)

        *       - Is a dot product,
        (.)     - is a Hadamard product (element-wise),
        f, g, h - are activation functions.

Note

This class represents only single cell (for current time step) and not the whole LSTM Sequence layer

Public Functions

LSTMCell(const Output<Node> &X, const Output<Node> &initial_hidden_state, const Output<Node> &initial_cell_state, const Output<Node> &W, const Output<Node> &R, std::size_t hidden_size, LSTMWeightsFormat weights_format = LSTMWeightsFormat::IFCO, const std::vector<std::string> &activations = std::vector<std::string>{"sigmoid", "tanh", "tanh"}, const std::vector<float> &activations_alpha = {}, const std::vector<float> &activations_beta = {}, float clip = 0.f, bool input_forget = false)#

Constructs LSTMCell node.

Parameters:
  • X[in] The input tensor with shape: [batch_size, input_size].

  • initial_hidden_state[in] The hidden state tensor at current time step with shape: [batch_size, hidden_size].

  • initial_cell_state[in] The cell state tensor at current time step with shape: [batch_size, hidden_size].

  • W[in] The gate weights tensor with shape: [4*hidden_size, input_size].

  • R[in] The recurrence weights tensor with shape: [4*hidden_size, hidden_size].

  • hidden_size[in] The number of hidden units for recurrent cell.

  • weights_format[in] The order of gates in weights tensors. The default format is IFCO since it is used by DNNL.

  • activations[in] The vector of activation functions used inside recurrent cell.

  • activations_alpha[in] The vector of alpha parameters for activation functions in order respective to activation list.

  • activations_beta[in] The vector of beta parameters for activation functions in order respective to activation list.

  • clip[in] The value defining clipping range [-clip, clip] on input of activation functions.

  • input_forget[in] Controls coupling input and forget gates.

LSTMCell(const Output<Node> &X, const Output<Node> &initial_hidden_state, const Output<Node> &initial_cell_state, const Output<Node> &W, const Output<Node> &R, const Output<Node> &B, std::size_t hidden_size, LSTMWeightsFormat weights_format = LSTMWeightsFormat::IFCO, const std::vector<std::string> &activations = std::vector<std::string>{"sigmoid", "tanh", "tanh"}, const std::vector<float> &activations_alpha = {}, const std::vector<float> &activations_beta = {}, float clip = 0.f, bool input_forget = false)#

Constructs LSTMCell node.

Parameters:
  • X[in] The input tensor with shape: [batch_size, input_size].

  • initial_hidden_state[in] The hidden state tensor at current time step with shape: [batch_size, hidden_size].

  • initial_cell_state[in] The cell state tensor at current time step with shape: [batch_size, hidden_size].

  • W[in] The weight tensor with shape: [4*hidden_size, input_size].

  • R[in] The recurrence weight tensor with shape: [4*hidden_size, hidden_size].

  • B[in] The bias tensor for gates with shape: [4*hidden_size].

  • hidden_size[in] The number of hidden units for recurrent cell.

  • weights_format[in] The order of gates in weights tensors. The default format is IFCO since it is used by DNNL.

  • activations[in] The vector of activation functions used inside recurrent cell.

  • activations_alpha[in] The vector of alpha parameters for activation functions in order respective to activation list.

  • activations_beta[in] The vector of beta parameters for activation functions in order respective to activation list.

  • clip[in] The value defining clipping range [-clip, clip] on input of activation functions.

  • input_forget[in] Controls coupling input and forget gates.

LSTMCell(const Output<Node> &X, const Output<Node> &initial_hidden_state, const Output<Node> &initial_cell_state, const Output<Node> &W, const Output<Node> &R, const Output<Node> &B, const Output<Node> &P, std::size_t hidden_size, LSTMWeightsFormat weights_format = LSTMWeightsFormat::IFCO, const std::vector<std::string> &activations = std::vector<std::string>{"sigmoid", "tanh", "tanh"}, const std::vector<float> &activations_alpha = {}, const std::vector<float> &activations_beta = {}, float clip = 0.f, bool input_forget = false)#

Constructs LSTMCell node.

Parameters:
  • X[in] The input tensor with shape: [batch_size, input_size].

  • initial_hidden_state[in] The hidden state tensor at current time step with shape: [batch_size, hidden_size].

  • initial_cell_state[in] The cell state tensor at current time step with shape: [batch_size, hidden_size].

  • W[in] The weight tensor with shape: [4*hidden_size, input_size].

  • R[in] The recurrence weight tensor with shape: [4*hidden_size, hidden_size].

  • B[in] The bias tensor for gates with shape: [4*hidden_size].

  • P[in] The weight tensor for peepholes with shape: [3*hidden_size] - 3 equals to only iof gates. The order is: input, output, forget gates.

  • hidden_size[in] The number of hidden units for recurrent cell.

  • weights_format[in] The order of gates in weights tensors. The default format is IFCO since it is used by DNNL.

  • activations[in] The vector of activation functions used inside recurrent cell.

  • activations_alpha[in] The vector of alpha parameters for activation functions in order respective to activation list.

  • activations_beta[in] The vector of beta parameters for activation functions in order respective to activation list.

  • clip[in] The value defining clipping range [-clip, clip] on input of activation functions.

  • input_forget[in] Controls coupling input and forget gates.

virtual void validate_and_infer_types() override#

Verifies that attributes and inputs are consistent and computes output shapes and element types. Must be implemented by concrete child classes so that it can be run any number of times.

Throws if the node is invalid.