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

Function static_rnn

DIEN/rnn.py:1104–1268  ·  view source on GitHub ↗

Creates a recurrent neural network specified by RNNCell `cell`. The simplest form of RNN network generated is: ```python state = cell.zero_state(...) outputs = [] for input_ in inputs: output, state = cell(input_, state) outputs.append(output) return (outputs, state

(cell,
               inputs,
               initial_state=None,
               dtype=None,
               sequence_length=None,
               scope=None)

Source from the content-addressed store, hash-verified

1102
1103
1104def static_rnn(cell,
1105 inputs,
1106 initial_state=None,
1107 dtype=None,
1108 sequence_length=None,
1109 scope=None):
1110 """Creates a recurrent neural network specified by RNNCell `cell`.
1111
1112 The simplest form of RNN network generated is:
1113
1114 ```python
1115 state = cell.zero_state(...)
1116 outputs = []
1117 for input_ in inputs:
1118 output, state = cell(input_, state)
1119 outputs.append(output)
1120 return (outputs, state)
1121 ```
1122 However, a few other options are available:
1123
1124 An initial state can be provided.
1125 If the sequence_length vector is provided, dynamic calculation is performed.
1126 This method of calculation does not compute the RNN steps past the maximum
1127 sequence length of the minibatch (thus saving computational time),
1128 and properly propagates the state at an example's sequence length
1129 to the final state output.
1130
1131 The dynamic calculation performed is, at time `t` for batch row `b`,
1132
1133 ```python
1134 (output, state)(b, t) =
1135 (t >= sequence_length(b))
1136 ? (zeros(cell.output_size), states(b, sequence_length(b) - 1))
1137 : cell(input(b, t), state(b, t - 1))
1138 ```
1139
1140 Args:
1141 cell: An instance of RNNCell.
1142 inputs: A length T list of inputs, each a `Tensor` of shape
1143 `[batch_size, input_size]`, or a nested tuple of such elements.
1144 initial_state: (optional) An initial state for the RNN.
1145 If `cell.state_size` is an integer, this must be
1146 a `Tensor` of appropriate type and shape `[batch_size, cell.state_size]`.
1147 If `cell.state_size` is a tuple, this should be a tuple of
1148 tensors having shapes `[batch_size, s] for s in cell.state_size`.
1149 dtype: (optional) The data type for the initial state and expected output.
1150 Required if initial_state is not provided or RNN state has a heterogeneous
1151 dtype.
1152 sequence_length: Specifies the length of each sequence in inputs.
1153 An int32 or int64 vector (tensor) size `[batch_size]`, values in `[0, T)`.
1154 scope: VariableScope for the created subgraph; defaults to "rnn".
1155
1156 Returns:
1157 A pair (outputs, state) where:
1158
1159 - outputs is a length T list of outputs (one for each input), or a nested
1160 tuple of such elements.
1161 - state is the final state

Callers 2

static_state_saving_rnnFunction · 0.85
static_bidirectional_rnnFunction · 0.85

Calls 2

_create_zero_outputFunction · 0.85
_rnn_stepFunction · 0.85

Tested by

no test coverage detected