Level 1 · Complete beginner · 10 min
What an LLM Actually Is
An LLM is a next-word predictor trained on huge amounts of text.
What you will learn
- Explain what a large language model actually does
- Describe next-token prediction in plain terms
- Recognize why LLMs sound fluent but can be wrong
The idea
A large language model (LLM) is a program that has learned, from huge amounts of text, to predict the single most likely next token given everything written so far. That is the entire mechanism. Ask it a question, and under the hood it is repeatedly answering: given this text so far, what token comes next?
Why does this matter?
If you think an LLM looks things up or reasons like a database, you will misuse it: expect facts it never memorized correctly, or trust confident-sounding text that is actually a plausible-sounding guess. Understanding next-token prediction explains both its power and its failure modes.
A real-world analogy
Think of the world's best autocomplete on your phone keyboard, trained on nearly the entire internet instead of your texts. It does not know facts are true — it knows which words tend to follow which other words in similar contexts. Scaled up enough, that turns out to be extremely useful.
See it in code
const bigramCounts = {
"the cat": { "sat": 5, "ran": 2 },
"cat sat": { "on": 7 }
};
function predictNext(context) {
const options = bigramCounts[context];
if (!options) return null;
return Object.entries(options).sort((a, b) => b[1] - a[1])[0][0];
}
console.log(predictNext("the cat")); // "sat"Line by line
const bigramCounts = { ... }A tiny lookup table of how often one phrase is followed by a word — a miniature, hand-made version of what an LLM learns from billions of examples.
function predictNext(context) { ... }Given a context, it picks the word seen most often after that context. Real LLMs do this with far more context and far subtler statistics, one token at a time.
console.log(predictNext("the cat"));Prints the single most likely next word learned from the tiny table — the same basic idea an LLM applies at a massive scale.
What do you think happens?
An LLM answers a factual question wrong but very confidently. What is the most likely underlying reason?
Have a guess before you read on. Guessing wrong is part of learning it.
Try it yourself
Extend the toy predictor: add a new context key and see how predictNext behaves when the context is unseen (returns null). This mirrors how real LLMs behave less reliably on rare or unseen phrasing.
Worth knowing
Common mistake: treating an LLM like a search engine or calculator. It has no guaranteed access to true facts or live data unless you explicitly give it that data (see the retrieval lesson later in this course).
The proper words for it
- LLM (Large Language Model)
- A model trained to predict the next token in text, at massive scale.
- Token
- A chunk of text (often a word piece) the model reads and generates one at a time.
- Hallucination
- When a model generates fluent, confident text that is factually wrong.
Where you'll meet this
Companies building AI products design around this: they add retrieval (real documents), validation (checking output), and guardrails, because they know the raw model is a next-token predictor, not a truth oracle.
Lesson recap
- An LLM predicts the next token based on patterns learned from huge text data
- It has no built-in fact-checker — fluency is not correctness
- Real systems compensate with retrieval, validation, and careful prompting
Still fuzzy on any of this?
That's normal, and it's not a dead end. Pick a different way to hear it.
Quick check
1. What does an LLM fundamentally do at each generation step?
2. Why can an LLM sound confident while being factually wrong?
3. What is a common technique to reduce hallucination on factual questions?
Pick the Most Likely Next Word
Write pickMostLikely(wordCounts) that simulates a tiny next-token predictor. Given an object mapping candidate words to counts (how often each appeared after some context), return the word with the highest count. Break ties alphabetically.