class_docstr: Long Short-Term Memory (LSTM)
  
  .. math::
     i_t = \rm{recurrent\_activation}(W_{ii} x_t + B_{ii} + W_{hi} h_{t-1} + B_{hi})
  
  .. math::
     f_t = \rm{recurrent\_activation}(W_{if} x_t + B_{if} + W_{hf} h_{t-1} + B_{hf})
  
  .. math::
     z_t = \rm{cell\_activation}(W_{iz} x_t + B_{iz} + W_{hz} h_{t-1} + B_{hz})
  
  .. math::
     o_t = \rm{recurrent\_activation}(W_{io} x_t + B_{io} + W_{ho} h_{t-1} + B_{ho})
  
  .. math::
     c_t = f_t * c_{t-1} + i_t * z_t
  
  .. math::
     h_t = o_t * \rm{activation(c_t)}
  
  Where:
  
  * :math:`i_t`, :math:`f_t`, :math:`o_t`, and :math:`z_t` are input, forget, output, and cell gates,
    respectively, at time ``t``.
  * :math:`c_t` is cell state at time ``t``.
  * :math:`h_t`  is the hidden state at time ``t``.
  * :math:`W_{ii}`, :math:`W_{if}`, :math:`W_{io}`, and :math:`W_{iz}` are input weights for input,
    forget, output, and cell gate, respectively.
  * :math:`B_{ii}`, :math:`B_{if}`, :math:`B_{io}`, and :math:`B_{iz}` are input biases for input,
    forget, output, and cell gate, respectively.
  * :math:`W_{hi}`, :math:`W_{hf}`, :math:`W_{ho}`, and :math:`W_{hz}` are recurrent weights for input,
    forget, output, and cell gate, respectively.
  * :math:`B_{hi}`, :math:`B_{hf}`, :math:`B_{ho}`, and :math:`B_{hz}` are recurrent weights for input,
    forget, output, and cell gate, respectively.
  
  Parameters
  ----------
  x: <s, b, I, T> (Required)
      * ``s`` is the sequence length, ``b`` is the batch size, and ``I`` is the
        input dimension.
  
  initial_h: <b, DIRECTIONS*H, T> (Required)
      * Initial hidden state. ``DIRECTIONS = 1`` for uni-directional.
        ``DIRECTIONS = 2`` for bi-directional LSTM.
      * ``H`` denotes hidden size.
      * ``[b, :H]`` and ``[b, H:]`` represents forward and reverse direction
        values, respectively.
  
  initial_c: <b, DIRECTIONS*H, T> (Required)
      * Initial cell state.
      * Format is same as ``initial_h``.
  
  weight_ih: const<4*H, I, T> (Required)
      * Input-hidden weight matrix
      * Weight tensor should be in order of
        ``[input_gate, forget_gate, output_gate, cell_gate]``.
      * If direction=="bidirectional", this is applied in forward direction.
      * If direction=="forward" or "backward" these weights are used.
  
  weight_hh: const<4*H, H, T> (Required)
      * Hidden-hidden weight matrix.
      * Weight tensor should be in order of
        ``[input_gate, forget_gate, output_gate, cell_gate]``.
      * If direction=="bidirectional", this is applied in forward direction.
      * If direction=="forward" or "backward" these weights are used.
  
  bias: const<4*H, T> (Optional, default all 0s)
      * bias = input-hidden bias + hidden-hidden bias
      * If direction=="bidirectional", this is applied in forward direction.
      * If direction=="forward" or "backward" this bias are used.
  
  peephole: const<3*H, T> (Optional, default all 0s)
      * Weight tensor for peephole.
      * Order is ``[input_gate, forget_gate, output_gate]``.
      * Shape of each peephole vector is ``(H,)`` (``H`` is hidden size).
      * If direction=="bidirectional", this is applied in forward direction.
      * If direction=="forward" or "backward" these weights are used.
  
  weight_ih_back: const<4*H, I, T> (Optional) -
      * Input-hidden weight matrix for backward direction for `bidirectinal LSTM`.
      * Weight tensor should be in order of
        ``[input_gate, forget_gate, output_gate, cell_gate]``.
      * Must be provided for `bidirectional LSTM`.
      * This is only used when `direction` is "bidirectional".
      * For direction="reverse" use `weight_ih` instead.
  
  weight_hh_back: const<4*H, H, T> (Optional) - Hidden-hidden weight matrix
      * Hidden-hidden weight matrix for backward direction for `bidirectinal LSTM`.
      * Weight tensor should be in order of
        ``[input_gate, forget_gate, output_gate, cell_gate]``.
      * Must be provided for `bidirectional LSTM`.
      * This is only used when `direction` is "bidirectional".
      * For direction="reverse" use `weight_hh` instead.
  
  bias_back: const<4*H, T> (Optional, default all 0s)
      * bias = input-hidden bias + hidden-hidden bias.
      * Bias of backward direction for `bidirectional lstm`
      * This is only used when `direction` is "bidirectional".
      * For direction="reverse" use `bias` instead.
  
  peephole_back: const<3*H, T> (Optional, default all 0s)
      * Weight tensor for peephole in backward direction for `bidirectional LSTM`.
      * Order is ``[input_gate, forget_gate, output_gate]``.
      * Shape of each peephole vector is ``(H,)`` (``H`` is hidden size).
      * Peephole of backward direction for `bidirectional lstm`
      * Bias of backward direction for `bidirectional lstm`
      * This is only used when `direction` is "bidirectional".
      * For direction="reverse" use `peephole` instead.
  
  direction: const<str> (Optional) [Default=forward]
      * One of the following: ``forward``, ``reverse``, or ``bidirectional``.
      * Must match ``DIRECTIONAL`` in initial states and weight parameters.
  
  output_sequence: const<bool> (Optional) [Default=False]
      * Outputs every step if ``True``.
  
  recurrent_activation: const<str> (Optional) [Default=sigmoid]
      * Activation applied on input, forget, and output gates.
      * Supported values: ``hard_sigmoid``, ``linear``, ``relu``, ``scaled_tanh``, ``sigmoid``, ``tanh``
  
  cell_activation: const<str> (Optional) [Default=tanh]
      * Activation applied on cell gate.
      * Supported values: ``hard_sigmoid``, ``linear``, ``relu``, ``scaled_tanh``, ``sigmoid``, ``tanh``
  
  activation: const<str> (Optional) [Default=tanh]
      * Activation applied on output gate.
      * Supported values: ``hard_sigmoid``, ``linear``, ``relu``, ``scaled_tanh``, ``sigmoid``, ``tanh``
  
  clip: const<T> (optional) [Default=None]
      * Cell gate is clipped to ``[-clip, +clip]``.
  
  Returns
  -------
  <s, b, DIRECTIONS*H, T> or <1, b, DIRECTIONS*H, T>
      * If ``output_sequence == True`` (hidden states from every step):
        ``<s, b, DIRECTIONS*H, T>``.
      * Else ``<1, b, DIRECTIONS*H, T>`` (hidden states of the final step).
  <b, DIRECTIONS*H, T>
      * Hidden states of the final step.
  <b, DIRECTIONS*H, T>
      * Memory state of the final step.
  
  Attributes
  ----------
  T: fp32
