Foundation Models: Tokens, Attention, And Generation · Lesson 8

Encoder And Decoder Models Explained

Compare model families by their permitted information paths and outputs. Then evaluate the model’s objective and the application’s actual task; architecture alone establishes neither quality nor delivery terms.

Study And Save Progress

Watch The Lesson

7 min 34 sec

Read the video transcript

A museum team has 3 jobs: find the right archive description, label a visitor comment, and translate a description into another language. A model that represents a complete text for comparison can help with the first jobs. Producing a new sequence adds another requirement.

Follow the same museum material through an encoder that reads both sides, a decoder that continues an allowed prefix, and an encoder–decoder that generates from encoded source material. These paths will help us choose a test, rather than guess from a product name. An encoder transforms its input into representations.

Consider the complete visitor comment: The bank beside the river is closed. In a bidirectional encoder, the representation at bank can use allowed context on both sides, including river. A task-specific output component could then use the resulting representation to assign a category to the comment.

The supplied sentence and museum task are teaching examples; no model has been run to classify them here. BERT provides a dated architectural example. Introduced in a 2018 preprint and published at NAACL in June 2019, it was designed to learn bidirectional representations using left and right context.

Its masked-language training hides some tokens and learns to predict them from the surrounding input. That objective differs from predicting each next token using only a preceding prefix. BERT's representation can support a classification or question-answering component after appropriate task adaptation; it is not a conversational service

merely because it processes language. For archive search, the system needs representations that bring relevant questions and descriptions together under a chosen comparison rule. A model trained for that retrieval objective may be a useful encoder, but a generic encoder output is not automatically a good search vector.

Evaluate which relevant descriptions it retrieves, which languages it covers, its dimensions, cost and compatibility with the stored index. The search result is a selected archive item; it need not be newly generated prose. Now ask for a continuation of the prefix: The exhibition opens on.

A causal decoder produces scores for possible next tokens under its allowed earlier context. After a token is selected and appended, the longer prefix supports the next step. At an earlier prediction, later generated tokens are unavailable. This information restriction is maintained inside the causal attention path, even when a

training program processes many prediction positions together. GPT-3's 2020 paper gives a historical autoregressive model example. The authors evaluated tasks specified through text instructions and demonstrations without updating the model's parameters for those task examples. This illustrates how a causal language model can receive a task through

its input and generate a continuation. It does not establish that a particular museum instruction will work reliably. Our team would still need to check its own task, output format and errors. A decoder can also return a category as text. For example, a prompt might request

exactly 1 of 3 visitor-comment labels. The application must then check that the response is an allowed label and assess the classification quality. Compare this with an encoder plus a category-output component: the routes produce different output objects and may have different resource and reliability tradeoffs.

The architecture name alone does not settle which route is more useful for the museum's volume and requirements. For translation, follow a separate source-conditioned path. The encoder reads the complete archive description and produces source representations. A decoder generates the target-language sequence using both its already available

target prefix and those source representations. Its self-attention is causally restricted on the target side. A separate encoder–decoder attention connection lets the target computation use the encoded source. The source description is available in full; future target tokens are not. The original Transformer paper, released in June 2017,

used this encoder–decoder design for translation. Its architecture diagram distinguishes the decoder's masked self-attention from its attention over encoder outputs. That historical example makes the separate information paths inspectable. A source-conditioned summarizer can use the same broad architectural family, while other systems can implement translation

or summary generation using a different family. Task names do not uniquely determine the architecture. Architecture is also separate from access. Downloadable weights, a hosted interface, licence conditions and data-handling terms answer questions about delivery and permitted use. They do not follow from

the words encoder or decoder. The museum might access a decoder through a service or run a suitable released model locally. Those choices require the actual licence, deployment resources and operational controls, not a guess from the information-flow diagram. Pause at the archive-search decision.

The museum already has a chat model and needs to retrieve relevant descriptions. Why is the chat model's availability insufficient evidence that its representations are the right embedding model for this index? Name the output the retrieval stage needs and what you would compare before choosing. Retrieval needs representations and a

comparison method that bring relevant queries and archive items together. Chat availability establishes neither a suitable retrieval objective nor compatibility with the index. Compare retrieval quality on representative queries, language coverage, representation dimensions, cost and index compatibility. Keep those retrieval results separate from whether

a later generator writes a fluent answer. Try a new task. A clinic has a complete, non-identifying information leaflet and wants a translation into another language. Sketch an encoder–decoder path showing what the encoder sees, what the decoder can use at each target step,

and which future information is unavailable. Does this diagram tell you whether the system must be hosted or whether its licence permits local use? The encoder can represent the complete source leaflet. At each target step, the decoder uses the available target prefix

and the encoded source, while later target tokens remain unavailable through causal self-attention. The architecture diagram supplies no hosting or licence decision. Inspect the actual offering and evaluate translation accuracy and terminology with an appropriate reviewer. No observed translation or deployment result is supplied by this sketch.

We have compared representations for a task, causal continuation and source-conditioned generation by following what information each computation may use and what it produces. Other model families and multimodal combinations extend beyond these text examples; the next course develops those distinctions. Within this course, the next question is

how prediction errors provide a learning signal that changes the parameters of a model.

Main Point

Compare model families by their permitted information paths and outputs. Then evaluate the model’s objective and the application’s actual task; architecture alone establishes neither quality nor delivery terms.

Key Points

1. Start from the museum’s required output

The museum wants to retrieve archive descriptions, label visitor comments and translate a description. Retrieval returns relevant items under a comparison rule. Classification returns a category. Translation produces a new sequence in another language. These outputs suggest different tests rather than a single model ranking.

