AYUMAD/AI ~/ai/what-is-an-llm 74 notes/

What is an LLM?

status evergreenupdated 2026-09-09tags ai-engineering, models, llm

[!summary] The gist An LLM is autocomplete at scale. It predicts the next word based on patterns from training data. It doesn't look things up or take actions—those are engineering problems solved around the model. This note covers tokenization, embeddings, model families, and what isn't built in.


Mental model

context → model inference → candidate continuation → decoding

Tokens are not identical to words. Tokenization affects context length, cost, and how identifiers or code are represented. Decoding chooses an output from probabilities; temperature, top-p, seed behavior, and model-specific controls affect variability.

Tokenization

Tokenization converts raw text into the integer sequences models actually process. The choice of tokenizer determines context length, cost, and how well code, rare words, and multilingual text are handled.

BPE (Byte Pair Encoding): Merges the most frequent byte pairs iteratively (Sennrich 2016). Handles rare and unknown words via subword decomposition. +1.1–1.3 BLEU over dictionary baselines on WMT 15.

WordPiece: Used in BERT (Google). Longest-match-first strategy with a trie. Fast WordPiece achieves O(n) tokenization via Aho-Corasick—8.2× faster than HuggingFace Tokenizers (Wu et al. 2021).

SentencePiece: Language-independent tokenizer (Kudo & Richardson 2018). Trains directly from raw sentences without pre-tokenization. Implements BPE + Unigram LM. Used by T5, Llama, and Gemma.

Why tokenization matters for cost and context: APIs charge per token. English averages 0.75 words per token (4 characters). CJK languages average ~1 token per character (2–3× more expensive for the same content). Code, agglutinative languages, and URLs also tokenize poorly. A 128K-token context window ≈ 96K English words but ≈ 40K CJK characters. Petrov et al. (NeurIPS 2023) showed tokenized lengths differ by >10× between best- and worst-served languages for the same content.

Embeddings

After tokenization, each token (or sequence) is mapped to a dense vector—an embedding—that captures semantic and syntactic relationships.

Static embeddings (Word2Vec, GloVe): One fixed vector per word regardless of context. Word2Vec (Mikolov 2013) learns from local co-occurrence via skip-gram or CBOW. GloVe (Pennington 2014) factorizes log co-occurrence matrices. Dimensions: 100–300. Fast and interpretable, but cannot distinguish polysemous uses (e.g., "bank" as riverbank vs. financial institution).

Contextual embeddings (ELMo, BERT, GPT): Representation varies by sentence. ELMo (Peters 2018) extracts deep bidirectional LM internals; upper layers become more context-specific (Ethayarajh 2019). Transformer hidden dimensions range from 768 (BERT-base) to 12,288 (GPT-4 class). Retrieval-specific embeddings: OpenAI ada-002 uses 3,072 dimensions; BGE uses 1,024.

Cosine similarity measures the angle between two vectors: 1 = identical direction, 0 = orthogonal, −1 = opposite. It is the primary metric for retrieval and nearest-neighbor search. Inner product and L2 distance are alternatives with different geometric interpretations.

Trade-off: Static embeddings are fast and cheap but ignore context. Contextual embeddings capture polysemy and nuance but require the full model forward pass.

Model families snapshot

The landscape as of 2026-08-27:

Family Provider Key models Approx. params Strengths Access
GPT OpenAI GPT-4o, GPT-4.1 ~1.8T MoE (rumored) Broad reasoning, multimodal Closed API
Claude Anthropic Claude 4 Opus, Sonnet Undisclosed Constitutional AI alignment, 100K+ context Closed API
Llama Meta Llama 4 Scout/Maverick 8B–405B Open weights, commercial license, 128K context Open
Gemini Google Gemini 2.5 Pro Undisclosed Multimodal native, 1M+ context API
DeepSeek DeepSeek V3 (671B/37B active), R1 671B MoE Extremely cost-efficient training, open weights Open
Mistral Mistral AI Mixtral 8x7B 47B/13B active Efficiency-focused, strong small models, Apache 2.0 Open

