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

Method call

tensorflow/python/ops/rnn_cell_impl.py:987–1063  ·  view source on GitHub ↗

Run one step of LSTM. Args: inputs: input Tensor, must be 2-D, `[batch, input_size]`. state: if `state_is_tuple` is False, this must be a state Tensor, `2-D, [batch, state_size]`. If `state_is_tuple` is True, this must be a tuple of state Tensors, both `2-D`, with c

(self, inputs, state)

Source from the content-addressed store, hash-verified

985 self.built = True
986
987 def call(self, inputs, state):
988 """Run one step of LSTM.
989
990 Args:
991 inputs: input Tensor, must be 2-D, `[batch, input_size]`.
992 state: if `state_is_tuple` is False, this must be a state Tensor, `2-D,
993 [batch, state_size]`. If `state_is_tuple` is True, this must be a tuple
994 of state Tensors, both `2-D`, with column sizes `c_state` and `m_state`.
995
996 Returns:
997 A tuple containing:
998
999 - A `2-D, [batch, output_dim]`, Tensor representing the output of the
1000 LSTM after reading `inputs` when previous state was `state`.
1001 Here output_dim is:
1002 num_proj if num_proj was set,
1003 num_units otherwise.
1004 - Tensor(s) representing the new state of LSTM after reading `inputs` when
1005 the previous state was `state`. Same type and shape(s) as `state`.
1006
1007 Raises:
1008 ValueError: If input size cannot be inferred from inputs via
1009 static shape inference.
1010 """
1011 _check_rnn_cell_input_dtypes([inputs, state])
1012
1013 num_proj = self._num_units if self._num_proj is None else self._num_proj
1014 sigmoid = math_ops.sigmoid
1015
1016 if self._state_is_tuple:
1017 (c_prev, m_prev) = state
1018 else:
1019 c_prev = array_ops.slice(state, [0, 0], [-1, self._num_units])
1020 m_prev = array_ops.slice(state, [0, self._num_units], [-1, num_proj])
1021
1022 input_size = inputs.get_shape().with_rank(2).dims[1].value
1023 if input_size is None:
1024 raise ValueError("Could not infer input size from inputs.get_shape()[-1]")
1025
1026 # i = input_gate, j = new_input, f = forget_gate, o = output_gate
1027 lstm_matrix = math_ops.matmul(
1028 array_ops.concat([inputs, m_prev], 1), self._kernel)
1029 lstm_matrix = nn_ops.bias_add(lstm_matrix, self._bias)
1030
1031 i, j, f, o = array_ops.split(
1032 value=lstm_matrix, num_or_size_splits=4, axis=1)
1033 # Diagonal connections
1034 if self._use_peepholes:
1035 c = (
1036 sigmoid(f + self._forget_bias + self._w_f_diag * c_prev) * c_prev +
1037 sigmoid(i + self._w_i_diag * c_prev) * self._activation(j))
1038 else:
1039 c = (
1040 sigmoid(f + self._forget_bias) * c_prev +
1041 sigmoid(i) * self._activation(j))
1042
1043 if self._cell_clip is not None:
1044 # pylint: disable=invalid-unary-operand-type

Callers

nothing calls this directly

Calls 9

LSTMStateTupleClass · 0.85
sliceMethod · 0.80
with_rankMethod · 0.80
sigmoidFunction · 0.70
get_shapeMethod · 0.45
matmulMethod · 0.45
concatMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected