How Large Language Models Work
Open up a chat assistant. Text becomes tokens, tokens become vectors, attention lets every word look at every other, and a temperature dial decides how adventurous the next word is. Then see how raw models are turned into helpful assistants.
Start this course →Lessons
- 1Text becomes tokensSee how text is chopped up and numbered before a model reads it.7 min
- 2Meaning as numbersUnderstand embeddings: words as points where nearby means similar.7 min
- 3Attention and transformersUnderstand how each word uses the other words around it.7 min
- 4Generating text, and becoming an assistantSee how the next word is chosen, and how a raw model becomes a helpful assistant.8 min
What you will learn
- A tokenizer splits text into tokens and numbers them.
- Tokens are often pieces of words; common words are one token, rare words several.
- The model only ever sees token numbers, never letters.
- Each token becomes an embedding: a vector of numbers.
- Similar meanings end up with nearby vectors.
- Cosine similarity measures how close two vectors point.
- Attention lets each token weigh every other token in the context.
- A transformer stacks many attention layers with simple neuron layers.
- Stacking layers lets the model build up meaning step by step.
- The model outputs a score for every token; softmax turns them into probabilities.
- Temperature controls how adventurous the choice is.
- Pretraining, then fine-tuning and RLHF, turn a text predictor into an assistant.
Terms explained in this course
- tokenizer
- The tool that splits text into tokens and gives each one a number, before the model sees it.
- vocabulary
- The fixed list of all tokens a model knows. Large models use tens of thousands to hundreds of thousands.
- vector
- A list of numbers. In AI, a vector often represents something, such as a word, as a point in space.
- embedding
- A vector that represents a token, word or sentence so that similar meanings get nearby vectors.
- cosine similarity
- A measure of how closely two vectors point in the same direction, from −1 (opposite) to 1 (same direction).
- attention
- The mechanism that lets each word in a text decide how much to take into account every other word.
- transformer
- The neural network design behind modern language models. It is built from many layers of attention and simple neuron layers.
- softmax
- A function that turns a list of scores into probabilities that are all positive and add up to 1.
- temperature
- A setting that sharpens or flattens the next-token probabilities. Low temperature makes the likeliest token even likelier; high temperature gives unlikely tokens more chance.
- pretraining
- The first, enormous training stage, in which a model learns to predict the next token on huge amounts of text.
- fine-tuning
- Further training of a pretrained model on a smaller, focused dataset to change its behaviour or specialise it.
- reinforcement learning from human feedback
- Training a model with a reward based on which of its answers people preferred, to make it more helpful and safer. Often shortened to RLHF.