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

Function _dynamic_rnn_loop

tensorflow/python/ops/rnn.py:719–936  ·  view source on GitHub ↗

Internal implementation of Dynamic RNN. Args: cell: An instance of RNNCell. inputs: A `Tensor` of shape [time, batch_size, input_size], or a nested tuple of such elements. initial_state: A `Tensor` of shape `[batch_size, state_size]`, or if `cell.state_size` is a tuple, th

(cell,
                      inputs,
                      initial_state,
                      parallel_iterations,
                      swap_memory,
                      sequence_length=None,
                      dtype=None)

Source from the content-addressed store, hash-verified

717
718
719def _dynamic_rnn_loop(cell,
720 inputs,
721 initial_state,
722 parallel_iterations,
723 swap_memory,
724 sequence_length=None,
725 dtype=None):
726 """Internal implementation of Dynamic RNN.
727
728 Args:
729 cell: An instance of RNNCell.
730 inputs: A `Tensor` of shape [time, batch_size, input_size], or a nested
731 tuple of such elements.
732 initial_state: A `Tensor` of shape `[batch_size, state_size]`, or if
733 `cell.state_size` is a tuple, then this should be a tuple of tensors
734 having shapes `[batch_size, s] for s in cell.state_size`.
735 parallel_iterations: Positive Python int.
736 swap_memory: A Python boolean
737 sequence_length: (optional) An `int32` `Tensor` of shape [batch_size].
738 dtype: (optional) Expected dtype of output. If not specified, inferred from
739 initial_state.
740
741 Returns:
742 Tuple `(final_outputs, final_state)`.
743 final_outputs:
744 A `Tensor` of shape `[time, batch_size, cell.output_size]`. If
745 `cell.output_size` is a (possibly nested) tuple of ints or `TensorShape`
746 objects, then this returns a (possibly nested) tuple of Tensors matching
747 the corresponding shapes.
748 final_state:
749 A `Tensor`, or possibly nested tuple of Tensors, matching in length
750 and shapes to `initial_state`.
751
752 Raises:
753 ValueError: If the input depth cannot be inferred via shape inference
754 from the inputs.
755 ValueError: If time_step is not the same for all the elements in the
756 inputs.
757 ValueError: If batch_size is not the same for all the elements in the
758 inputs.
759 """
760 state = initial_state
761 assert isinstance(parallel_iterations, int), "parallel_iterations must be int"
762
763 state_size = cell.state_size
764
765 flat_input = nest.flatten(inputs)
766 flat_output_size = nest.flatten(cell.output_size)
767
768 # Construct an initial output
769 input_shape = array_ops.shape(flat_input[0])
770 time_steps = input_shape[0]
771 batch_size = _best_effort_input_batch_size(flat_input)
772
773 inputs_got_shape = tuple(
774 input_.get_shape().with_rank_at_least(3) for input_ in flat_input)
775
776 const_time_steps, const_batch_size = inputs_got_shape[0].as_list()[:2]

Callers 2

dynamic_rnnFunction · 0.90
dynamic_rnnFunction · 0.70

Calls 15

tupleFunction · 0.85
_concatFunction · 0.85
with_rank_at_leastMethod · 0.80
is_fully_definedMethod · 0.80
executing_eagerlyMethod · 0.80
minimumMethod · 0.80
maximumMethod · 0.80
_create_zero_arraysFunction · 0.70
_create_taFunction · 0.70
_infer_state_dtypeFunction · 0.70

Tested by

no test coverage detected