Learn AI · Foundations
What is an LLM?
Large Language Models, explained from first principles — what they are, how they predict tokens, and where the magic and limits come from.
Key takeaways
- 1LLMs predict the next token, not the next 'word' — tokens are sub-word pieces of text.
- 2Every output is sampled from a probability distribution; temperature controls how 'creative' the sampling is.
- 3Context window = how many tokens of input + output the model can attend to at once.
- 4LLMs don't 'know facts' — they compress patterns from their training data and reproduce them.
- 5Hallucination isn't a bug — it's the same generation process producing plausible but wrong tokens.
The one-sentence version
A Large Language Model (LLM) is a neural network trained to predict the next token in a sequence of text — and that single capability, scaled up, turns out to be powerful enough to write code, summarize PDFs, and answer questions.
Tokens, not words
LLMs don't read words. They read tokens — short fragments of text. The word "unbelievable" might be split into three tokens like ["un", "believ", "able"]. Tokens are the unit of input and output.
When you send a prompt, the model:
- Splits your text into tokens.
- Runs those tokens through a stack of transformer layers.
- Outputs a probability distribution over every possible next token.
- Samples one token from that distribution and adds it to the output.
- Repeats until it hits a stop signal.
That loop — token in, token out — is the entire trick.
Why it works
The model is trained on trillions of tokens scraped from the public internet, books, and code. To predict the next token well, it has to learn:
- Grammar (so the sentence sounds right)
- Facts (so the content is plausible)
- Reasoning patterns (so the logic holds up)
- Style (so the tone matches)
It's not memorizing — it's compressing patterns. The same model that completes "The capital of France is" with "Paris" also completes "def quicksort(arr):" with a working implementation.
Context windows
The number of tokens an LLM can consider at once is its context window. Modern models range from 8K tokens (older GPT-3.5) to 1M+ tokens (Claude, Gemini). Bigger windows mean you can fit more of a codebase, a book, or a transcript into a single prompt.
One nuance: bigger context isn't free. Quality of recall often degrades past ~100K tokens. For long documents, retrieval (RAG) often beats stuffing everything into context.
Temperature, top-p, and sampling
Generation isn't deterministic. After the model produces a probability distribution over the next token, it samples one. The shape of the sampling is controlled by:
- Temperature — higher = more random. 0 = always pick the highest-probability token.
- Top-p (nucleus) — only sample from the smallest set of tokens whose cumulative probability passes p.
- Top-k — only sample from the top k candidates.
For coding and factual tasks, lower temperature (0–0.3). For brainstorming and creative work, higher (0.7–1.0).
What LLMs are bad at
- Math beyond rough estimates — they predict tokens, they don't calculate. Even modern reasoning models lean on tools for serious math.
- Knowing what they don't know — they will confidently hallucinate.
- Anything past their training cutoff unless you give them tools or retrieval.
- Counting — try asking "how many R's are in 'strawberry'" on a model with no tool use.
What's next
LLMs alone are useful, but the real leverage comes when you combine them with retrieval (RAG), tools (function calling), and memory. Those layers are what turn a clever autocomplete into an actual assistant.
Common misconceptions
The wrong-but-common takes worth correcting.
Myth
LLMs understand language the way humans do.
Reality
They model statistical patterns over tokens. The behavior looks like understanding because the patterns are deep — but the underlying mechanism is prediction, not comprehension.
Myth
Bigger models are always better.
Reality
Quality scales with parameters until task-specific data, training, and architecture matter more. A 70B model fine-tuned on coding can beat a generic 400B on code tasks.
Myth
An LLM can answer anything if you prompt it right.
Reality
It can only answer from what's encoded in its weights or what you give it in context. For private data, you need retrieval (RAG). For current events, you need tools.
Real-world use cases
Chat assistants
The most familiar surface — Claude, ChatGPT, Gemini all expose the LLM as a conversational interface with memory and tool use.
Code generation and editing
LLMs are now mainstream developer tools — Cursor, Claude Code, GitHub Copilot all wrap an LLM with code-aware context.
Open
Document understanding
Throw a contract, paper, or codebase at a long-context LLM and ask questions — no specialized model required.
Agent loops
Give the LLM tools and let it iterate — research, automation, multi-step tasks.
Open
Frequently asked questions
Watch
Hand-picked videos from official + trusted channels. Opens in a new tab.
- Andrej Karpathy1 hr
Intro to Large Language Models
The single best one-hour intro to how LLMs actually work, from a co-founder of OpenAI.
- Andrej Karpathy3 hr 31 min
Deep Dive into LLMs like ChatGPT
Long-form, deeper dive — pre-training, RLHF, hallucinations. Take notes.
- 3Blue1Brown27 min
But what is a GPT?
Beautifully animated explanation of how transformers process tokens. Visual-learner gold.
Related on AIKnowHub
Concept
AI Agents Explained
Agents are LLMs that can take actions in a loop. Here's what that actually means, where they shine, and where they fall over.
Concept
Prompt Engineering Basics
The actual techniques that move the needle — role priming, structured output, few-shot examples, and why specificity always wins.
Concept
RAG Explained
Retrieval-Augmented Generation is how you give LLMs access to your own data without retraining them. Here's how it actually works.
Tool Guide
Claude Code Guide
The definitive guide to Anthropic's terminal-native AI coding agent — install, configure, MCP, hooks, skills, sub-agents, plan mode, cost, security, limitations.
Comparison
GPT vs Claude vs Gemini
An honest head-to-head of the three frontier models — where each one wins, where each one loses, and what to pick.
Directory
Claude Code
Terminal-native agent that reads, writes, runs, and reviews your codebase.