Tutelage

Lessons › coding and computer science · taught by Leo

How large language models work

Learn how LLMs predict the next token, learn patterns from text, and generate fluent responses while still making mistakes.

Learn this with Leo, freeA voiced lesson with a live whiteboard, quizzes and a tutor you can call, at tutelage.app

What a language model does

Think of a large language model as a super fast guesser for text. It reads what is already there and predicts what should come next.

It does not copy from a rule book word by word. It learns patterns from lots of examples.

Those patterns let it suggest words, sentences, code, and answers.

Big idea: pattern prediction

A language model is trained to predict the next token, which is a piece of text like a word or part of a word.

The key job is next-token prediction.

If it gets very good at that job, it starts to look smart at many language tasks.

That is because language itself has patterns, structure, and context.

Predict: what comes next?

In a sentence, the model mainly tries to predict the next...

  1. token
  2. printer
  3. database
Show answer

token: Yes. Token is the right idea. The model looks at the text so far and guesses the next piece.

Training on huge text examples

During training, the model sees a huge amount of text.

It guesses the next token, then checks how wrong it was.

Then it adjusts its internal numbers, called weights.

Over and over, it gets better at the pattern.

next token

How the answer is built

Here is the basic loop. Read the context, score options, pick one, and repeat.

This is why the model can make long responses. It keeps extending the text one token at a time.

The board shows the whole process as a chain.

Quick check: what gets adjusted?

After the model makes a mistake during training, what gets changed?

  1. Its internal weights
  2. The user’s sentence
  3. The keyboard layout
Show answer

Its internal weights: Right. The weights get updated. That is how learning happens.

Why it sounds fluent

It sounds fluent because it has learned statistical patterns from many examples, including grammar, style, and common phrasing.

The model is not matching one fixed script.

It is using patterns it learned from lots of text.

That is why it can sound natural, even when the topic changes.

Why it can be wrong

Here is the catch. Being good at language does not automatically mean being always correct.

It can produce something that sounds right but is not true. That is called a hallucination.

So you still want to check important facts.

Quick check: why do errors happen?

Why can a language model sometimes sound confident but be wrong?

  1. It predicts likely text, not truth
  2. It only reads one book
  3. It refuses to learn
Show answer

It predicts likely text, not truth: Exactly. It is optimized for likely next text, not for guaranteed truth.

Key idea: tokens plus context

Here are the four words to remember: tokens, context, weights, and output.

Tokens are the pieces. Context is the text so far. Weights are what it learned.

Output is the next-token guess built from all of that.

Watch out: not a human brain

Common mistake: treating it like a person who understands everything like a human does.

It is a pattern machine, not a conscious mind.

That is why it can be brilliant in one moment and shaky in another.

Your turn: best description

Which description fits a large language model best?

  1. A system that predicts likely text from context
  2. A search engine that stores every answer
  3. A human mind inside a computer
Show answer

A system that predicts likely text from context: Nice. That is the best description.

Recap: the 3-step flow

Use this checklist on your own. First, it reads context.

Second, it predicts the next token.

Third, it repeats, and you should still check important facts.

Learn this with Leo, freeA voiced lesson with a live whiteboard, quizzes and a tutor you can call, at tutelage.app