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

How Embeddings Represent Information

A token ID selects a learned vector. Model computation then uses context and position to produce hidden states for the supplied input; a retrieval representation serves its own defined task.

Study And Save Progress

Watch The Lesson

7 min 2 sec

Read the video transcript

Consider 2 sentences: “Sit beside the river bank” and “Deposit money at the bank.” In our classroom tokenizer, bank is 1 unit with ID 417 in both sentences. The model needs to use its surroundings to distinguish the situations. How can the same identifier lead to a representation that depends on the sentence?

The last lesson established what an identifier does: it selects an entry in a vocabulary. The next step is an embedding lookup. An embedding is an ordered list of learned numerical values, called a vector. The lookup uses the token ID to select a row

from the model’s embedding table. That row supplies numbers the model can transform through calculation. Suppose the bank row in a tiny teaching table contains 0.2, negative 0.4, and 0.7. ID 417 selects that 3-coordinate vector. Another selected row can

contain a different vector. The row numbers identify entries; the coordinates are the representation used in subsequent computation. These supplied numbers help us follow the lookup. They are not a measurement of a production model or a claim that 1 coordinate literally means river or money.

2 dimensions of the table matter. Vocabulary size determines how many token entries it can contain. Embedding dimension determines the number of coordinates in each row. With 50,000 entries and 1,000 coordinates per entry, a simple table holds 50,000,000 scalar values.

Multiplying the row count by the coordinates per row gives that result. This counts 1 matrix. The full model contains other learned transformations, so this calculation does not give its total parameter count. Keep the bank row and the checkpoint fixed while we change the surrounding sentence.

The initial token embedding can stay the same, while the model’s layers combine information under the architecture and produce context-dependent representations. An intermediate representation is called a hidden state. At the bank position, a later hidden state can depend on the surrounding river words or payment words.

The model is computing for the supplied sequence; this example has not performed a training update. The sequence must also preserve order. “The dog chased the cat” and “The cat chased the dog” contain the same familiar words but describe different relationships. Position information helps the model

distinguish where each unit occurs. Depending on the architecture, position can be represented or applied in different ways. When we follow the layers, we need the token representations, their order, and the rules governing which positions can interact. A dated architecture example makes that concrete.

Devlin and colleagues introduced BERT in October 2018 and published the paper at NAACL in June 2019. Its input representation adds 3 kinds of vector: the token’s learned representation, a vector marking which input text segment it belongs to, and its position. Its bidirectional encoder uses

context from both sides. The input construction and the later hidden states therefore perform different jobs. We will compare this encoder’s information boundary with causal generation later. Adding position information does not give a coordinate an automatic human label. In a trained model, useful patterns can

be distributed across many coordinates and transformations. A particular coordinate might participate in several relationships. To argue that it consistently represents a named concept would require a separate investigation. For this lesson, follow which object is a vocabulary identity, which is an input vector, and which

is the state produced after contextual computation. There is another representation boundary worth keeping clear. A retrieval system may turn a whole sentence or document into a vector for comparing it with a query. That representation needs an appropriate training objective and a way to

combine information across the input. An internal token state in a language model is produced for a different role. Its presence alone does not establish a useful document-similarity system. A retrieval test should check the intended corpus and query task. Imagine searching a collection containing a

river-bank description and a bank-loan document. A question about erosion calls for the river document; a question about loan interest calls for the financial document. The retrieval application needs a representation and comparison rule suited to those selections. Inside a language model, we may instead inspect the state at 1 bank

token while it processes a supplied sentence. The objects differ in what they represent and how the application will use them. Calling both an embedding does not specify those choices. Pause for a checkpoint. In our supplied example, ID 417 selects the same initial

bank row for 2 different sentences. Must its final hidden state also be identical? Separately, what does a 50,000 by 1,000 embedding table contain? Explain what each number counts before continuing. The initial lookup can be identical while the later state changes with

context and position under the architecture. The table has 50,000 token entries, each with 1,000 coordinates, for 50,000,000 scalar values. That is the size of the defined embedding matrix. It leaves other model parameters and runtime state outside the calculation. For a separate practice task,

a simple embedding table has 30,000 entries with 512 coordinates each. Calculate its scalar-entry count. A colleague then says token ID 418 must be semantically closer to 417 than to ID 900. Explain what evidence would be needed for a similarity claim.

Pause and use the blank worksheet. The table contains 15,360,000 scalar values. The neighboring identifier values establish no semantic distance. To study similarity, identify the actual learned representations, the comparison rule, and the relevant task, then test the relationship.

The IDs alone supply none of those measurements. We can now follow bank from an identifier into a learned row, then through order-sensitive contextual computation into a hidden state. We can also ask whether a vector represents 1 token inside a model or a whole item for retrieval.

The next question concerns what survives the request: which numerical values belong to the saved model, and which values were computed while it processed this input?

Main Point

A token ID selects a learned vector. Model computation then uses context and position to produce hidden states for the supplied input; a retrieval representation serves its own defined task.

Key Points

