teaching_llm_applications

Week 1 — Introduction and History of Large Language Models

Lecture Overview

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!


2-Hour Lecture Timeline

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.

Detailed Lesson Plan

Part 1: The Limits of Symbolic AI (15 Mins)

Part 2: The Deep Learning Revolution (15 Mins)

Part 3: Embeddings & Shared Vector Spaces (30 Mins)

Part 4: Semantic Mathematics (20 Mins)


Python Practical: Exploring Vector Spaces (40 Mins)

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 gensim in their terminal or Jupyter Notebook.

🎮 🛠️ Practical: The Code

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}'")

How to Guide the Practical

  1. Run the Basics: Have students run the script exactly as written so they can see the magic happen instantly.
  2. Experimentation: Encourage them to change the words in Experiment 1. Have them look up slang or complex verbs to see how the model groups them.
  3. Break the Math: Have them try to come up with their own semantic equations in Experiment 2 (e.g., 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!

1. What Is a Language Model?

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.


2. A Brief History

2.1 Statistical Language Models (1990s–2000s)

2.2 Neural Language Models (2003–2012)

2.3 The Attention Revolution (2014–2017)

2.4 The Pre-training Era (2018–present)

Year Model Organisation Parameters
2018 GPT-1 OpenAI 117M
2018 BERT Google 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.


3. Why Do LLMs Work?

3.1 The Distributional Hypothesis

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:

3.2 Emergent Abilities

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.

3.3 In-Context Learning

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).


Intro

4. Common Applications

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

5. Key Concepts to Remember


6. The Transformer at a Glance

(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]

7. Practical This Week

See practicals/week01_practical.py:


8. Further Reading


Discussion Questions

  1. What are the limitations of n-gram models that motivated neural language models?
  2. What does “emergent” mean in the context of LLMs, and why is it surprising?
  3. Give two examples of tasks you might want to apply an LLM to in your own research domain.