Concepts / Transformer Architecture for Language Foundation Models

Transformer Architecture for Language Foundation Models

Large models need large amounts of training data, which is expensive and slow to collect, so providers often use whatever data is available, and that may leave gaps for specific tasks.

  • Programming

The Hospital Assistant Question

Imagine a hospital network that wants an assistant able to read and summarize clinical notes. The notes are written in a regional language and in one specialized medical vocabulary. Before anyone asks which model design to pick, a more basic question comes first: what has the model seen? A model can only become good at patterns that appear in the material it learned from. For foundation models, that material is the training data, and the course treats it as one of the most important factors in how a model performs.

This article follows the chain of decisions that shapes a language foundation model. It starts with training data, then moves to the architecture, the size of the model, the way the model is refined after its first training phase, and the way it produces output. Each choice connects back to the data question, so keep the hospital scenario in mind as you read. By the end you should be able to trace how a batch of token sequences moves through the transformer and how the scale numbers describing that model are related.

Why Training Data Sets the Ceiling

Large models need large amounts of training data. Collecting that data is expensive and slow, so providers often use whatever data is available. That practical choice has a consequence: the data may leave gaps for the specific tasks you care about. Curating training data is often necessary for low-resource languages and specialized domains, because the general data a provider can easily gather may contain little of the regional language or medical vocabulary the hospital needs.

The Transformer as the Default Design

Definition

The transformer is the dominant architecture for language-based foundation models, and it is chosen before training begins. Dominant means the common default, not the only design. A dominant design wins because it solves a set of problems well enough that most builders reach for it first. It does not mean every problem is solved or that the design is free of tradeoffs.

Architecture is a deliberate design response to earlier challenges. The course material says the transformer was designed to address certain problems and that it has limitations, and it explores both. The excerpt this article draws on does not list those problems or limitations by name, so this article does not claim a specific list. The practical takeaway is that understanding the transformer means understanding what it handles well and where it falls short.

Architecture is picked before training starts. Two teams that each want a language model may begin differently. One asks which data to gather and how to run the training job. The other first asks what shape the model itself should take. Training usually gets the attention in news coverage, but the architecture and model size decision happens earlier, and it controls how much compute training will require and what the finished model can do.

Three Numbers That Describe Scale

A model's scale is not captured by one number. It is described with three quantities, and each answers a different question. The number of parameters tells you how many learned values the model has. The number of training tokens tells you how much text the model is trained on. The number of FLOPs needed for training tells you how much computation the training run requires. The three are linked but separate.

QuantityWhat it countsQuestion it answers
ParametersLearned values inside the modelHow big is the model?
Training tokensUnits of text the model is trained onHow much data did it see?
Training FLOPsComputation needed for trainingHow expensive was it to build?

The three scale quantities and what each one tells you

In the real world

Consider two models with the same parameter count. If one is trained on a small amount of data and the other on a much larger amount, they can need very different amounts of compute. Reading only the parameter count tells you about the model's size but not about how expensive it was to build.

How Compute Depends on Size and Data

Training compute is shaped by two things: the size of the model and the size of the data. A bigger model has more learned values to adjust, and a bigger dataset means more text passes through the training process. Both push total compute upward. The numbers therefore have to be read together rather than one at a time.

Model sizeparametersTraining computeFLOPs neededScaling lawreads the budgetBalanced splitparameters vs tokensData sizetraining tokensCompute budgetfixed totaladds toadds tomust fit withinis read bysuggests
When total compute is fixed, how do increasing parameters and increasing training tokens compete, and what does the scaling law read and return?

The diagram shows the chain of reasoning. Model size and data size both draw on the same compute budget, so increasing one leaves less room for the other. The scaling law is the rule that reads the budget and suggests a balanced allocation between parameters and tokens. The excerpt does not provide a numeric formula for that balance, so the scaling law should be understood as a principle for deciding the split rather than a specific equation.

Deciding Between Bigger and Longer Training

Worked example

Spending a fixed compute budget

The hospital team can spend only a fixed amount of compute. Should it build a larger model trained on fewer tokens, or a smaller model trained on more tokens?

  1. 1
    Name the fixed resource

    The total compute budget is fixed. Whatever split the team chooses must fit inside it.

  2. 2
    Consider the larger-model option

    More parameters means more learned values to adjust, which raises compute per token. Fewer tokens lowers the data side of the total, so the budget can still be met.

  3. 3
    Consider the smaller-model option

    A smaller model with more tokens lowers the parameter side and raises the data side. The total still has to fit the same budget.

  4. 4
    Apply the scaling law

    Instead of guessing, the team uses a scaling law. The law takes the fixed budget and returns a recommended balance of parameters and tokens.

Result

The choice is a trade-off decided by a principle, not by intuition alone. The source does not supply numbers for the final split, so the team would need the scaling law's guidance and its own compute estimates to set the exact balance.

Tracing a Batch Through Query, Key, and Value

Models do not process one word at a time in isolation. Input tokens are handled in batches, and the shape of the data tells you how those batches are organized. The course material gives the shape of the input as $N \times T \times 4096$, where $N$ is the batch size and $T$ is the sequence length. The number 4096 is the width of each token's vector. The query, key, and value vectors that the transformer computes from that input have the same shape.

