MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / call

Method call

tensorflow/python/ops/rnn_cell_impl.py:743–789  ·  view source on GitHub ↗

Long short-term memory cell (LSTM). Args: inputs: `2-D` tensor with shape `[batch_size, input_size]`. state: An `LSTMStateTuple` of state tensors, each shaped `[batch_size, num_units]`, if `state_is_tuple` has been set to `True`. Otherwise, a `Tensor` shaped `[batch

(self, inputs, state)

Source from the content-addressed store, hash-verified

741 self.built = True
742
743 def call(self, inputs, state):
744 """Long short-term memory cell (LSTM).
745
746 Args:
747 inputs: `2-D` tensor with shape `[batch_size, input_size]`.
748 state: An `LSTMStateTuple` of state tensors, each shaped `[batch_size,
749 num_units]`, if `state_is_tuple` has been set to `True`. Otherwise, a
750 `Tensor` shaped `[batch_size, 2 * num_units]`.
751
752 Returns:
753 A pair containing the new hidden state, and the new state (either a
754 `LSTMStateTuple` or a concatenated state, depending on
755 `state_is_tuple`).
756 """
757 _check_rnn_cell_input_dtypes([inputs, state])
758
759 sigmoid = math_ops.sigmoid
760 one = constant_op.constant(1, dtype=dtypes.int32)
761 # Parameters of gates are concatenated into one multiply for efficiency.
762 if self._state_is_tuple:
763 c, h = state
764 else:
765 c, h = array_ops.split(value=state, num_or_size_splits=2, axis=one)
766
767 gate_inputs = math_ops.matmul(
768 array_ops.concat([inputs, h], 1), self._kernel)
769 gate_inputs = nn_ops.bias_add(gate_inputs, self._bias)
770
771 # i = input_gate, j = new_input, f = forget_gate, o = output_gate
772 i, j, f, o = array_ops.split(
773 value=gate_inputs, num_or_size_splits=4, axis=one)
774
775 forget_bias_tensor = constant_op.constant(self._forget_bias, dtype=f.dtype)
776 # Note that using `add` and `multiply` instead of `+` and `*` gives a
777 # performance improvement. So using those at the cost of readability.
778 add = math_ops.add
779 multiply = math_ops.multiply
780 new_c = add(
781 multiply(c, sigmoid(add(f, forget_bias_tensor))),
782 multiply(sigmoid(i), self._activation(j)))
783 new_h = multiply(self._activation(new_c), sigmoid(o))
784
785 if self._state_is_tuple:
786 new_state = LSTMStateTuple(new_c, new_h)
787 else:
788 new_state = array_ops.concat([new_c, new_h], 1)
789 return new_h, new_state
790
791 def get_config(self):
792 config = {

Callers

nothing calls this directly

Calls 9

LSTMStateTupleClass · 0.85
multiplyFunction · 0.70
sigmoidFunction · 0.70
addFunction · 0.50
constantMethod · 0.45
splitMethod · 0.45
matmulMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected