Seq2Seq: Turning One Sequence Into Another

A Seq2Seq model acts like a universal translator, reading one sequence to generate another. It's foundational for machine translation and text summarization. The main footgun is its fixed-size context vector, which can forget details from long inputs.
Why it exists
Before Seq2Seq, many neural network models required inputs and outputs to have the same, fixed length. This fails for common tasks like machine translation, where a sentence in one language rarely has the same number of words as its translation. Seq2Seq was designed to solve this variable-length sequence problem.
The mental model
Think of a Seq2Seq model as a two-part system: an encoder and a decoder. The encoder reads an entire input sequence, like a person reading a full sentence in French, and compresses its meaning into a single summary of thought—a 'context vector'. The decoder then takes this thought summary and generates the output sequence word by word, like a person speaking the equivalent sentence in English based on their understanding.
How it works
The model uses two Recurrent Neural Networks (RNNs). The encoder RNN processes the input sequence one item at a time, updating its internal state. After the last input item, the encoder's final state becomes the context vector—a single vector of numbers representing the entire input's meaning. This context vector is then fed as the initial state to the decoder RNN. The decoder generates the output sequence one item at a time, using the context and the previously generated item to predict the next, until it outputs a special 'end-of-sequence' token.
When to use it
Seq2Seq is the classic approach for tasks where an input sequence of one length maps to an output sequence of a different length. This includes machine translation (a sentence to its translation), text summarization (a long article to a short paragraph), and conversational AI (a user's question to a chatbot's answer). It's also used for image captioning, where the 'input' is a feature vector from an image and the output is a descriptive sentence.
When not to use it
The primary weakness of basic Seq2Seq is its reliance on a single, fixed-size context vector. For very long inputs, this vector becomes an information bottleneck, as it's difficult to cram all the necessary information into it. This can cause the model to 'forget' details from the beginning of the input. For tasks requiring memory of long-range dependencies, more advanced architectures like the Transformer (which uses an attention mechanism) have largely superseded classic Seq2Seq.
One canonical example
To translate the English sentence "The cat sat on the mat" to French, the encoder processes each word and produces a single context vector. The decoder, given this vector, starts generating the French translation. It might first produce "Le". It then takes "Le" and the context vector to generate "chat", and so on, until it produces the full sequence "Le chat est assis sur le tapis" followed by an end-of-sequence token.
Interview question
What is the primary limitation of a basic Seq2Seq model when dealing with very long input sequences?
- a.The fixed-size context vector acts as an information bottleneck, leading to the forgetting of early input details.Correct
- b.It struggles to accurately predict the end-of-sequence token, often resulting in overly long or truncated outputs.
- c.Its recurrent neural network architecture is inherently slow, making it computationally expensive for long inputs.
- d.It requires input and output sequences to be of the same fixed length, which limits its applicability.
Why? this is the answer
The card states that the "primary weakness of basic Seq2Seq is its reliance on a single, fixed-size context vector" which "becomes an information bottleneck" for "very long inputs," causing the model to "forget details from the beginning of the input." Option D describes the problem that Seq2Seq was designed to solve, not its limitation.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
- #seq2seq
- #nlp
- #machine learning
- #encoder-decoder
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles