MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / dynamic_rnn

Function dynamic_rnn

DIEN/rnn.py:437–621  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 4

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls 4

_transpose_batch_timeFunction · 0.85
_assert_has_shapeFunction · 0.85
_dynamic_rnn_loopFunction · 0.85

Tested by

no test coverage detected