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=False,
scope=None)
| 519 | "Please use `keras.layers.RNN(cell)`, which is equivalent to this API") |
| 520 | @tf_export(v1=["nn.dynamic_rnn"]) |
| 521 | def dynamic_rnn(cell, |
| 522 | inputs, |
| 523 | sequence_length=None, |
| 524 | initial_state=None, |
| 525 | dtype=None, |
| 526 | parallel_iterations=None, |
| 527 | swap_memory=False, |
| 528 | time_major=False, |
| 529 | scope=None): |
| 530 | """Creates a recurrent neural network specified by RNNCell `cell`. |
| 531 | |
| 532 | Performs fully dynamic unrolling of `inputs`. |
| 533 | |
| 534 | Example: |
| 535 | |
| 536 | ```python |
| 537 | # create a BasicRNNCell |
| 538 | rnn_cell = tf.compat.v1.nn.rnn_cell.BasicRNNCell(hidden_size) |
| 539 | |
| 540 | # 'outputs' is a tensor of shape [batch_size, max_time, cell_state_size] |
| 541 | |
| 542 | # defining initial state |
| 543 | initial_state = rnn_cell.zero_state(batch_size, dtype=tf.float32) |
| 544 | |
| 545 | # 'state' is a tensor of shape [batch_size, cell_state_size] |
| 546 | outputs, state = tf.compat.v1.nn.dynamic_rnn(rnn_cell, input_data, |
| 547 | initial_state=initial_state, |
| 548 | dtype=tf.float32) |
| 549 | ``` |
| 550 | |
| 551 | ```python |
| 552 | # create 2 LSTMCells |
| 553 | rnn_layers = [tf.compat.v1.nn.rnn_cell.LSTMCell(size) for size in [128, 256]] |
| 554 | |
| 555 | # create a RNN cell composed sequentially of a number of RNNCells |
| 556 | multi_rnn_cell = tf.compat.v1.nn.rnn_cell.MultiRNNCell(rnn_layers) |
| 557 | |
| 558 | # 'outputs' is a tensor of shape [batch_size, max_time, 256] |
| 559 | # 'state' is a N-tuple where N is the number of LSTMCells containing a |
| 560 | # tf.nn.rnn_cell.LSTMStateTuple for each cell |
| 561 | outputs, state = tf.compat.v1.nn.dynamic_rnn(cell=multi_rnn_cell, |
| 562 | inputs=data, |
| 563 | dtype=tf.float32) |
| 564 | ``` |
| 565 | |
| 566 | |
| 567 | Args: |
| 568 | cell: An instance of RNNCell. |
| 569 | inputs: The RNN inputs. |
| 570 | If `time_major == False` (default), this must be a `Tensor` of shape: |
| 571 | `[batch_size, max_time, ...]`, or a nested tuple of such elements. |
| 572 | If `time_major == True`, this must be a `Tensor` of shape: `[max_time, |
| 573 | batch_size, ...]`, or a nested tuple of such elements. This may also be |
| 574 | a (possibly nested) tuple of Tensors satisfying this property. The |
| 575 | first two dimensions must match across all the inputs, but otherwise the |
| 576 | ranks and other shape components may differ. In this case, input to |
| 577 | `cell` at each time-step will replicate the structure of these tuples, |
| 578 | except for the time dimension (from which the time is taken). The input |
no test coverage detected