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

Method call

tensorflow/contrib/rnn/python/ops/rnn_cell.py:3006–3080  ·  view source on GitHub ↗

Run one step of LSTM. Args: inputs: input Tensor, 2D, batch x num_units. state: A tuple of state Tensors, both `2-D`, with column sizes `c_state` and `m_state`. Returns: A tuple containing: - A `2-D, [batch x output_dim]`, Tensor representing the output of t

(self, inputs, state)

Source from the content-addressed store, hash-verified

3004 return nn_ops.bias_add(res, biases)
3005
3006 def call(self, inputs, state):
3007 """Run one step of LSTM.
3008
3009 Args:
3010 inputs: input Tensor, 2D, batch x num_units.
3011 state: A tuple of state Tensors, both `2-D`, with column sizes
3012 `c_state` and `m_state`.
3013
3014 Returns:
3015 A tuple containing:
3016
3017 - A `2-D, [batch x output_dim]`, Tensor representing the output of the
3018 LSTM after reading `inputs` when previous state was `state`.
3019 Here output_dim is:
3020 num_proj if num_proj was set,
3021 num_units otherwise.
3022 - Tensor(s) representing the new state of LSTM after reading `inputs` when
3023 the previous state was `state`. Same type and shape(s) as `state`.
3024
3025 Raises:
3026 ValueError: If input size cannot be inferred from inputs via
3027 static shape inference.
3028 """
3029 dtype = inputs.dtype
3030 num_units = self._num_units
3031 sigmoid = math_ops.sigmoid
3032 c, h = state
3033
3034 input_size = inputs.get_shape().with_rank(2).dims[1]
3035 if input_size.value is None:
3036 raise ValueError("Could not infer input size from inputs.get_shape()[-1]")
3037
3038 with vs.variable_scope(self._scope, initializer=self._initializer):
3039
3040 concat = self._linear(
3041 [inputs, h], 4 * num_units, norm=self._norm, bias=True)
3042
3043 # i = input_gate, j = new_input, f = forget_gate, o = output_gate
3044 i, j, f, o = array_ops.split(value=concat, num_or_size_splits=4, axis=1)
3045
3046 if self._use_peepholes:
3047 w_f_diag = vs.get_variable("w_f_diag", shape=[num_units], dtype=dtype)
3048 w_i_diag = vs.get_variable("w_i_diag", shape=[num_units], dtype=dtype)
3049 w_o_diag = vs.get_variable("w_o_diag", shape=[num_units], dtype=dtype)
3050
3051 new_c = (
3052 c * sigmoid(f + self._forget_bias + w_f_diag * c) +
3053 sigmoid(i + w_i_diag * c) * self._activation(j))
3054 else:
3055 new_c = (
3056 c * sigmoid(f + self._forget_bias) +
3057 sigmoid(i) * self._activation(j))
3058
3059 if self._cell_clip is not None:
3060 # pylint: disable=invalid-unary-operand-type
3061 new_c = clip_ops.clip_by_value(new_c, -self._cell_clip, self._cell_clip)
3062 # pylint: enable=invalid-unary-operand-type
3063 if self._use_peepholes:

Callers

nothing calls this directly

Calls 7

_linearMethod · 0.95
with_rankMethod · 0.80
variable_scopeMethod · 0.80
sigmoidClass · 0.50
get_shapeMethod · 0.45
splitMethod · 0.45
get_variableMethod · 0.45

Tested by

no test coverage detected