This first lecture sets the scene. We ask: what is a language model, why has it become so powerful, and how did we get here?
A fantastic narrative arc for an introductory lecture. Framing the evolution of LLMs as a transition from the rigid, rules-based world of Good Old-Fashioned AI (GOFAI) to the fluid, pattern-matching world of deep learning gives students the perfect historical and technical context.
Just a quick, gentle correction on the vector math before you present it: the famous analogy formula is actually $\vec{w}{king} - \vec{w}{man} + \vec{w}{woman} \approx \vec{w}{queen}$, but you have the exact right idea!
| Time (Mins) | Topic | Key Concepts |
|---|---|---|
| 00 - 15 | The Limits of Symbolic AI | GOFAI, syntax vs. semantics, the scaling problem. |
| 15 - 30 | The Deep Learning Revolution | Connectionism, massive text associations, learning without explicit rules. |
| 30 - 60 | Embeddings & Vector Spaces | 3Blue1Brown visual concepts, high-dimensional arrays. |
| 60 - 80 | Semantic Mathematics | Vector arithmetic, how meaning is encoded in distance. |
| 80 - 120 | Python Practical Session | Hands-on with word vectors using Gensim. |
Context is Everything: Explain the foundational linguistic theory by J.R. Firth: “You shall know a word by the company it keeps.” Deep learning models look at a word and learn its meaning based on the words that frequently surround it.
Bag of words model: how that fails to capture context.
Concept 🧩 🚀 Context is everything! Bag of words model cannot capture context
Enter LLMs
transformers model long-range dependencies in text
Formula: $\vec{w}{king} - \vec{w}{man} + \vec{w}{woman} \approx \vec{w}{queen}$
For the practical, we will use gensim, a robust Python library for topic modeling and document similarity, to download a pre-trained set of GloVe (Global Vectors for Word Representation) embeddings.
Prerequisites: Have your students install the library by running
pip install gensimin their terminal or Jupyter Notebook.
import gensim.downloader as api
print("Downloading/Loading the word vector model... (This may take a minute or two)")
# We use a relatively small 50-dimensional model for speed in a classroom setting
model = api.load("glove-wiki-gigaword-50")
print("Model loaded successfully!\n")
# --- EXPERIMENT 1: Finding Similar Words ---
print("--- Experiment 1: Nearest Neighbors ---")
word = "computer"
print(f"Words most similar to '{word}':")
for similar_word, similarity_score in model.most_similar(word, topn=5):
# Formatting the score to 2 decimal places using standard Python formatting
print(f"- {similar_word} (Score: {similarity_score:.2f})")
print("\n")
# --- EXPERIMENT 2: Semantic Mathematics ---
# King - Man + Woman = ?
print("--- Experiment 2: Vector Arithmetic ---")
print("Equation: King - Man + Woman = ?")
# In Gensim, positive=[additions], negative=[subtractions]
result = model.most_similar(positive=['king', 'woman'], negative=['man'], topn=1)
print(f"Result: {result[0][0]} (Confidence: {result[0][1]:.2f})\n")
# --- EXPERIMENT 3: The Odd One Out ---
print("--- Experiment 3: Finding the Outlier ---")
word_list = ["breakfast", "cereal", "dinner", "lunch", "car"]
print(f"List: {word_list}")
outlier = model.doesnt_match(word_list)
print(f"The model thinks the odd one out is: '{outlier}'")
doctor - human + dog = vet). Warn them that it doesn’t always work perfectly, which opens up a great discussion on the biases and limitations of training data!A language model assigns a probability to a sequence of tokens (words, subwords, characters):
P(w_1, w_2, ..., w_n)
Equivalently, using the chain rule:
P(w_1, ..., w_n) = P(w_1) * P(w_2 | w_1) * P(w_3 | w_1, w_2) * ...
This is the autoregressive view: each token is predicted given all previous tokens.
| n-gram models: estimate P(w_t | w_{t-n+1}, …, w_{t-1}) using counts. |
| Year | Model | Organisation | Parameters |
|---|---|---|---|
| 2018 | GPT-1 | OpenAI | 117M |
| 2018 | BERT | 340M | |
| 2019 | GPT-2 | OpenAI | 1.5B |
| 2020 | GPT-3 | OpenAI | 175B |
| 2022 | ChatGPT / InstructGPT | OpenAI | ~175B |
| 2023 | LLaMA-2 | Meta | 7B–70B |
| 2024 | Llama-3, Mistral, Gemini, Claude | Meta/Mistral/Google/Anthropic | 7B–1T+ |
The core recipe: pre-train on massive text corpora (self-supervised), then fine-tune or prompt for downstream tasks.
Words that appear in similar contexts tend to have similar meanings. (Harris, 1954; Firth, 1957)
Training on next-token prediction forces the model to learn:
At sufficient scale, LLMs develop emergent abilities not present in smaller models:
Wei et al. (2022) document many such emergent abilities as a function of model size.
One of the most surprising properties: LLMs can perform new tasks just from examples in the prompt, without updating weights. This is called in-context learning (ICL).
Design decisions
Loss function
Optimizer
Initialization scale
Learning rate schedule
Regularization
Batch size
Assignment: BPE encoding and create model while doing Resource accounting
DGX B200
Operator fusion, flash attention
Minimize data movement principle
Shard memory: split data o split models, layers, sequences, etc.
| Domain | Example Application |
|---|---|
| Text generation | Creative writing, summarisation |
| Code | GitHub Copilot, code review |
| Q&A / search | RAG-based assistants |
| Healthcare | Clinical note summarisation, diagnostic support |
| Science | Hypothesis generation, literature review |
| Education | Tutoring, automated feedback |
| Agents | Web browsing, task automation |
(We cover this in depth in Weeks 4–5; here is a high-level sketch.)
Input tokens
│
▼
[Token Embedding + Positional Encoding]
│
▼
[Transformer Block × N]
┌──────────────────────────────────┐
│ Multi-Head Self-Attention │
│ + Add & Norm │
│ Feed-Forward Network │
│ + Add & Norm │
└──────────────────────────────────┘
│
▼
[Linear + Softmax → Probability over vocabulary]
See practicals/week01_practical.py: