Art of DS

Appearance

Palette
Theme
Unlock $20 one time
Sign in, or create an account

Sign in to Art of DSCreate your Art of DS account

We email you a link and a six-digit code. Either one signs you in; there is no password.Enter your email. We send a link and a six-digit code to confirm it — no password to remember. The account is free.

  • You come back to this page, right where you were.
  • Already have an account? The same email simply signs you in.

By continuing you accept the Terms and the Privacy policy.

Your account

Free accountLifetime access

difficulty 3/5

Sequence-to-sequence

Definition

An encoder reads a variable-length input and a decoder writes a variable-length output. Squeezing that into one fixed vector is the bottleneck attention was invented to remove.

Formula
ci=∑j=1Txαijhj,αij=exp⁡(eij)∑kexp⁡(eik)c_i = \sum_{j=1}^{T_x} \alpha_{ij} h_j, \quad \alpha_{ij} = \frac{\exp(e_{ij})}{\sum_k \exp(e_{ik})}

Intuition

Translation, summarisation and speech transcription share a shape that classification does not have: the input and the output are both sequences, they are different lengths, and no token of one lines up with a token of the other. d2l calls these problems ones "where inputs and outputs each consist of variable-length unaligned sequences", and says the response is an encoder-decoder architecture [2, §10.7].

Split the work. One network reads the input and produces a representation; a second network writes the output from it, one token at a time. The second half is already familiar — "if we ignore the encoder, the decoder in a sequence-to-sequence architecture behaves just like a normal language model" [2, §10.7].

Everything interesting is in what passes between them. The original answer was one fixed-length vector, and Bahdanau et al. open by naming that as the problem: "we conjecture that the use of a fixed-length vector is a bottleneck in improving the performance of this basic encoder-decoder architecture" [1, Abstract].

Formal definition

How it works

Where it's used

Why & when

Worked example

Pitfalls

Check yourself

3 questions

The questions on this page come with access. They are graded on the server, so the answers stay there until you have given yours.

Unlock all quizzes

On the cheat sheet: NLP tasks →

Sources

  1. Bahdanau, Cho, Bengio. Neural Machine Translation by Jointly Learning to Align and Translate (2015)paperhttps://ar5iv.labs.arxiv.org/html/1409.0473
  2. Zhang, Lipton, Li, Smola. Dive into Deep Learning — Sequence-to-Sequence Learningbook · retrieved 2026-09-13https://d2l.ai/chapter_recurrent-modern/seq2seq.html

Have a promo code?

A code that takes 100% off unlocks everything at once. A smaller one takes its share off the price in the payment window: enter the same code there.

Write to support

A question, a problem with access, a refund? Write to us and we answer by email.

What is it about?

Your address is used only to answer you.

Message sent

Thank you. We will reply to the address you gave, by email.

Or write to us directly

support@artofds.com

Message sent Thank you. We will reply to the address you gave, by email.

Check the email address: we need it to reply.

That is our own address. Enter yours, so the reply reaches you.

This address cannot receive email. Check it for a typo.

Write a little more: at least 10 characters.

Too many messages in a short time. Try again in a few minutes.

The message could not be sent. Please write to us directly: support@artofds.com