Creates a recurrent neural network specified by RNNCell `cell`. Performs fully dynamic unrolling of `inputs`. Example: ```python # create a BasicRNNCell rnn_cell = tf.compat.v1.nn.rnn_cell.BasicRNNCell(hidden_size) # 'outputs' is a tensor of shape [batch_size, max_time, cell_state_si
(cell,
inputs,
sequence_length=None,
initial_state=None,
dtype=None,
parallel_iterations=None,
swap_memory=False,
time_major=True,
scope=None)
| 40 | |
| 41 | @tf_export(v1=["lite.experimental.nn.dynamic_rnn"]) |
| 42 | def dynamic_rnn(cell, |
| 43 | inputs, |
| 44 | sequence_length=None, |
| 45 | initial_state=None, |
| 46 | dtype=None, |
| 47 | parallel_iterations=None, |
| 48 | swap_memory=False, |
| 49 | time_major=True, |
| 50 | scope=None): |
| 51 | """Creates a recurrent neural network specified by RNNCell `cell`. |
| 52 | |
| 53 | Performs fully dynamic unrolling of `inputs`. |
| 54 | |
| 55 | Example: |
| 56 | |
| 57 | ```python |
| 58 | # create a BasicRNNCell |
| 59 | rnn_cell = tf.compat.v1.nn.rnn_cell.BasicRNNCell(hidden_size) |
| 60 | |
| 61 | # 'outputs' is a tensor of shape [batch_size, max_time, cell_state_size] |
| 62 | |
| 63 | # defining initial state |
| 64 | initial_state = rnn_cell.zero_state(batch_size, dtype=tf.float32) |
| 65 | |
| 66 | # 'state' is a tensor of shape [batch_size, cell_state_size] |
| 67 | outputs, state = tf.compat.v1.nn.dynamic_rnn(rnn_cell, input_data, |
| 68 | initial_state=initial_state, |
| 69 | dtype=tf.float32) |
| 70 | ``` |
| 71 | |
| 72 | ```python |
| 73 | # create 2 LSTMCells |
| 74 | rnn_layers = [tf.compat.v1.nn.rnn_cell.LSTMCell(size) for size in [128, 256]] |
| 75 | |
| 76 | # create a RNN cell composed sequentially of a number of RNNCells |
| 77 | multi_rnn_cell = tf.compat.v1.nn.rnn_cell.MultiRNNCell(rnn_layers) |
| 78 | |
| 79 | # 'outputs' is a tensor of shape [batch_size, max_time, 256] |
| 80 | # 'state' is a N-tuple where N is the number of LSTMCells containing a |
| 81 | # tf.nn.rnn_cell.LSTMStateTuple for each cell |
| 82 | outputs, state = tf.compat.v1.nn.dynamic_rnn(cell=multi_rnn_cell, |
| 83 | inputs=data, |
| 84 | dtype=tf.float32) |
| 85 | ``` |
| 86 | |
| 87 | |
| 88 | Args: |
| 89 | cell: An instance of RNNCell. |
| 90 | inputs: The RNN inputs. |
| 91 | If `time_major == False` (default), this must be a `Tensor` of shape: |
| 92 | `[batch_size, max_time, ...]`, or a nested tuple of such elements. |
| 93 | If `time_major == True`, this must be a `Tensor` of shape: `[max_time, |
| 94 | batch_size, ...]`, or a nested tuple of such elements. This may also be |
| 95 | a (possibly nested) tuple of Tensors satisfying this property. The |
| 96 | first two dimensions must match across all the inputs, but otherwise the |
| 97 | ranks and other shape components may differ. In this case, input to |
| 98 | `cell` at each time-step will replicate the structure of these tuples, |
| 99 | except for the time dimension (from which the time is taken). The input |
no test coverage detected