Concepts / Training Large Language Models

Training Large Language Models

A tokenizer answers the question how is text cut into pieces. A language model answers the question what patterns exist across those pieces. Both appear in the same pipeline, but they are not the same thing.

  • Programming

Why a Model Needs Pieces of Text

Imagine you want a program that can write fluent sentences. You could try to write rules for grammar and word choice by hand, but language is too varied for that to work. A different approach is to let a model learn patterns from a large body of text and then use what it learned to generate new text. The process of building that learned starting point is called pretraining. It is the stage where a model is first trained on text before anyone asks it to do a specific job.

Before a language model can learn anything from text, that text has to be broken into pieces. Those pieces are called tokens, and the process of producing them is called tokenization. This article focuses on one particular tokenization scheme, byte pair encoding, usually abbreviated BPE. It also places that scheme inside the larger path that leads from raw data to a model you can evaluate.

Tracing a Piece of Text Through the Pipeline

The easiest way to see the roles of each component is to follow a piece of text from start to finish. Raw text goes into the BPE tokenizer. The tokenizer produces tokens. Those tokens are part of what the language model learns from during training. Each arrow in this trace marks a change of role, not a change of content, and keeping track of which component owns which step is the key skill for the rest of this article.

Raw textinput to the pipelineBPE tokenizersplits text into tokensTokenswhat the tokenizer producesLanguage modeltrained on the tokensgoes inproducesused during training
What does the tokenizer produce, what does the model consume, and how do the two components connect? Raw text enters the BPE tokenizer, which produces tokens; the language model is trained on those tokens.

Where BPE Sits Among Tokenization Schemes

Definition

Byte pair encoding (BPE) is a tokenization scheme, meaning a method for splitting text into tokens.

The source introduces BPE as a more sophisticated tokenization scheme than the simpler approaches that come before it. The word sophisticated is the key signal. BPE is not a basic way of cutting text apart; it is a scheme built on a specific concept, namely byte pair encoding. So the safe classification to hold onto is this: BPE is one way to split text into tokens, and it is considered more capable than the simpler schemes introduced earlier in the same chapter.

Why BPE Matters in Practice

The reason BPE deserves attention is its use in practice. The source states that a BPE tokenizer was used to train large language models such as GPT-2, GPT-3, and the original model used in ChatGPT. In other words, BPE was not only a topic in theory. It was part of the pipeline that prepared text for training some of the best-known language models.

In the real world

GPT-2, GPT-3, and the original ChatGPT model are the three named examples in the source. Each of them was trained on tokens produced by a BPE tokenizer, which means the tokenizer decided the pieces the model actually saw during learning, even though the tokenizer itself is not the model.

Tokenizer Versus Language Model

The tokenizer and the language model are different parts of the pipeline. The tokenizer's job is to turn text into tokens. The language model's job is to learn from those tokens during training. Because the two are separate, you can say what each one is responsible for without mixing them up. The tokenizer produces the tokens; the model is trained on them.

Key point

A tokenizer answers the question how is text cut into pieces. A language model answers the question what patterns exist across those pieces. Both appear in the same pipeline, but they are not the same thing.

Pretraining in the Course Path

In this course, pretraining is treated as the second major stage of work. The first stage prepares the ingredients: data preprocessing and the attention mechanism at the core of modern LLMs. The second stage puts those ingredients together, showing how to code and pretrain a GPT-like model that can generate new text, and then how to evaluate the result. Keeping these stages in mind helps you see why each topic exists.

Data preprocessingturns collected text intotraining materialAttention mechanismcore of modern LLMsPretrainingcode and pretrain aGPT-like modelLoad open modelweightsreach a trained modelwithout full trainingEvaluationmeasure what the model doesthenthenthenthen
What comes before pretraining in the course sequence, and what follows it? Stage 1 prepares data and attention; stage 2 pretrains a model and then evaluates it. Loading open weights is a branch beside pretraining, and both routes end at evaluation.

