# tf.contrib.seq2seq.BasicDecoder

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/seq2seq/python/ops/basic_decoder.py#L44-L147) |

Basic sampling decoder.

Inherits From: [`Decoder`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/Decoder)

    tf.contrib.seq2seq.BasicDecoder(
        cell, helper, initial_state, output_layer=None
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `cell` | An `RNNCell` instance. |
| `helper` | A `Helper` instance. |
| `initial_state` | A (possibly nested tuple of...) tensors and TensorArrays. The initial state of the RNNCell. |
| `output_layer` | (Optional) An instance of [`tf.compat.v1.layers.Layer`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/Layer), i.e., [`tf.compat.v1.layers.Dense`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/Dense). Optional layer to apply to the RNN output prior to storing the result or sampling. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | if `cell`, `helper` or `output_layer` have an incorrect type. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `batch_size` | The batch size of input values. |
| `output_dtype` | A (possibly nested tuple of...) dtype\[s\]. |
| `output_size` | A (possibly nested tuple of...) integer\[s\] or `TensorShape` object\[s\]. |
| `tracks_own_finished` | Describes whether the Decoder keeps track of finished states. <br /> Most decoders will emit a true/false `finished` value independently at each time step. In this case, the `dynamic_decode` function keeps track of which batch entries are already finished, and performs a logical OR to insert new batches to the finished set. Some decoders, however, shuffle batches / beams between time steps and `dynamic_decode` will mix up the finished state across these entries because it does not track the reshuffle across time steps. In this case, it is up to the decoder to declare that it will keep track of its own finished state by setting this property to `True`. |

<br />

## Methods

### `finalize`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/seq2seq/python/ops/decoder.py#L115-L130)

    finalize(
        outputs, final_state, sequence_lengths
    )

Called after decoding iterations complete.

<br />

<br />

<br />

| Args ||
|---|---|
| `outputs` | RNNCell outputs (possibly nested tuple of) tensor\[s\] for all time steps. |
| `final_state` | RNNCell final state (possibly nested tuple of) tensor\[s\] for last time step. |
| `sequence_lengths` | 1-D `int32` tensor containing lengths of each sequence. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `(final_outputs, final_state)`: `final_outputs` is an object containing the final decoder output, `final_state` is a (structure of) state tensors and TensorArrays. ||

<br />

### `initialize`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/seq2seq/python/ops/basic_decoder.py#L112-L121)

    initialize(
        name=None
    )

Initialize the decoder.

<br />

<br />

<br />

| Args ||
|---|---|
| `name` | Name scope for any created operations. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `(finished, first_inputs, initial_state)`. ||

<br />

### `step`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/seq2seq/python/ops/basic_decoder.py#L123-L147)

    step(
        time, inputs, state, name=None
    )

Perform a decoding step.

<br />

<br />

<br />

| Args ||
|---|---|
| `time` | scalar `int32` tensor. |
| `inputs` | A (structure of) input tensors. |
| `state` | A (structure of) state tensors and TensorArrays. |
| `name` | Name scope for any created operations. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `(outputs, next_state, next_inputs, finished)`. ||

<br />