1. Follow the lookup

Our supplied classroom tokenizer represents `bank` as 1 token with ID 417 in both “Sit beside the river bank” and “Deposit money at the bank.” These are teaching inputs; no model run is reported. The identifier selects a row in an embedding table. The selected row contains learned numerical coordinates.

Selected classroom rowTokenSupplied vector
416garden(-0.6, 0.1, 0.3)
417bank(0.2, -0.4, 0.7)
903believ(0.5, 0.8, -0.2)

Only selected rows are shown. The gap between row labels does not specify missing rows or semantic distance. ID 417 chooses `(0.2, -0.4, 0.7)` under these rules. The 3 coordinates are an ordered vector; none has been assigned the literal label “river” or “finance.”

2. Calculate the table's size

A simple table with 50,000 vocabulary entries and 1,000 coordinates per entry contains:

`50,000 × 1,000 = 50,000,000 scalar entries`.

The 50,000 is the row count; 1,000 is the number of coordinates in each row. This counts the specified embedding matrix. It excludes other model transformations and says nothing by itself about runtime memory. A diagram of 1 selected row must not be mistaken for the whole vocabulary or the full model.

3. Follow a representation through context

Keep the checkpoint and token ID fixed. The initial `bank` embedding can be identical in the 2 sentences, while later model computation incorporates their surroundings and yields different hidden states. A hidden state is an intermediate representation produced in that computation. It can change when the input changes without implying a permanent parameter update.

Information is distributed across coordinates and transformations. Finding a useful pattern does not justify treating every coordinate as a named concept. An interpretation claim needs evidence about the representation and method being studied.

4. Preserve order and inspect an actual architecture

“The dog chased the cat” and “The cat chased the dog” use the same words in different relationships. Position information helps distinguish their sequence order. Its implementation is part of the architecture.

Devlin and colleagues' BERT preprint appeared on 11 October 2018; the paper was published at NAACL in June 2019. It combines token, segment and position embeddings at input and uses a bidirectional encoder. The segment component marks which input text span a token belongs to. Its input construction and subsequent contextual states are distinct stages. This historical mechanism gives an inspectable example; causal generation will impose a different information boundary later in the course.

5. Choose the representation for its job

A query about erosion should retrieve the river document; a query about loan interest should retrieve the financial document. A sentence/document representation and comparison rule need evaluation for that retrieval task. An internal state at 1 `bank` token represents a different object in a different computation. Pooling, training objective, input unit and similarity rule can affect what is useful. Keep those choices explicit rather than assuming any available vector is suitable.

6. Closing

You can now trace an ID into its learned row, distinguish table axes, and explain how order and context enter later computation. You can also ask whether a vector represents a token or a whole retrieval item. The next lesson separates persistent learned values from values computed during a request.

7. Learning Checks

Attempt the questions before opening the explanations. Keep the separate worksheet blank during your attempt.

M14-L03-Q01

In our supplied classroom example, ID 417 selects the same initial `bank` row for 2 different sentences under the same checkpoint. Must the final hidden state also be identical? What does a 50,000 × 1,000 embedding table contain, and what does each axis count?

Your explanation and calculation: ____________________

Show explanation after your attempt

The initial lookup can match while later hidden states differ because context and position participate in subsequent computation. The table has 50,000 token entries with 1,000 coordinates each: 50,000,000 scalar values. This counts the defined embedding matrix rather than all model parameters or runtime state.

M14-L03-P01

A simple embedding table has 30,000 entries and 512 coordinates per entry. Calculate its scalar-entry count. A colleague claims ID 418 must be semantically closer to ID 417 than to ID 900. What would you need to investigate that claim?

Your calculation and evidence plan: ____________________

Show explanation after your attempt

The product is 15,360,000 scalar entries in this matrix. Numeric proximity of IDs establishes no semantic distance. Identify actual learned representations, a comparison rule and the relevant task, then test the relationship. The identifiers alone provide no such measurement.

Sources

Learner Materials

Download Lesson 3 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.

In our supplied classroom example, ID 417 selects the same initial `bank` row for 2 different sentences under the same checkpoint. Must the final hidden state also be identical? What does a 50,000 × 1,000 embedding table contain, and what does each axis count? Your explanation and calculation: ____________________

Show The Model Answer

The initial lookup can match while later hidden states differ because context and position participate in subsequent computation. The table has 50,000 token entries with 1,000 coordinates each: 50,000,000 scalar values. This counts the defined embedding matrix rather than all model parameters or runtime state.

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

A simple embedding table has 30,000 entries and 512 coordinates per entry. Calculate its scalar-entry count. A colleague claims ID 418 must be semantically closer to ID 417 than to ID 900. What would you need to investigate that claim? Your calculation and evidence plan: ____________________

Show The Model Answer

The product is 15,360,000 scalar entries in this matrix. Numeric proximity of IDs establishes no semantic distance. Identify actual learned representations, a comparison rule and the relevant task, then test the relationship. The identifiers alone provide no such measurement.

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

Open Practice And Save Your Work