# Module: tf.contrib.seq2seq

<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/__init__.py) |

Ops for building neural network seq2seq decoders and losses.

See the
[Contrib Seq2seq](https://tensorflow.org/api_guides/python/contrib.seq2seq)
guide.

## Classes

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

[`class AttentionWrapper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/AttentionWrapper): Wraps another `RNNCell` with attention.

[`class AttentionWrapperState`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/AttentionWrapperState): `namedtuple` storing the state of a `AttentionWrapper`.

[`class BahdanauAttention`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/BahdanauAttention): Implements Bahdanau-style (additive) attention.

[`class BahdanauMonotonicAttention`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/BahdanauMonotonicAttention): Monotonic attention mechanism with Bahadanau-style energy function.

[`class BasicDecoder`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/BasicDecoder): Basic sampling decoder.

[`class BasicDecoderOutput`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/BasicDecoderOutput): BasicDecoderOutput(rnn_output, sample_id)

[`class BeamSearchDecoder`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/BeamSearchDecoder): BeamSearch sampling decoder.

[`class BeamSearchDecoderOutput`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/BeamSearchDecoderOutput): BeamSearchDecoderOutput(scores, predicted_ids, parent_ids)

[`class BeamSearchDecoderState`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/BeamSearchDecoderState): BeamSearchDecoderState(cell_state, log_probs, finished, lengths, accumulated_attention_probs)

[`class CustomHelper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/CustomHelper): Base abstract class that allows the user to customize sampling.

[`class Decoder`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/Decoder): An RNN Decoder abstract interface object.

[`class FinalBeamSearchDecoderOutput`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/FinalBeamSearchDecoderOutput): Final outputs returned by the beam search after all decoding is finished.

[`class GreedyEmbeddingHelper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/GreedyEmbeddingHelper): A helper for use during inference.

[`class Helper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/Helper): Interface for implementing sampling in seq2seq decoders.

[`class InferenceHelper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/InferenceHelper): A helper to use during inference with a custom sampling function.

[`class LuongAttention`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/LuongAttention): Implements Luong-style (multiplicative) attention scoring.

[`class LuongMonotonicAttention`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/LuongMonotonicAttention): Monotonic attention mechanism with Luong-style energy function.

[`class SampleEmbeddingHelper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/SampleEmbeddingHelper): A helper for use during inference.

[`class ScheduledEmbeddingTrainingHelper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/ScheduledEmbeddingTrainingHelper): A training helper that adds scheduled sampling.

[`class ScheduledOutputTrainingHelper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/ScheduledOutputTrainingHelper): A training helper that adds scheduled sampling directly to outputs.

[`class TrainingHelper`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/TrainingHelper): A helper for use during training. Only reads inputs.

## Functions

[`dynamic_decode(...)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/dynamic_decode): Perform dynamic decoding with `decoder`.

[`gather_tree(...)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/gather_tree): Calculates the full beams from the per-step ids and parent beam ids.

[`hardmax(...)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/hardmax): Returns batched one-hot vectors.

[`monotonic_attention(...)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/monotonic_attention): Compute monotonic attention distribution from choosing probabilities.

[`safe_cumprod(...)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/safe_cumprod): Computes cumprod of x in logspace using cumsum to avoid underflow.

[`sequence_loss(...)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/sequence_loss): Weighted cross-entropy loss for a sequence of logits.

[`tile_batch(...)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/seq2seq/tile_batch): Tile the batch dimension of a (possibly nested structure of) tensor(s) t.