A helpful way to hold the whole topic is to follow one path. Start with raw data and ask what must happen before a model can learn from it. Then ask what the model needs in its design, and what training does with that design. Finally, ask how you judge whether the trained model is any good, and whether you should train it yourself at all or start from weights someone else already produced.

Preparing the Ground for Pretraining

Stage 1 of the course is where the foundations are laid. Pretraining depends on two of them: data preprocessing and the attention mechanism. Neither is the training itself, but each one has to be understood before the training stage makes sense.

Training From Scratch or Loading Open Weights

There are two routes to a trained model. The first is to pretrain an LLM from scratch. The second is to load openly available model weights, which means starting from a set of learned values that someone else already produced. The source treats loading weights as an alternative way to reach a trained model without running the full training yourself.

AspectTrain from scratchLoad open model weights
CostThousands to millions of dollars for GPT-like modelsAvoids the full training cost
InputText data, prepared through preprocessingOpenly available model weights
Purpose in this courseEducational: implement training on a small datasetAlternative route to a trained model
Still required afterwardEvaluationEvaluation

Two routes to a trained model, as described in the course

The cost is the reason the course narrows its goal. Pretraining at full scale demands thousands to millions of dollars in computing costs for GPT-like models, a range wide enough that full-scale pretraining is a major commitment rather than a routine exercise. So stage 2 focuses on implementing training with a small dataset for educational purposes.

Why Evaluation Is Required

The third topic in stage 2 is evaluating LLMs, which the source describes as essential for developing capable NLP systems. A trained model is a set of learned values, and those values alone do not tell you whether the model produces good text. Evaluation is the step that measures what the model does, so that you can compare versions and decide what to change.

Evaluation applies to both routes. A model you pretrain on a small dataset needs to be evaluated, and so does a model whose weights you loaded from an open source. Because the weights in the second case came from elsewhere, you cannot assume they behave as you expect in your own setting. Measuring is how you find out.

Mistakes Learners Make

  • Common mistake

    Treating the tokenizer and the language model as one component

    Why it fails

    The tokenizer produces tokens, and the language model is trained on them. They play different roles in the pipeline.

    Do this instead

    Name the tokenizer as the thing that splits text, and the model as the thing that learns from the resulting tokens.

  • Common mistake

    Assuming BPE's merge rules are explained in this article

    Why it fails

    The source classifies BPE as a more sophisticated tokenization scheme but explicitly defers the merging steps to the next stage of study.

    Do this instead

    Keep the classification in mind now and treat the mechanics as a later topic.

  • Common mistake

    Thinking loading open weights makes evaluation unnecessary

    Why it fails

    Both routes end at evaluation, and weights from elsewhere cannot be assumed to behave as expected in your own setting.

    Do this instead

    Always measure the model you have, whether you trained it or loaded it.

  • Common mistake

    Treating pretraining from scratch as a routine exercise rather than a major cost commitment

Checking Your Understanding of the Route

EASY

Without looking back, trace the path of a piece of text from raw input to a model you can judge. Name the tokenizer, the tokens it produces, the model that learns from them, and the step that tells you whether the result is any good. Then say which step would be skipped if you loaded openly available weights instead of pretraining.

Hints
  • Start with the component that splits text into tokens.
  • Remember that the model is trained on the tokens, not on the raw text directly.
  • Think about which step both routes share at the end of the path.

Key Takeaways

  • Byte pair encoding (BPE) is a tokenization scheme for splitting text into tokens, and the source presents it as more sophisticated than the simpler schemes before it.
  • A BPE tokenizer was used to train LLMs such as GPT-2, GPT-3, and the original ChatGPT model. The tokenizer produces tokens, and the language model is trained on them.
  • Pretraining is the second major stage of the course. Stage 1 covers data preprocessing and the attention mechanism, and stage 2 pretrains a GPT-like model and evaluates it.
  • Training from scratch at full scale costs thousands to millions of dollars, so the course uses a small dataset for education. Loading open weights is an alternative route.
  • Evaluation is required whichever route you take, because a model's learned values alone do not show whether it produces good text.

Related concepts

More concepts starting with T