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