LLMs from 30,000 feet

Sign in to save progress
0:00
0:00
The discussion is for premium members.Go premium
  • Be the first to say something about this lesson.

Prefer reading? Every lesson in this course as text

Read this lesson as text: How words become numbers

How words become numbers

How does turning words into numbers work? Let's try to understand. In a simple way. Here is the thing.

A language model is pure math. Millions of multiplications. And math can only run on numbers. So the word cat, as letters, is useless to it.

Step one is quick. The text gets chopped into pieces called tokens, and each piece gets an ID from a fixed list. Cat might be number four thousand. But an ID is just a label.

If dog is nine thousand, that tells the model nothing about dogs. Four thousand and nine thousand are not related at all. So step two. Each ID gets swapped for a long list of numbers, a vector.

This is called an embedding. Hundreds of numbers, all describing one token. Now, treat those numbers as coordinates. Every token becomes a point in a giant space.

And here is the magic. Tokens with similar meanings sit close together. So cat lands near dog, and near kitten. Carburetor sits far away.

Distance in this space is basically a measure of meaning. Even directions mean something. Take the classic example. Start at king, subtract man, add woman.

You land right next to queen. Meaning has become geometry. And who chooses these numbers? Nobody.

They start random, and get adjusted during training. Words that keep appearing in similar contexts slowly drift together. So, chop text into tokens, give each an ID, then swap the ID for an embedding vector. That vector is where meaning lives.

Quick check now. One question is coming up. Let's see if it clicked.

Read this lesson as text: How words look at each other

How words look at each other

What exactly is attention? Let's try to understand. In a simple way. Take the word bank.

River bank, one meaning. Bank account, another. Same word, different job. So a word alone is not enough.

Its neighbors decide what it means. Attention is the fix. Every word gets to look at every other word in the sentence, and ask, who here matters for my meaning? Try this.

The trophy did not fit in the suitcase because it was too big. What is it? The trophy. Attention builds that exact link, with numbers.

Each word scores every other word. High score, pay attention. Low score, ignore. Then it pulls in information from the high scorers, and its meaning gets updated.

The mechanism has names. Each word makes a query, what am I looking for. A key, what do I offer. And a value, the information it actually carries.

A query gets compared with every key. Strong matches get big weights. Then the word takes a weighted mix of the values. That mix is its new, context aware meaning.

And this runs many times in parallel. Each attention head tracks a different relationship, grammar, or who did what. Stack layers, and meaning sharpens each pass. This is the heart of the transformer.

All word pairs get compared at once, so long range links are easy, and GPUs can run it fast. So, attention lets every word ask every other word for help. Score, weight, blend. That is how loose words turn into meaning.

Quick check now. One question is coming up. Let's see if it clicked.

Read this lesson as text: What does training actually do?

What does training actually do?

How does training an AI model work? Let's try to understand. In a simple way. An untrained model is just billions of numbers, set at random.

Feed it a sentence, and it babbles pure noise. Those numbers are called parameters. Think of them as knobs. Training is one simple game.

Show the model some real text, hide the next word, and ask it to guess. The cat sat on the... what? At first, it guesses badly.

So we measure the miss. How far was the guess from the real word, mat? That distance has a name. The loss.

Now the key move. Nudge every knob, just a tiny bit, in the direction that shrinks the loss. Next time, mat gets a little more likely. This has real names.

Backpropagation works out which way each knob should move. Gradient descent takes the step. Guess, score, nudge. That's the whole loop.

Now repeat that loop on trillions of words. Books, code, websites. Months of GPU time. Each single nudge is tiny, but the pile of nudges adds up.

Here is the thing. To predict the next word well, the model is forced to absorb grammar, facts, even reasoning patterns. Nobody typed rules in. They emerge from the pressure to predict.

And when training ends, the knobs freeze. When you chat with the model, nothing is learning. It's just running those frozen numbers forward. So, training is guess, score, nudge, repeated trillions of times.

