Tokens, embeddings, attention, training, RAG and agents, each built in a few lines of plain Python so you can watch every number. No libraries, no black boxes.
AI · beginner · 20 lessons · 2 h 51 min · free
What you'll learn
See text turn into tokens and meaning turn into vectors
Follow a word through attention, heads and a whole transformer block
Watch a model be trained, tuned with human feedback, and sampled
Build prompts, tool calls, RAG, agents and evals, and defend against prompt injection
Before you start
Basic Python: lists, loops and functions
Helpful: the Machine Learning from Scratch course
Lessons
Text as Numbers
How words become something a model can calculate with.
Tokens: Turning Text into Numbers: Language models only work with numbers. Watch a sentence become a list of token ids, and see what happens to a word the model has never seen.
Byte-Pair Encoding: Learning Word Pieces: Real tokenizers are learned, not written by hand. Start from single letters and keep merging the most common pair, and useful pieces like "low" appear by themselves.
Embeddings: Meaning as Numbers: Give every word a vector, and words with similar meanings end up pointing the same way. Find the word closest to "kitten" with cosine similarity.
Positional Encoding: Where Is Each Word?: Attention looks at all the words at once, so on its own it cannot tell "dog bites man" from "man bites dog". Adding a position signal to each word fixes that.
Inside a Language Model
Predicting the next word, choosing it, and using context.
Predicting the Next Word: A language model guesses the next word, again and again. Build a tiny one by counting which word follows which, then let it write a sentence.
Softmax and Temperature: Turn a model's scores into chances with softmax, then turn the temperature down and up to watch its answers become surer or more adventurous.
Top-k and Top-p: Choosing Safely at Random: Picking the next word at random makes text lively, but should never pick nonsense. Top-k and top-p cut off the unlikely tail before rolling the dice.
Attention: Words Looking at Words: "Bank" means something different next to "river" than next to "money". Attention lets each word look at the others and borrow meaning from the ones that matter.
Multi-Head Attention: Asking Several Questions: One attention head can only look for one thing. Give "chased" two heads, and one finds who did the chasing while the other finds who was chased.
The Transformer Block: A transformer is the same block stacked many times: attention adds context, a normalising step keeps numbers steady, and a small network works on each word. Follow "bank" through one block.
The Context Window: Why Models Forget: A model reads only a fixed number of tokens at once. As a chat grows, the oldest words fall out of the window, and the model can no longer see them.
Training a Language Model
From predicting text to being a helpful assistant.
How a Language Model Is Trained: Show the model the real next word, measure how surprised it was (the loss), and nudge its scores. Repeat this billions of times and you have a language model.
Fine-Tuning and RLHF: Learning to Be Helpful: A pre-trained model only continues text. To make an assistant, people compare answers and a reward model learns what they prefer. That reward then steers the chat model.
Building with Models
Prompts, tools, facts and checks: making models useful and safe.
Prompting: Shaping the Answer: A prompt is just text, but its shape matters: an instruction, a few worked examples, and an ending that invites exactly the answer you want.
Tool Calling: Models Asking for Functions: The model never runs code. It writes a request in JSON: which tool, which arguments. Your program reads it, runs the function, and sends back the result.
RAG: Look It Up, Then Answer: A model only knows what it was trained on. Retrieval-augmented generation finds the right document first and puts it in the prompt.
Agents: A Model in a Loop: An agent lets a model use tools. The model picks an action, the program runs it, the result goes back to the model, and the loop repeats until it answers.
Evaluation: Is the Model Any Good?: You cannot improve what you do not measure. Ask the model questions with known answers, compare fairly, and count.
Prompt Injection: When Data Gives Orders: Text your app reads (web pages, emails, files) can contain instructions aimed at the model. See why it is dangerous and the basic defences.
Related courses
Machine Learning from Scratch: How machines learn from data, built from plain Python on tiny datasets so you can watch every number change. No libraries, no black boxes. (13 lessons, 2 h 25 min)
AI Agents and RAG: Build Them Step by Step: How retrieval-augmented generation and AI agents really work, built from small Python programs: embeddings, chunking, vector search, grounded answers, the agent loop, memory, planning, multi-agent routing, guardrails and MCP. Watch every score, tool call and decision as it happens. (16 lessons, 1 h 50 min)
AI Beyond Language Models: Search, game playing, learning from rewards, image generation, recommendations, forecasting and sound, each in a few lines of plain Python you can step through. (7 lessons, 58 min)