Please enable JavaScript to use CodeHS

Are LLMs Smarter Than a 5th Grader? — Advanced

Advanced: What is a large language model?

A large language model (LLM) is a neural network trained to predict the next token in a sequence of text. Billions of parameters and trillions of tokens give it an uncanny ability to mimic language, reasoning, and style — but it is still, at its core, a statistical pattern matcher.

LLMs ~12 min Upper High School
The Big Idea

Text to tokens

LLMs do not read words the way humans do. They read tokens: small pieces of text that can be whole words, prefixes, suffixes, or punctuation. Tokenization turns raw text into a sequence of integers the model can process.

Modern tokenizers use subword algorithms like Byte Pair Encoding (BPE). Common words get their own token; rare words are split into smaller units. This keeps the vocabulary manageable while allowing the model to represent any word.

Key idea: tokenization is the interface between human text and machine math. The choice of tokens affects how the model learns and what it can represent.


CS Minute

Embeddings and vectors

After tokenization, each token is converted into a long list of numbers called an embedding. The embedding captures meaning in a geometric sense: tokens with similar usage end up with similar vectors.

These vectors are not random. They are learned during training so that the model can use them to predict the next token. The embedding space becomes a map of language: synonyms cluster, opposites separate, and relationships between words appear as directions in space.


How It Works

Next-token prediction

At the center of an LLM is a simple-sounding task: given a sequence of tokens, predict the most likely next one. During training, the model sees text like "The cat sat on the ___" and learns to assign high probability to "mat."

Because the task is simple, the training data can be enormous: web pages, books, code, articles. Scale is what makes LLMs powerful. The same objective — predict the next token — produces models that can summarize, translate, answer questions, and even write code, because all of these can be framed as text completion.


Critical Thinking

It is not a database

LLMs do not store facts like a database. They store weights that encode patterns in language. Sometimes the pattern matches reality, and the output is true. Sometimes the pattern is plausible but false. This is called a hallucination.

LLMs are also not search engines. A search engine retrieves existing documents. An LLM generates new text based on patterns. If you need exact, up-to-date facts, combine an LLM with a search tool or a database.

Important: an LLM's goal is to produce plausible text, not to verify truth. Always check claims that matter.


Interactive

Tokenize a sentence

Type a sentence below. The demo uses a simple tokenizer for illustration. Real LLMs use subword tokenizers that can split words like "unhappiness" into "un", "happiness", or smaller pieces.

Tokens: —


Code

Next-token probabilities

An LLM turns a vocabulary of words into vectors, then scores each possible next word. This Python example uses embeddings and softmax to pick the next token.


Your Turn

Check yourself

Why might an LLM confidently give a wrong answer to a factual question?

Your answer:

Sample answer: LLMs generate text that is statistically plausible. They are not databases or truth-checkers. If the training data contains a common misconception, or if the prompt is misleading, the model may produce a confident but false answer.


Check Yourself

Quick quiz

1. What is the main training objective of an LLM?

2. What is an embedding?

3. Why is an LLM not a reliable database?

Keep learning

You now know what an LLM is at a high level. Next, learn how it turns a prompt into an answer.

Part of the advanced remake of the “Are LLMs Smarter Than a 5th Grader?” series.