All that knowledge is really one skill, squeezed in. Predicting the next word. Quick check now. One question is coming up.

Let's see if it clicked.

Read this lesson as text: Why the same question gets different answers

Why the same question gets different answers

How does sampling work? Let's try to understand. In a simple way. Ask an AI the same question twice, and you often get two different answers.

Not a bug. It's built in. Let's see why. Under the hood, the model never writes a whole answer at once.

It picks one token at a time. Word by word, roughly. And for each next token, it does not pick one thing. It computes a probability for every token on its menu.

A whole spread of options. Example. After, the sky is, maybe blue gets seventy percent, and clear gets twenty. The model rolls weighted dice and picks one.

That roll is called sampling. Here is the thing. One different pick changes everything after it. The next prediction builds on it, so the answers drift apart, token by token.

You can control the dice. That knob is called temperature. Low temperature sharpens the spread, so likely tokens win. High temperature flattens it, so wilder picks show up.

Set it near zero and the model just takes the top token every time. That's greedy decoding. Same question, basically the same answer. So why keep any randomness?

Because always taking the top pick makes text repetitive and dull. A little chance gives variety, and often better writing. So, the model outputs probabilities, sampling rolls the dice, and temperature sets how wild the roll is. That's the whole story.

Quick check now. One question is coming up. Let's see if it clicked.

Read this lesson as text: Why do models make things up?

Why do models make things up?

What exactly is AI hallucination? Let's try to understand. In a simple way. Ask a model for a paper on a niche topic.

It may hand you a perfect looking citation. Real journal, real sounding authors. And the paper does not exist. Here is the thing.

The model is not looking anything up. It writes by predicting the next likely word, over and over. It is built for plausible, not for true. There is no database of facts inside.

Knowledge lives as fuzzy statistical patterns squeezed into the weights. Some facts got stored cleanly. Many got blurred or lost. So when a fact is missing, the model does not stop.

It fills the gap with whatever sounds most likely. That fake citation? It matches the shape of real citations perfectly. And notice, the tone never changes.

A made up fact reads exactly as smooth as a real one. Fluency is not evidence. Why so confident? Partly training.

On most tests, a guess can score points, while saying I don't know scores zero. So models learn that guessing pays. Researchers call this hallucination. Some prefer confabulation, since the model is not seeing things.

It is filling memory gaps with invented detail, like people sometimes do. The main fix is grounding. Hand the model real documents to quote, a setup called retrieval augmented generation, or RAG. Checking becomes easier than remembering.

So, models make things up because they generate plausible text, and plausible is usually true. Usually. When knowledge runs out, the style keeps going. Quick check now.

One question is coming up. Let's see if it clicked.

Read this lesson as text: What is a context window?

What is a context window?

What exactly is a context window? Let's try to understand. In a simple way. Every model has a working memory.

There is a hard limit on how much text it can hold in view at once. That limit is the context window. The window is counted in tokens, those small pieces of text. A window of two hundred thousand tokens fits roughly a full novel.

Sounds huge, right? Here is the thing. Everything shares that one budget. Your question, the system instructions, the whole chat history, any pasted files, and even the answer being written.

So what happens when a long chat fills the window? The oldest messages get cut. That text is simply gone from view. That is why, deep into a conversation, it forgets your name.

The message where you said it slid out of the window. It never saw it again. Why not make it infinite? Cost.

Inside the model, every token compares itself with every other token. Double the window, and that work roughly quadruples. And the window is not memory. Close the chat, and it is empty again.

Nothing you said got saved into the model. It reads, it never records. One more catch. Even inside the window, recall is uneven.

Models read the start and the end of a long input better than the middle. The lost in the middle problem. So, the context window is the model's field of view, counted in tokens. Everything competes for it, and whatever falls outside might as well not exist.

Quick check now. One question is coming up. Let's see if it clicked.