Please enable JavaScript to use CodeHS

LLM Tutorial

What is a large language model?

A large language model, or LLM, is an AI that has read huge amounts of text. It learns patterns in language so it can finish sentences, answer questions, and even write stories.

AI ~10 min Beginner friendly
The Big Idea

What is a large language model?

A large language model, or LLM, is a type of AI that works with words. It reads enormous amounts of text — books, websites, articles, conversations — and learns the patterns of language.

After training, the model can take a prompt like “Write a poem about a robot” and generate words that fit the pattern. It does not truly understand poetry, but it is very good at guessing what words usually come next.

Remember: an LLM is a pattern machine for language. It predicts what words are likely to come next, based on everything it has read.


Tokens

Tokens: the building blocks

Before an LLM can read or write, it breaks text into small pieces called tokens. A token can be a whole word, part of a word, or even a single punctuation mark.

For example, the sentence “Cats are great!” might become four tokens: “Cats”, “ are”, “ great”, and “!”.

Type a sentence and see it split into tokens

Tokens
0 tokens

Modern LLMs do not always split text exactly at word boundaries. They often chop rare words into smaller pieces. For example, “unhappiness” might become “un” + “happiness.” That lets the model reuse pieces it has seen before.


Training

Reading the internet

LLMs are trained on billions of tokens. The training data includes books, web pages, code, and more. The model looks at a sentence, hides one word, and tries to guess what it should be.

Each book represents millions of pages the model reads during training.

It does this over and over, adjusting itself when it guesses wrong. After seeing enough text, it gets very good at predicting the next token. That is why it can write sentences that sound human.

Watch out: because LLMs learn from the internet, they also pick up mistakes, biases, and outdated information. They are not a perfect source of truth.


Interactive

Predict the next word

LLMs are basically very good at fill-in-the-blank. Try the prompts below and guess which word the model would pick. Remember: it chooses the most likely next token, not the “best” answer.

The capital of France is ___.

Code

A tiny next-word model

An LLM is just a very fancy next-word predictor. This Python program counts how often each word follows another word in a tiny corpus and uses those counts to predict the next word.


Your Turn

Check yourself

Explain why an LLM might say something that sounds right but is actually wrong. Use the idea of “patterns from text” in your answer.

Sample answer: An LLM guesses the next word based on patterns, not facts. If lots of text says “the moon is made of cheese” as a joke, the model might repeat it because the words fit a common pattern.


Check Yourself

Quick quiz

1. What is a token?

2. How do LLMs learn to write?

3. Which of these is a big risk of LLMs?

Keep learning about AI

Now you know what an LLM is and how it turns text into tokens. Next, see how it turns a prompt into a full answer, one token at a time.

Part of the “Are LLMs smarter than a 5th grader?” tutorial series.