Learning Outcome
4
Apply encoder-only vs decoder-only choices to real tasks.
3
Recognize how next-token prediction builds a full answer.
2
Identify the main parts of a Transformer.
1
Understand what makes a language model "large".
5
Connect LLMs to the chat products you use every day.
What is a Large Language Model?
A neural network trained on huge amounts of text to predict what comes next.
Large training data trillions of tokens from websites, books, articles, and code.
Large number of parameters billions to hundreds of billions of learned numbers that store what it knows.
A type of Generative AI it creates new content rather than only classifying.
Also called a foundation model i.e. one model adapts to thousands of tasks without building a new one each time.
Next-Token Prediction
Score every token
In the vocabulary (tens to hundreds of thousands).
Softmax
Turns scores into probabilities that add up to 1: "New" 0.92, "Delhi" 0.03, …
Read the context
Eg. "The capital of India is".
Choose one token
From those probabilities.
Predicting the next token well forces the model to learn grammar, facts, reasoning patterns, coding conventions, and writing styles.
Autoregressive Generation: How Full Answers Are Built
Predict one token for the prompt.
Append it to the end of the text.
Repeat with the longer text as the new input.
Stop at a special end token or a length limit.
while not finished:
next_token = model.predict(text)
text = text + next_tokenCode
This is why answers stream word by word, longer answers take longer, and an early mistake carries through the rest.
The Transformer Architecture
Token embeddings
Positional information
Self-attention
Each token becomes a list of numbers; related words (doctor, nurse) sit close.
Tells "dog bites man" from "man bites dog".
Each token gathers information from the tokens that matter to it.
Introduced by Google researchers in the 2017 paper "Attention Is All You Need". It reads all tokens together instead of one at a time.
Feed-forward layers
Stacked layers
Output layer
Refine each token's representation.
Dozens of attention + feed-forward blocks, each building richer understanding.
Turns the last token's representation into next-token scores.
How Self-Attention Works (Core Mechanism)
Step 4
Value
Step 3
Compare
Step 2
Key
Step 1
Query
What this token is looking for ("she" looks for a person).
What each token offers ("student" signals a person).
Each query is matched against every key to get attention weights.
Information from relevant tokens is combined using those weights.
In "The trainer praised the student because she solved the problem", "she" must connect to "student".
Multi-head attention runs many of these in parallel to track grammar, references, and topic. Causal masking lets a generating model attend only to earlier tokens, so it can't peek ahead.
Three Types of Transformer Models
Encoder-only
Decoder-only
Encoder-decoder
Reads the whole text in both directions to understand it; doesn't generate long text. Example: BERT (Google, 2018), used for classification, search, embeddings.
Generates text token by token with causal masking. Examples: GPT family, Meta's Llama, most modern chat LLMs.
Encodes an input, then decodes a new output; suits translation and summarisation. Example: T5 (Google).
RNN vs Transformer
| Aspect | Recurrent Neural Network (RNN) | Secret |
|---|---|---|
| How text is read | One token at a time, in order | All tokens together, in parallel |
| Long-range connections | Weak; early words fade | Strong; any token attends to any other |
| Training speed | Slow; steps depend on each other | Fast on GPUs; work is parallel |
| Scale achieved | Millions of parameters | Billions to hundreds of billions |
| Typical use today | Platform setMostly replaced for languagetings or config files | Basis of almost all modern LLMs |
| Analogy | Keyboard looking at the last word | Keyboard reading your whole message |
Think About This: Spotting the Difference
Encoder-only: understanding, not generation.
Decoder-only: generates new text token by token.
A chatbot writing replies to learners
Encoder-only: represents meaning as vectors.
The LLM provider API key
Classifying student feedback comments as positive or negative
Real-World Applications
Chat products
A leaked dev key can't touch production data.
GitHub secret scanning
Blocks pushes containing recognised keys; bots scan public repos in minutes.
LLM apps
Keys never go to the browser or mobile app; the front end calls your API, and only the server calls the LLM.
Leaked LLM key
Can run up a large bill within hours, so revoke first.
Summary
5
Chat apps are products built on LLMs.
4
Generation: predict, append, repeat.
3
Attention links tokens that matter.
2
Embeddings turn tokens into numbers.
1
An LLM is a giant next-token predictor.
Quiz
Why does a chatbot's answer appear on screen word by word?
A. The internet connection is slow
B. Generates tokens sequentially, building text.
C. The model searches the web for each word
D. An encoder reads the answer backwards first
Quiz-Answer
Why does a chatbot's answer appear on screen word by word?
A. The internet connection is slow
B. Generates tokens sequentially, building text.
C. The model searches the web for each word
D. An encoder reads the answer backwards first