# tf.compat.v1.nn.rnn_cell.DropoutWrapper

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/layers/rnn/legacy_cell_wrappers.py#L186-L531) |

Operator adding dropout to inputs and outputs of the given cell.

Inherits From: [`RNNCell`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/nn/rnn_cell/RNNCell), [`Layer`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/layers/Layer), [`Layer`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/keras/layers/Layer), [`Module`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/Module)

    tf.compat.v1.nn.rnn_cell.DropoutWrapper(
        cell,
        input_keep_prob=1.0,
        output_keep_prob=1.0,
        state_keep_prob=1.0,
        variational_recurrent=False,
        input_size=None,
        dtype=None,
        seed=None,
        dropout_state_filter_visitor=None,
        **kwargs
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `cell` | an RNNCell, a projection to output_size is added to it. |
| `input_keep_prob` | unit Tensor or float between 0 and 1, input keep probability; if it is constant and 1, no input dropout will be added. |
| `output_keep_prob` | unit Tensor or float between 0 and 1, output keep probability; if it is constant and 1, no output dropout will be added. |
| `state_keep_prob` | unit Tensor or float between 0 and 1, output keep probability; if it is constant and 1, no output dropout will be added. State dropout is performed on the outgoing states of the cell. **Note** the state components to which dropout is applied when `state_keep_prob` is in `(0, 1)` are also determined by the argument `dropout_state_filter_visitor` (e.g. by default dropout is never applied to the `c` component of an `LSTMStateTuple`). |
| `variational_recurrent` | Python bool. If `True`, then the same dropout pattern is applied across all time steps per run call. If this parameter is set, `input_size` **must** be provided. |
| `input_size` | (optional) (possibly nested tuple of) `TensorShape` objects containing the depth(s) of the input tensors expected to be passed in to the `DropoutWrapper`. Required and used **iff** `variational_recurrent = True` and `input_keep_prob < 1`. |
| `dtype` | (optional) The `dtype` of the input, state, and output tensors. Required and used **iff** `variational_recurrent = True`. |
| `seed` | (optional) integer, the randomness seed. |
| `dropout_state_filter_visitor` | (optional), default: (see below). Function that takes any hierarchical level of the state and returns a scalar or depth=1 structure of Python booleans describing which terms in the state should be dropped out. In addition, if the function returns `True`, dropout is applied across this sublevel. If the function returns `False`, dropout is not applied across this entire sublevel. Default behavior: perform dropout on all terms except the memory (`c`) state of `LSTMCellState` objects, and don't try to apply dropout to `TensorArray` objects: <br /> def dropout_state_filter_visitor(s): # Never perform dropout on the c state. if isinstance(s, LSTMCellState): return LSTMCellState(c=False, h=True) elif isinstance(s, TensorArray): return False return True <br /> |
| `**kwargs` | dict of keyword arguments for base layer. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | if `cell` is not an `RNNCell`, or `keep_state_fn` is provided but not `callable`. |
| `ValueError` | if any of the keep_probs are not between 0 and 1. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `graph` | <br /> <br /> |
| `output_size` | Integer or TensorShape: size of outputs produced by this cell. |
| `scope_name` | <br /> <br /> |
| `state_size` | size(s) of state(s) used by this cell. <br /> It can be represented by an Integer, a TensorShape or a tuple of Integers or TensorShapes. |
| `wrapped_cell` | <br /> <br /> |

<br />

## Methods

### `apply`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/legacy_tf_layers/base.py#L239-L240)

    apply(
        *args, **kwargs
    )

### `get_initial_state`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/layers/rnn/legacy_cells.py#L254-L290)

    get_initial_state(
        inputs=None, batch_size=None, dtype=None
    )

### `get_losses_for`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/engine/base_layer_v1.py#L1467-L1484)

    get_losses_for(
        inputs
    )

Retrieves losses relevant to a specific set of inputs.

<br />

<br />

<br />

| Args ||
|---|---|
| `inputs` | Input tensor or list/tuple of input tensors. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| List of loss tensors of the layer that depend on `inputs`. ||

<br />

### `get_updates_for`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/engine/base_layer_v1.py#L1448-L1465)

    get_updates_for(
        inputs
    )

Retrieves updates relevant to a specific set of inputs.

<br />

<br />

<br />

| Args ||
|---|---|
| `inputs` | Input tensor or list/tuple of input tensors. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| List of update ops of the layer that depend on `inputs`. ||

<br />

### `zero_state`

[View source](https://github.com/keras-team/keras/tree/v2.13.1/keras/layers/rnn/legacy_cell_wrappers.py#L157-L159)

    zero_state(
        batch_size, dtype
    )

Return zero-filled state tensor(s).

<br />

<br />

<br />

| Args ||
|---|---|
| `batch_size` | int, float, or unit Tensor representing the batch size. |
| `dtype` | the data type to use for the state. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| If `state_size` is an int or TensorShape, then the return value is a `N-D` tensor of shape `[batch_size, state_size]` filled with zeros. <br /> If `state_size` is a nested list or tuple, then the return value is a nested list or tuple (of the same structure) of `2-D` tensors with the shapes `[batch_size, s]` for each s in `state_size`. ||

<br />