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

Method call

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

Run one step of LSTM. Args: inputs: input Tensor, 2D, batch x num_units. state: state Tensor, 2D, batch x state_size. Returns: A tuple containing: - A 2D, batch x output_dim, Tensor representing the output of the LSTM after reading "inputs" when previous sta

(self, inputs, state)

Source from the content-addressed store, hash-verified

387 return self._state_size
388
389 def call(self, inputs, state):
390 """Run one step of LSTM.
391
392 Args:
393 inputs: input Tensor, 2D, batch x num_units.
394 state: state Tensor, 2D, batch x state_size.
395
396 Returns:
397 A tuple containing:
398 - A 2D, batch x output_dim, Tensor representing the output of the LSTM
399 after reading "inputs" when previous state was "state".
400 Here output_dim is num_units.
401 - A 2D, batch x state_size, Tensor representing the new state of LSTM
402 after reading "inputs" when previous state was "state".
403 Raises:
404 ValueError: if an input_size was specified and the provided inputs have
405 a different dimension.
406 """
407 sigmoid = math_ops.sigmoid
408 tanh = math_ops.tanh
409
410 freq_inputs = self._make_tf_features(inputs)
411 dtype = inputs.dtype
412 actual_input_size = freq_inputs[0].get_shape().as_list()[1]
413
414 concat_w = _get_concat_variable(
415 "W", [actual_input_size + 2 * self._num_units, 4 * self._num_units],
416 dtype, self._num_unit_shards)
417
418 b = vs.get_variable(
419 "B",
420 shape=[4 * self._num_units],
421 initializer=init_ops.zeros_initializer(),
422 dtype=dtype)
423
424 # Diagonal connections
425 if self._use_peepholes:
426 w_f_diag = vs.get_variable(
427 "W_F_diag", shape=[self._num_units], dtype=dtype)
428 w_i_diag = vs.get_variable(
429 "W_I_diag", shape=[self._num_units], dtype=dtype)
430 w_o_diag = vs.get_variable(
431 "W_O_diag", shape=[self._num_units], dtype=dtype)
432
433 # initialize the first freq state to be zero
434 m_prev_freq = array_ops.zeros(
435 [inputs.shape.dims[0].value or inputs.get_shape()[0], self._num_units],
436 dtype)
437 for fq in range(len(freq_inputs)):
438 c_prev = array_ops.slice(state, [0, 2 * fq * self._num_units],
439 [-1, self._num_units])
440 m_prev = array_ops.slice(state, [0, (2 * fq + 1) * self._num_units],
441 [-1, self._num_units])
442 # i = input_gate, j = new_input, f = forget_gate, o = output_gate
443 cell_inputs = array_ops.concat([freq_inputs[fq], m_prev, m_prev_freq], 1)
444 lstm_matrix = nn_ops.bias_add(math_ops.matmul(cell_inputs, concat_w), b)
445 i, j, f, o = array_ops.split(
446 value=lstm_matrix, num_or_size_splits=4, axis=1)

Callers

nothing calls this directly

Calls 12

_make_tf_featuresMethod · 0.95
_get_concat_variableFunction · 0.85
sliceMethod · 0.80
rangeFunction · 0.50
sigmoidClass · 0.50
tanhClass · 0.50
as_listMethod · 0.45
get_shapeMethod · 0.45
get_variableMethod · 0.45
concatMethod · 0.45
matmulMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected