# tf.keras.layers.Bidirectional

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Bidirectional) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/layers/wrappers.py#L339-L742) |

Bidirectional wrapper for RNNs.

Inherits From: [`Wrapper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/layers/Wrapper)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.layers.Bidirectional`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Bidirectional), \`tf.compat.v2.keras.layers.Bidirectional\`

<br />

    tf.keras.layers.Bidirectional(
        layer, merge_mode='concat', weights=None, backward_layer=None, **kwargs
    )

<br />

<br />

<br />

| ## Arguments ||
|---|---|
| `layer` | `Recurrent` instance. |
| `merge_mode` | Mode by which outputs of the forward and backward RNNs will be combined. One of {'sum', 'mul', 'concat', 'ave', None}. If None, the outputs will not be combined, they will be returned as a list. |
| `backward_layer` | Optional `Recurrent` instance to be used to handle backwards input processing. If `backward_layer` is not provided, the layer instance passed as the `layer` argument will be used to generate the backward layer automatically. Note that the provided `backward_layer` layer should have properties matching those of the `layer` argument, in particular it should have the same values for `stateful`, `return_states`, `return_sequence`, etc. In addition, `backward_layer` and `layer` should have different `go_backwards` argument values. A `ValueError` will be raised if these requirements are not met. |

<br />

#### Call arguments:

The call arguments for this layer are the same as those of the wrapped RNN
layer.

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | <br /> 1. If `layer` or `backward_layer` is not a `Layer` instance. 2. In case of invalid `merge_mode` argument. 3. If `backward_layer` has mismatched properties compared to `layer`. |

#### Examples:

    model = Sequential()
    model.add(Bidirectional(LSTM(10, return_sequences=True), input_shape=(5, 10)))
    model.add(Bidirectional(LSTM(10)))
    model.add(Dense(5))
    model.add(Activation('softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='rmsprop')

     # With custom backward layer
     model = Sequential()
     forward_layer = LSTM(10, return_sequences=True)
     backard_layer = LSTM(10, activation='relu', return_sequences=True,
                          go_backwards=True)
     model.add(Bidirectional(forward_layer, backward_layer=backward_layer,
                             input_shape=(5, 10)))
     model.add(Dense(5))
     model.add(Activation('softmax'))
     model.compile(loss='categorical_crossentropy', optimizer='rmsprop')

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `constraints` | <br /> <br /> |

<br />

## Methods

### `reset_states`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/layers/wrappers.py#L676-L678)

    reset_states()