AI Glossary / Generative AI and language / Intermediate
Sequence-to-sequence (seq2seq)
Definition
Sequence-to-sequence, often shortened to seq2seq, describes a model or task that transforms an input sequence into an output sequence. The two sequences can have different lengths and need not use the same vocabulary or modality. Translation and summarization are familiar language examples. Seq2seq identifies the mapping being learned; it does not specify one unique neural architecture or guarantee that the generated sequence faithfully preserves the input's meaning.
What it means
A classifier might assign one category to a whole document. A seq2seq system instead produces an ordered series of outputs, such as the words of a translation or the tokens of a summary.
The output is not required to align one-to-one with the input. A short phrase in one language may need more words in another, and a summary deliberately compresses a longer passage. The model must learn both what to produce and when to stop.
Encoder-decoder architectures are strongly associated with seq2seq. Historical implementations used recurrent networks, while transformer implementations use attention-based components. The task description is broader than either implementation.
How it works
In a typical encoder-decoder system, the encoder processes the input into representations. The decoder generates the output using those representations and, in an autoregressive design, the output tokens already available at that step.
Training commonly uses paired input and target sequences. Under teacher forcing, the decoder receives the earlier target tokens while learning to predict the next one. At inference, it instead conditions on its own generated tokens, so early mistakes can influence later output.
A decoding procedure selects the final sequence using rules such as greedy selection, beam search, or sampling. Input limits, output stopping conditions, and special tokens are part of the implementation. Evaluation must address the task's required content and accuracy, not merely whether a well-formed sequence was generated.
Three practical examples
1. A translation model maps a customer message in one language to a response-ready translation in another language.
2. A summarization system maps a long incident report to a shorter sequence describing the main events and unresolved issues.
3. A speech-recognition system maps an audio-derived input sequence to a text sequence, using an architecture and training objective suited to that task.
Think of it this way
Think of seq2seq as rewriting an ordered message into another ordered message under a transformation rule. The result may be shorter, longer, or expressed in a different language while still needing to preserve the intended information.
The analogy has limits. A neural model learns patterns from examples rather than executing a perfect translation rule. It can omit details, add unsupported content, or choose an incorrect order even when the output sounds natural.
Worked example
Consider a toy task that converts informal order notes into standardized text. Input: “Need two blue folders tomorrow.” The intended output is “Order: 2 blue folders. Delivery: tomorrow.” The input and output clearly differ in length and formatting.
During a simplified autoregressive decoding trace, suppose the model assigns probabilities 0.8, 0.9, and 0.5 to three successive target tokens, conditioned on the input and the preceding target tokens. Their joint conditional probability for that three-token fragment is 0.8 × 0.9 × 0.5 = 0.36.
A full sequence probability would include every generated token and the relevant end marker. The fragment calculation does not establish that the order is valid or that “tomorrow” has been resolved to the correct calendar date. Those are separate application checks.
Illustrative case study
Fictional case: Meadow Notes builds a seq2seq system to turn field notes into structured summaries. Early outputs look consistent, but reviewers find that some summaries drop uncertainty words such as “possibly” and “reported”.
The team adds explicit evaluation cases for uncertainty and source attribution. It checks the whole output against the input instead of scoring only formatting and word overlap with a reference.
It also provides a review path when notes are incomplete. The project treats the sequence transformation as a useful drafting capability, while retaining responsibility for whether the transformed text preserves the information needed by its readers.
Common misconceptions and mistakes
Seq2seq does not require input and output sequences to have equal lengths. It is also different from token labeling, where a label may be assigned to each input position under a more direct alignment.
Another mistake is assuming the encoder must compress everything into one fixed vector. Some early designs did, but attention-based encoder-decoder systems can expose multiple input representations to the decoder.
The model is not necessarily recurrent, and a seq2seq label does not imply a specific decoding rule. Finally, fluent output is not proof of source faithfulness: content preservation needs task-specific checks.
Business use
Seq2seq provides a useful way to frame business tasks that transform language or other ordered information into a new sequence. The framing helps define training pairs, output requirements, and evaluation examples.
Before selecting a model, establish which input details must survive, what transformations are permitted, and how missing information should be handled. Measure omissions, unsupported additions, and critical value changes alongside general quality. Consider whether a simpler extraction or templating system can satisfy the requirement when the output is tightly constrained and factual precision dominates flexibility.
People also ask
Is seq2seq the same as an encoder-decoder transformer?
No. That is one common implementation. Seq2seq describes the broader input-to-output sequence mapping.
Can the input be audio rather than text?
Yes. Sequence transformations can involve different modalities when the model and data are designed for them.
Why can inference differ from training?
In common teacher-forced training, the decoder sees correct earlier target tokens. During generation, it often sees its own earlier outputs, which may contain mistakes.
Check your understanding
A summarizer takes 600 input tokens and generates 80 output tokens. Does the different length mean it is not a seq2seq system?
Answer: No. Different input and output lengths are normal for seq2seq tasks. The relevant question is whether the generated sequence performs the intended transformation correctly.
Related terms
- Encoder
- Decoder
- Transformer
- Recurrent neural network
- Teacher forcing
- Attention
- Machine translation
- Beam search
- autoregressive generation
- summarization
Learn next
Define a small transformation task with paired inputs and reviewed target outputs. Identify which changes are allowed and which facts must remain exact. Trace the encoder input, decoder context, and stopping condition for one example. Then evaluate a generated output for both sequence quality and preservation of required information.
More in Generative AI and language
- Sampling rate - Sampling rate is the number of signal measurements taken or represented per second, usually expressed in hertz.
- Sampling with replacement - Sampling with replacement is a selection procedure in which an item remains eligible to be selected again after it has been drawn.
- Self-attention - Self-attention is a neural-network mechanism that updates representations of positions in a sequence by combining information from positions in that same...
- Sequential importance sampling - Sequential importance sampling, or SIS, is a probabilistic inference method that builds candidate sequences incrementally and updates a weight for each...
- Skip-gram negative sampling - Skip-gram negative sampling, commonly abbreviated SGNS, is a method for learning word vectors by distinguishing observed word-context pairs from randomly...
- Specificational coding - Specificational coding is an approach to creating software by writing and maintaining a human-language specification file that describes the required...
Sources
Sources: Hugging Face Transformers glossary, https://huggingface.co/docs/transformers/main/en/glossary — supplied seq2seq definition and training-label context. Sutskever, Vinyals, and Le, Sequence to Sequence Learning with Neural Networks, https://arxiv.org/abs/1409.3215 — original author abstract for historical recurrent encoder-decoder modeling. Vaswani and colleagues, Attention Is All You Need, https://arxiv.org/pdf/1706.03762 — original transformer encoder-decoder description. The order example and fictional case are original illustrations.
Previous: Sequence model Next: Sequence-to-sequence task