Creates a recurrent neural network specified by RNNCell `cell`. Performs fully dynamic unrolling of `inputs`. Example: ```python # create a BasicRNNCell rnn_cell = tf.nn.rnn_cell.BasicRNNCell(hidden_size) # 'outputs' is a tensor of shape [batch_size, max_time, cell_state_size] # d
(cell, inputs, att_scores=None, sequence_length=None, initial_state=None,
dtype=None, parallel_iterations=None, swap_memory=False,
time_major=False, scope=None)
| 438 | |
| 439 | |
| 440 | def dynamic_rnn(cell, inputs, att_scores=None, sequence_length=None, initial_state=None, |
| 441 | dtype=None, parallel_iterations=None, swap_memory=False, |
| 442 | time_major=False, scope=None): |
| 443 | """Creates a recurrent neural network specified by RNNCell `cell`. |
| 444 | |
| 445 | Performs fully dynamic unrolling of `inputs`. |
| 446 | |
| 447 | Example: |
| 448 | |
| 449 | ```python |
| 450 | # create a BasicRNNCell |
| 451 | rnn_cell = tf.nn.rnn_cell.BasicRNNCell(hidden_size) |
| 452 | |
| 453 | # 'outputs' is a tensor of shape [batch_size, max_time, cell_state_size] |
| 454 | |
| 455 | # defining initial state |
| 456 | initial_state = rnn_cell.zero_state(batch_size, dtype=tf.float32) |
| 457 | |
| 458 | # 'state' is a tensor of shape [batch_size, cell_state_size] |
| 459 | outputs, state = tf.nn.dynamic_rnn(rnn_cell, input_data, |
| 460 | initial_state=initial_state, |
| 461 | dtype=tf.float32) |
| 462 | ``` |
| 463 | |
| 464 | ```python |
| 465 | # create 2 LSTMCells |
| 466 | rnn_layers = [tf.nn.rnn_cell.LSTMCell(size) for size in [128, 256]] |
| 467 | |
| 468 | # create a RNN cell composed sequentially of a number of RNNCells |
| 469 | multi_rnn_cell = tf.nn.rnn_cell.MultiRNNCell(rnn_layers) |
| 470 | |
| 471 | # 'outputs' is a tensor of shape [batch_size, max_time, 256] |
| 472 | # 'state' is a N-tuple where N is the number of LSTMCells containing a |
| 473 | # tf.contrib.rnn.LSTMStateTuple for each cell |
| 474 | outputs, state = tf.nn.dynamic_rnn(cell=multi_rnn_cell, |
| 475 | inputs=data, |
| 476 | dtype=tf.float32) |
| 477 | ``` |
| 478 | |
| 479 | |
| 480 | Args: |
| 481 | cell: An instance of RNNCell. |
| 482 | inputs: The RNN inputs. |
| 483 | If `time_major == False` (default), this must be a `Tensor` of shape: |
| 484 | `[batch_size, max_time, ...]`, or a nested tuple of such |
| 485 | elements. |
| 486 | If `time_major == True`, this must be a `Tensor` of shape: |
| 487 | `[max_time, batch_size, ...]`, or a nested tuple of such |
| 488 | elements. |
| 489 | This may also be a (possibly nested) tuple of Tensors satisfying |
| 490 | this property. The first two dimensions must match across all the inputs, |
| 491 | but otherwise the ranks and other shape components may differ. |
| 492 | In this case, input to `cell` at each time-step will replicate the |
| 493 | structure of these tuples, except for the time dimension (from which the |
| 494 | time is taken). |
| 495 | The input to `cell` at each time step will be a `Tensor` or (possibly |
| 496 | nested) tuple of Tensors each with dimensions `[batch_size, ...]`. |
| 497 | sequence_length: (optional) An int32/int64 vector sized `[batch_size]`. |
no test coverage detected