class_docstr_tok: ["Long","Short-Term","Memory","(","LSTM",")","..","math",":",":","i_t","=","\\rm","{","recurrent\\_activation","}","(","W_","{","ii","}","x_t","+","B_","{","ii","}","+","W_","{","hi","}","h_","{","t-1","}","+","B_","{","hi","}",")","..","math",":",":","f_t","=","\\rm","{","recurrent\\_activation","}","(","W_","{","if","}","x_t","+","B_","{","if","}","+","W_","{","hf","}","h_","{","t-1","}","+","B_","{","hf","}",")","..","math",":",":","z_t","=","\\rm","{","cell\\_activation","}","(","W_","{","iz","}","x_t","+","B_","{","iz","}","+","W_","{","hz","}","h_","{","t-1","}","+","B_","{","hz","}",")","..","math",":",":","o_t","=","\\rm","{","recurrent\\_activation","}","(","W_","{","io","}","x_t","+","B_","{","io","}","+","W_","{","ho","}","h_","{","t-1","}","+","B_","{","ho","}",")","..","math",":",":","c_t","=","f_t","*","c_","{","t-1","}","+","i_t","*","z_t","..","math",":",":","h_t","=","o_t","*","\\rm","{","activation","(","c_t",")","}","Where",":","*",":","math",":","`","i_t","`",",",":","math",":","`","f_t","`",",",":","math",":","`","o_t","`",",","and",":","math",":","`","z_t","`","are","input",",","forget",",","output",",","and","cell","gates",",","respectively",",","at","time","``","t","``",".","*",":","math",":","`","c_t","`","is","cell","state","at","time","``","t","``",".","*",":","math",":","`","h_t","`","is","the","hidden","state","at","time","``","t","``",".","*",":","math",":","`","W_","{","ii","}","`",",",":","math",":","`","W_","{","if","}","`",",",":","math",":","`","W_","{","io","}","`",",","and",":","math",":","`","W_","{","iz","}","`","are","input","weights","for","input",",","forget",",","output",",","and","cell","gate",",","respectively",".","*",":","math",":","`","B_","{","ii","}","`",",",":","math",":","`","B_","{","if","}","`",",",":","math",":","`","B_","{","io","}","`",",","and",":","math",":","`","B_","{","iz","}","`","are","input","biases","for","input",",","forget",",","output",",","and","cell","gate",",","respectively",".","*",":","math",":","`","W_","{","hi","}","`",",",":","math",":","`","W_","{","hf","}","`",",",":","math",":","`","W_","{","ho","}","`",",","and",":","math",":","`","W_","{","hz","}","`","are","recurrent","weights","for","input",",","forget",",","output",",","and","cell","gate",",","respectively",".","*",":","math",":","`","B_","{","hi","}","`",",",":","math",":","`","B_","{","hf","}","`",",",":","math",":","`","B_","{","ho","}","`",",","and",":","math",":","`","B_","{","hz","}","`","are","recurrent","weights","for","input",",","forget",",","output",",","and","cell","gate",",","respectively",".","Parameters","--","--","--","--","--","x",":","<","s",",","b",",","I",",","T",">","(","Required",")","*","``","s","``","is","the","sequence","length",",","``","b","``","is","the","batch","size",",","and","``","I","``","is","the","input","dimension",".","initial_h",":","<","b",",","DIRECTIONS","*","H",",","T",">","(","Required",")","*","Initial","hidden","state",".","``","DIRECTIONS","=","1","``","for","uni-directional",".","``","DIRECTIONS","=","2","``","for","bi-directional","LSTM",".","*","``","H","``","denotes","hidden","size",".","*","``","[","b",",",":","H","]","``","and","``","[","b",",","H",":","]","``","represents","forward","and","reverse","direction","values",",","respectively",".","initial_c",":","<","b",",","DIRECTIONS","*","H",",","T",">","(","Required",")","*","Initial","cell","state",".","*","Format","is","same","as","``","initial_h","``",".","weight_ih",":","const","<","4","*","H",",","I",",","T",">","(","Required",")","*","Input-hidden","weight","matrix","*","Weight","tensor","should","be","in","order","of","``","[","input_gate",",","forget_gate",",","output_gate",",","cell_gate","]","``",".","*","If","direction==","''","bidirectional","''",",","this","is","applied","in","forward","direction",".","*","If","direction==","''","forward","''","or","``","backward","''","these","weights","are","used",".","weight_hh",":","const","<","4","*","H",",","H",",","T",">","(","Required",")","*","Hidden-hidden","weight","matrix",".","*","Weight","tensor","should","be","in","order","of","``","[","input_gate",",","forget_gate",",","output_gate",",","cell_gate","]","``",".","*","If","direction==","''","bidirectional","''",",","this","is","applied","in","forward","direction",".","*","If","direction==","''","forward","''","or","``","backward","''","these","weights","are","used",".","bias",":","const","<","4","*","H",",","T",">","(","Optional",",","default","all","0s",")","*","bias","=","input-hidden","bias","+","hidden-hidden","bias","*","If","direction==","''","bidirectional","''",",","this","is","applied","in","forward","direction",".","*","If","direction==","''","forward","''","or","``","backward","''","this","bias","are","used",".","peephole",":","const","<","3","*","H",",","T",">","(","Optional",",","default","all","0s",")","*","Weight","tensor","for","peephole",".","*","Order","is","``","[","input_gate",",","forget_gate",",","output_gate","]","``",".","*","Shape","of","each","peephole","vector","is","``","(","H",",",")","``","(","``","H","``","is","hidden","size",")",".","*","If","direction==","''","bidirectional","''",",","this","is","applied","in","forward","direction",".","*","If","direction==","''","forward","''","or","``","backward","''","these","weights","are","used",".","weight_ih_back",":","const","<","4","*","H",",","I",",","T",">","(","Optional",")","-","*","Input-hidden","weight","matrix","for","backward","direction","for","`","bidirectinal","LSTM","`",".","*","Weight","tensor","should","be","in","order","of","``","[","input_gate",",","forget_gate",",","output_gate",",","cell_gate","]","``",".","*","Must","be","provided","for","`","bidirectional","LSTM","`",".","*","This","is","only","used","when","`","direction","`","is","``","bidirectional","''",".","*","For","direction=","''","reverse","''","use","`","weight_ih","`","instead",".","weight_hh_back",":","const","<","4","*","H",",","H",",","T",">","(","Optional",")","-","Hidden-hidden","weight","matrix","*","Hidden-hidden","weight","matrix","for","backward","direction","for","`","bidirectinal","LSTM","`",".","*","Weight","tensor","should","be","in","order","of","``","[","input_gate",",","forget_gate",",","output_gate",",","cell_gate","]","``",".","*","Must","be","provided","for","`","bidirectional","LSTM","`",".","*","This","is","only","used","when","`","direction","`","is","``","bidirectional","''",".","*","For","direction=","''","reverse","''","use","`","weight_hh","`","instead",".","bias_back",":","const","<","4","*","H",",","T",">","(","Optional",",","default","all","0s",")","*","bias","=","input-hidden","bias","+","hidden-hidden","bias",".","*","Bias","of","backward","direction","for","`","bidirectional","lstm","`","*","This","is","only","used","when","`","direction","`","is","``","bidirectional","''",".","*","For","direction=","''","reverse","''","use","`","bias","`","instead",".","peephole_back",":","const","<","3","*","H",",","T",">","(","Optional",",","default","all","0s",")","*","Weight","tensor","for","peephole","in","backward","direction","for","`","bidirectional","LSTM","`",".","*","Order","is","``","[","input_gate",",","forget_gate",",","output_gate","]","``",".","*","Shape","of","each","peephole","vector","is","``","(","H",",",")","``","(","``","H","``","is","hidden","size",")",".","*","Peephole","of","backward","direction","for","`","bidirectional","lstm","`","*","Bias","of","backward","direction","for","`","bidirectional","lstm","`","*","This","is","only","used","when","`","direction","`","is","``","bidirectional","''",".","*","For","direction=","''","reverse","''","use","`","peephole","`","instead",".","direction",":","const","<","str",">","(","Optional",")","[","Default=forward","]","*","One","of","the","following",":","``","forward","``",",","``","reverse","``",",","or","``","bidirectional","``",".","*","Must","match","``","DIRECTIONAL","``","in","initial","states","and","weight","parameters",".","output_sequence",":","const","<","bool",">","(","Optional",")","[","Default=False","]","*","Outputs","every","step","if","``","True","``",".","recurrent_activation",":","const","<","str",">","(","Optional",")","[","Default=sigmoid","]","*","Activation","applied","on","input",",","forget",",","and","output","gates",".","*","Supported","values",":","``","hard_sigmoid","``",",","``","linear","``",",","``","relu","``",",","``","scaled_tanh","``",",","``","sigmoid","``",",","``","tanh","``","cell_activation",":","const","<","str",">","(","Optional",")","[","Default=tanh","]","*","Activation","applied","on","cell","gate",".","*","Supported","values",":","``","hard_sigmoid","``",",","``","linear","``",",","``","relu","``",",","``","scaled_tanh","``",",","``","sigmoid","``",",","``","tanh","``","activation",":","const","<","str",">","(","Optional",")","[","Default=tanh","]","*","Activation","applied","on","output","gate",".","*","Supported","values",":","``","hard_sigmoid","``",",","``","linear","``",",","``","relu","``",",","``","scaled_tanh","``",",","``","sigmoid","``",",","``","tanh","``","clip",":","const","<","T",">","(","optional",")","[","Default=None","]","*","Cell","gate","is","clipped","to","``","[","-clip",",","+clip","]","``",".","Returns","--","--","--","-","<","s",",","b",",","DIRECTIONS","*","H",",","T",">","or","<","1",",","b",",","DIRECTIONS","*","H",",","T",">","*","If","``","output_sequence","==","True","``","(","hidden","states","from","every","step",")",":","``","<","s",",","b",",","DIRECTIONS","*","H",",","T",">","``",".","*","Else","``","<","1",",","b",",","DIRECTIONS","*","H",",","T",">","``","(","hidden","states","of","the","final","step",")",".","<","b",",","DIRECTIONS","*","H",",","T",">","*","Hidden","states","of","the","final","step",".","<","b",",","DIRECTIONS","*","H",",","T",">","*","Memory","state","of","the","final","step",".","Attributes","--","--","--","--","--","T",":","fp32"]
code: def type_inference(self):
      self._validate_inputs()
  
      sequence_length, batch_size, input_size = self.x.shape
      hidden_dim, hidden_size = self.weight_hh.shape
      dim_factor = 8 if self.direction.val == "bidirectional" else 4
      out_seq_len = sequence_length if self.output_sequence.val else 1
      num_directions = dim_factor // 4
      output_shape = [
          out_seq_len,
          batch_size,
          num_directions * hidden_size,
      ]
      output_h_shape = [batch_size, num_directions * hidden_size]
      output_c_shape = [batch_size, num_directions * hidden_size]
      return (
          types.tensor(self.x.dtype, tuple(output_shape)),
          types.tensor(self.x.dtype, tuple(output_h_shape)),
          types.tensor(self.x.dtype, tuple(output_c_shape)),
      )
  
file_path: coremltools/coremltools/converters/mil/mil/ops/defs/iOS15/recurrent.py
imports: from coremltools.converters.mil.mil import Operation, Var, types
  from coremltools.converters.mil.mil.input_type import DefaultInputs, InputSpec, TensorInputType
  from coremltools.converters.mil.mil.ops.defs._op_reqs import register_op
label_desc: Use image node_id 2 for calling the lstm obj's underlying member method code with example usage: obj.type_inference() and returns: types,  types,  types