Creates a bidirectional recurrent neural network. Similar to the unidirectional case above (rnn) but takes input and builds independent forward and backward RNNs with the final forward and backward outputs depth-concatenated, such that the output will have the format [time][batch][cell_fw.o
(cell_fw,
cell_bw,
inputs,
initial_state_fw=None,
initial_state_bw=None,
dtype=None,
sequence_length=None,
scope=None)
| 1543 | "equivalent to this API") |
| 1544 | @tf_export(v1=["nn.static_bidirectional_rnn"]) |
| 1545 | def static_bidirectional_rnn(cell_fw, |
| 1546 | cell_bw, |
| 1547 | inputs, |
| 1548 | initial_state_fw=None, |
| 1549 | initial_state_bw=None, |
| 1550 | dtype=None, |
| 1551 | sequence_length=None, |
| 1552 | scope=None): |
| 1553 | """Creates a bidirectional recurrent neural network. |
| 1554 | |
| 1555 | Similar to the unidirectional case above (rnn) but takes input and builds |
| 1556 | independent forward and backward RNNs with the final forward and backward |
| 1557 | outputs depth-concatenated, such that the output will have the format |
| 1558 | [time][batch][cell_fw.output_size + cell_bw.output_size]. The input_size of |
| 1559 | forward and backward cell must match. The initial state for both directions |
| 1560 | is zero by default (but can be set optionally) and no intermediate states are |
| 1561 | ever returned -- the network is fully unrolled for the given (passed in) |
| 1562 | length(s) of the sequence(s) or completely unrolled if length(s) is not given. |
| 1563 | |
| 1564 | Args: |
| 1565 | cell_fw: An instance of RNNCell, to be used for forward direction. |
| 1566 | cell_bw: An instance of RNNCell, to be used for backward direction. |
| 1567 | inputs: A length T list of inputs, each a tensor of shape [batch_size, |
| 1568 | input_size], or a nested tuple of such elements. |
| 1569 | initial_state_fw: (optional) An initial state for the forward RNN. This must |
| 1570 | be a tensor of appropriate type and shape `[batch_size, |
| 1571 | cell_fw.state_size]`. If `cell_fw.state_size` is a tuple, this should be a |
| 1572 | tuple of tensors having shapes `[batch_size, s] for s in |
| 1573 | cell_fw.state_size`. |
| 1574 | initial_state_bw: (optional) Same as for `initial_state_fw`, but using the |
| 1575 | corresponding properties of `cell_bw`. |
| 1576 | dtype: (optional) The data type for the initial state. Required if either |
| 1577 | of the initial states are not provided. |
| 1578 | sequence_length: (optional) An int32/int64 vector, size `[batch_size]`, |
| 1579 | containing the actual lengths for each of the sequences. |
| 1580 | scope: VariableScope for the created subgraph; defaults to |
| 1581 | "bidirectional_rnn" |
| 1582 | |
| 1583 | Returns: |
| 1584 | A tuple (outputs, output_state_fw, output_state_bw) where: |
| 1585 | outputs is a length `T` list of outputs (one for each input), which |
| 1586 | are depth-concatenated forward and backward outputs. |
| 1587 | output_state_fw is the final state of the forward rnn. |
| 1588 | output_state_bw is the final state of the backward rnn. |
| 1589 | |
| 1590 | Raises: |
| 1591 | TypeError: If `cell_fw` or `cell_bw` is not an instance of `RNNCell`. |
| 1592 | ValueError: If inputs is None or an empty list. |
| 1593 | """ |
| 1594 | rnn_cell_impl.assert_like_rnncell("cell_fw", cell_fw) |
| 1595 | rnn_cell_impl.assert_like_rnncell("cell_bw", cell_bw) |
| 1596 | if not nest.is_sequence(inputs): |
| 1597 | raise TypeError("inputs must be a sequence") |
| 1598 | if not inputs: |
| 1599 | raise ValueError("inputs must not be empty") |
| 1600 | |
| 1601 | with vs.variable_scope(scope or "bidirectional_rnn"): |
| 1602 | # Forward direction |
nothing calls this directly
no test coverage detected