Input batch$N \times T \times 4096$Query vectors$N \times T \times 4096$Key vectors$N \times T \times 4096$Value vectors$N \times T \times 4096$computed fromcomputed fromcomputed from
How does a batch of token sequences change shape as it is used to compute query, key, and value vectors?

Read the diagram carefully. The input batch enters with three dimensions. Each of the query, key, and value tensors leaves with the same three dimensions. The shape is preserved across these vectors, so the batch size, the sequence length, and the vector width each keep the meaning they had at the input. The excerpt does not describe how the attention computation combines these tensors afterward, so this article stops at the shape of each vector.

Worked example

Reading the shape of a small batch

A batch contains 8 sequences, and each sequence is 512 tokens long. What is the shape of the input, and how many numbers does it hold?

  1. 1
    Assign the dimensions

    The batch size $N$ is 8, the sequence length $T$ is 512, and the width is 4096.

  2. 2
    Write the shape

    The input shape is $8 \times 512 \times 4096$.

  3. 3
    Count the values

    Multiplying the three dimensions gives $8 \times 512 \times 4096 = 16{,}777{,}216$ numbers in the batch.

  4. 4
    Check the query, key, and value shapes

    Each of the query, key, and value vectors has the same shape, so each also holds $8 \times 512 \times 4096$ numbers.

Result

The input and each of Q, K, and V have shape $8 \times 512 \times 4096$. The sequence length 512 is the T dimension, which is what a model's context length refers to.

Post-Training After Pretraining

A pretrained model is not yet tuned to what people want. Post-training follows pretraining and has two steps: supervised finetuning and preference finetuning. Post-training addresses outputs that do not align with what users want. It narrows the gap between what a pretrained model produces and what people want, but it does not guarantee a perfect match.

Pretraininglearns from training dataSupervised finetuningadjusts outputs withsupervised examplesPreference finetuningaligns with humanpreferenceUsable assistantcloser to what users wantthenthenyields
What sequence of stages turns a pretrained model into a usable assistant, and what problem does each stage address?

Sampling and Probabilistic Outputs

A model's output is not a single fixed answer. The model produces outputs through sampling, which makes them probabilistic. Because the output is drawn from possibilities rather than fixed in advance, the same input can lead to different outputs. This brings a benefit, since the model can produce varied wording and options, and a risk, since the output may change from one run to the next in ways a user did not expect.

The source material available for this article names sampling as part of how outputs are produced but does not detail the mechanism further. Treat the benefit and risk described here as the general consequence of probabilistic output, and check the course's fuller treatment of sampling before relying on specifics.

Mistakes Beginners Make With Model Scale

  • Common mistake

    Judging a model by its parameter count alone

    What it looks like

    Two models share a parameter count, so the reader assumes they cost the same to build.

    Why it fails

    Training compute also depends on how much data the model sees, so equal parameter counts can hide very different training costs.

    Do this instead

    Read parameters, training tokens, and training FLOPs together.

  • Common mistake

    Assuming a dominant architecture is the only valid design

    What it looks like

    A builder rejects every alternative because the transformer is the common choice.

    Why it fails

    Dominant means the default for this family of models, not the only design anyone has tried.

    Do this instead

    Treat the transformer as the common default and evaluate tradeoffs for the specific task.

  • Common mistake

    Expecting training data volume to fix every gap

    What it looks like

    A team adds more general text and expects the model to learn a specialized medical vocabulary.

    Why it fails

    Providers often use whatever data is available, which may leave gaps for specialized tasks and low-resource languages.

    Do this instead

    Curate data for the specific language or domain the model must handle.

  • Common mistake

    Mixing up batch size and sequence length

    What it looks like

    A reader treats the $T$ in $N \times T \times 4096$ as the number of sequences in the batch.

    Why it fails

    $N$ is the batch size, and $T$ is the sequence length. Mixing them up gives wrong estimates of memory and compute.

    Do this instead

    Name each dimension: $N$ counts sequences, $T$ counts tokens per sequence, and 4096 counts numbers per token vector.

  • Common mistake

    Believing post-training guarantees a perfect match with user wants

Practice: Reading a Model's Numbers

MEDIUM

A team reports that its model has a large parameter count, and it claims the model is therefore the most expensive to build. Explain why this conclusion is incomplete, and name the other two scale quantities you would need before judging the cost.

Hints
  • Recall the three scale quantities: parameters, training tokens, and training FLOPs.
  • Think about whether a model can be large in parameters but trained on little data.
  • Compare what the parameter count tells you with what training FLOPs tell you.
EASY

Given a batch of 16 sequences that are each 256 tokens long, with a vector width of 4096, write the shape of the input batch and of its query, key, and value vectors. Then say which dimension corresponds to the context length.

Hints
  • Batch size is N, sequence length is T, and width is the third dimension.
  • Query, key, and value vectors share the input's shape.

Key Takeaways

  • Training data quantity and quality shape what a foundation model can do, and gaps often appear for specialized tasks and low-resource languages.
  • Scale is described by parameters, training tokens, and training FLOPs, which are linked but separate quantities.
  • Training compute depends on model size and data size, and a scaling law uses a fixed compute budget to suggest a balance between parameters and tokens.
  • The transformer is the dominant default for language foundation models, chosen before training; its input batch of shape N × T × 4096 keeps the same shape in its query, key, and value vectors.
  • Post-training after pretraining uses supervised finetuning and preference finetuning to narrow the gap with user wants, but it does not guarantee a perfect match.

Related concepts

More concepts starting with T