TaskRequired outputEvidence to inspect
Archive retrievalRelevant item IDs and associated descriptionsRetrieval quality, language coverage, index compatibility
Comment classificationAn allowed categoryClassification quality, format validity, resource use
TranslationTarget-language sequenceAccuracy, terminology, source fidelity, operating terms

No museum model run or observed result is supplied here.

2. Represent the complete input with an encoder

For the teaching sentence “The bank beside the river is closed”, a bidirectional encoder can let the representation at “bank” use allowed context on both sides, including “river”. A task-specific output component can use representations for a classification task after appropriate adaptation.

BERT is a historical architectural case: its preprint appeared in October 2018 and its paper was published at NAACL in June 2019. Its bidirectional representations and masked-token objective use surrounding input. That differs from a causal next-token objective. The original masking procedure also includes replacement variations; the essential point here is prediction of selected input targets using bidirectional context.

An encoder’s general hidden state is not automatically a useful whole-item search vector. The representation, objective, comparison rule and corpus must work together. Check relevant retrieval results, dimensions, language coverage, cost and compatibility before changing an existing index.

3. Continue a prefix with a causal decoder

For the teaching prefix “The exhibition opens on”, the model computes possible next-token scores from the allowed prefix. A selected token extends that prefix for a subsequent prediction. Later generated tokens are unavailable at the earlier prediction. A causal mask preserves the restriction even when training processes multiple prediction positions together.

Brown and colleagues’ 2020 GPT-3 study used an autoregressive language model and supplied task instructions and demonstrations in text without task-example gradient updates. This historical method illustrates task conditioning through the input; it does not establish success on the museum’s examples or describe every contemporary conversational system.

A decoder can generate a category label as text. If an application permits exactly 1 of 3 labels, check the response against that set and measure classification quality. Compare its cost, output validity and reliability with an encoder plus a category-output component rather than inferring the winner from architectural labels.

4. Generate from encoded source information

An encoder–decoder translation path has 2 information sources at a target step:

The encoder represents the source. The decoder’s causal self-attention uses the available target prefix. A separate encoder–decoder attention connection accesses the encoded source. Future target tokens do not become available through that source connection.

The original 2017 Transformer translation architecture makes these connections explicit. A translation or summarization task can also be implemented using another family. A task name alone does not establish architecture.

5. Inspect access and task fit separately

A decoder might be offered through a hosted service or suitable released weights. Its family name does not establish whether local deployment is permitted, technically feasible or operationally appropriate. Inspect licence conditions, resources and data-handling terms for the actual offering.

These text families are part of a wider ecosystem that also contains diffusion and multimodal combinations. The next course develops modality and generation families further. Do not transfer a causal-text description to every AI system.

6. Closing

Follow available information and the output object before choosing a task test. Evaluate retrieval independently of later prose, classification independently of chat availability, and translation against source fidelity. The next lesson explains how prediction errors provide a parameter-learning signal.

7. Learning Checks

Attempt each question before opening its explanation. Use the blank worksheet for your own diagram and comparison plan.

M14-L08-Q01

A museum already has a chat model and needs to retrieve relevant archive descriptions. Why is chat availability insufficient evidence that its representations are the right embedding model for this index? Identify the retrieval output and useful comparisons.

Your explanation: ____________________

Show explanation after your attempt

The retrieval stage needs representations and a comparison method that place relevant queries and archive items together. A chat model’s availability does not establish a suitable retrieval objective or compatibility with the stored index. Compare retrieval quality on representative queries, language coverage, representation dimensions, cost and index compatibility. A later fluent answer is a separate outcome from retrieving the right archive evidence.

M14-L08-P01

A clinic has a complete, non-identifying information leaflet and wants a translation. Sketch an encoder–decoder path: what does the encoder see, what may the decoder use at each target step, and what remains unavailable? Does the diagram establish hosting or permission for local use?

Your explanation: ____________________

Show explanation after your attempt

The encoder can represent the complete source leaflet. At each target step the decoder uses its available target prefix and the encoded source. Later target tokens remain unavailable through causal self-attention. These information paths do not establish hosting or licence rights. Inspect the particular offering, licence, deployment resources and operating controls; evaluate translation and terminology with a suitable reviewer. The sketch supplies no observed translation result.

Sources

Learner Materials

Download Lesson 8 Learner Materials

Use the supplied fictional cases and templates for practice.

Practice

Write your answer, compare it with the model answer and decide what to revisit. These written checkpoints are self-assessed.

A museum already has a chat model and needs to retrieve relevant archive descriptions. Why is chat availability insufficient evidence that its representations are the right embedding model for this index? Identify the retrieval output and useful comparisons. Your explanation: ____________________

Show The Model Answer

The retrieval stage needs representations and a comparison method that place relevant queries and archive items together. A chat model’s availability does not establish a suitable retrieval objective or compatibility with the stored index. Compare retrieval quality on representative queries, language coverage, representation dimensions, cost and index compatibility. A later fluent answer is a separate outcome from retrieving the right archive evidence.

Compare your reasoning with the model answer. These written checks are self-assessed.

A clinic has a complete, non-identifying information leaflet and wants a translation. Sketch an encoder–decoder path: what does the encoder see, what may the decoder use at each target step, and what remains unavailable? Does the diagram establish hosting or permission for local use? Your explanation: ____________________

Show The Model Answer

The encoder can represent the complete source leaflet. At each target step the decoder uses its available target prefix and the encoded source. Later target tokens remain unavailable through causal self-attention. These information paths do not establish hosting or licence rights. Inspect the particular offering, licence, deployment resources and operating controls; evaluate translation and terminology with a suitable reviewer. The sketch supplies no observed translation result.

Compare your reasoning with the model answer. These written checks are self-assessed.

Open Practice And Save Your Work