Parameter counts are approximate; MoE models store more parameters than they activate per token (see Local AI Hardware and Inference).

Evaluation benchmarks

Common benchmarks and why single numbers mislead:

Benchmark What it tests Status (2026)
MMLU (57 subjects, multiple-choice) Broad knowledge Saturated (>90% by frontier)
MMLU-Pro (10 choices, reasoning-focused) Harder reasoning, less trivia Better discriminator; drops accuracy 16–33% vs MMLU
GSM8K (grade school math) Multi-step reasoning Largely saturated (>95%)
HumanEval (164 Python problems) Code generation with unit tests Saturated (>95%); spawned SWE-bench
Chatbot Arena (LMSYS) Crowdsourced pairwise preference, Elo rating Most referenced live leaderboard; rankings shift by task type

Why single numbers mislead: (a) Saturation—top models cluster near ceiling. (b) Prompt sensitivity—same model scores vary 4–5% across formats. (c) No single benchmark covers all capabilities. (d) Contamination—training data may contain benchmark questions. (e) Arena shows rankings shift by task type.

What is not built in

An LLM does not automatically possess current web access, private files, durable memory, a todo list, authentication, safe execution, or a goal that persists after the request. Engineers add these around the model through a Agent Harness.

Useful distinctions

Thing Primary responsibility
Model Pattern completion and reasoning from supplied context
Application User experience and domain logic
Agent Model-directed loop that can choose actions
Workflow Explicit sequence and control flow
Harness Runtime that gives an agent context, tools, state, and guardrails

How to use this mental model

When a system fails, locate the missing layer before changing the model. A wrong current fact suggests retrieval; an invalid JSON field suggests a schema/validator; an action the model cannot take suggests a tool; repeated unsafe behavior suggests a harness policy. This prevents the common mistake of trying to solve every problem with a longer prompt or a larger model.

Build a small exercise around one request: record the exact input context, model output distribution/decoding settings where available, validator result, and final user-facing answer. Change one variable at a time. You will quickly see that the system surrounding inference controls much of real-world reliability.

Common misconceptions

  • Fluent output is not evidence of current knowledge, authorization, or tool completion.
  • A context window is not durable memory; it is a limited working set that must be selected and managed.
  • Reasoning capability does not confer safe execution. Authority comes from the application and its policies.

How a model is built and why that matters

Karpathy's "two-file" mental model: an LLM is parameters (the learned weights) plus the code that runs them. Everything a model "knows" was selected during training—so a capability gap is usually a training fact, not a prompt bug.

  • Pretraining: predict the next token over web-scale text. This yields broad language and world knowledge but no instruction-following. Loss falls as a power law with model size, data, and compute (Kaplan et al. 2020), and compute-optimal training shifts the balance toward more data per parameter (Hoffmann et al. 2022, "Chinchilla").
  • Post-training: supervised fine-tuning shapes output format, and preference/RL alignment tunes behavior against human judgments. Alignment changes behavior; it is not a security boundary (see Security and Jailbreaking).
  • Architecture: the transformer's attention mechanism (Vaswani et al. 2017) lets every token attend to every other token; most chat models are autoregressive decoder-only transformers that emit one token at a time. Mixture-of-experts models store more parameters than they activate per token (see Local AI Hardware and Inference). Chain-of-thought-style reasoning emerges at sufficient scale (Wei et al. 2022; see Prompting for Agents).

Scaling laws: practical implications

Kaplan et al. (2020) showed loss falls as a power law with model size, dataset size, and compute. The key practical implication: doubling parameters without proportionally more data yields diminishing returns. Chinchilla (Hoffmann et al. 2022) showed compute-optimal training shifts the balance toward more tokens per parameter—many "large" models were actually undertrained. This means a well-trained 70B model can outperform a poorly-trained 200B model. For practitioners, scaling laws predict the minimum data and compute needed for a target performance level, and they explain why simply making a model bigger without more data rarely helps.

Sources and further reading

All links verified 2026-08-27.

Related

Context Windows and Inference · Structured Outputs and Tool Calling · What Is an Agent



← Foundations Hub · Home · Context Windows and Inference →