LearnThatStack Ace your next interview
AI Engineering

LLM Fundamentals.

Start free Change topic Change

Practise LLM Fundamentals one question at a time. Answer out loud or in writing, get graded, and see exactly what you missed.

Try one question

What is a large language model, and how does it actually generate text?

The answer

A large language model (LLM) is a neural network trained on huge amounts of text to predict the next token.

The model reads the text so far, scores every vocabulary entry, and samples one token from the resulting probabilities.

tokens = encode(prompt)
while not done(tokens):
    logits = model(tokens)         # one score per vocabulary entry
    probs = softmax(logits[-1])    # next-token probabilities
    tokens.append(sample(probs))   # pick one, feed it back in
print(decode(tokens))

Autoregressive means each output becomes part of the next input.

The weights hold patterns, not a fact database, so fluent text is not proof of correctness.

Example · what grading looks like
What is a token, and why do models work with tokens instead of whole words or characters?

“So a token is the unit the model actually reads and writes. Usually it's a common word or a chunk of a word - 'unbelievable' might come out as 'un', 'believ', 'able' - and the model has a fixed vocabulary of them, something like a hundred thousand. Why not whole words? You'd never have a complete list. New words, names, typos, code identifiers - anything that isn't in the list would just be unknown to the model. Why not single characters, then? That would cover everything, but every sentence gets several times longer, and the model's work grows with sequence length, so you'd burn a lot more context and compute. Subword tokens are the middle ground: common words stay one token, and rare stuff breaks into pieces the model already has.”

Knew it

Correctly explains subword tokenization and why fixed word lists fail (OOV) and characters are too costly. Would be stronger with a concrete note on vocabulary size scaling to cover any input.

Missed: Doesn't mention that the ~100k vocabulary can encode any input by falling back to smaller pieces or bytes


Get your own answers graded

Sign up free. Your account comes with 50 credits for grading, and it remembers what you missed.

What it covers

All 58 questions

Each on its own page

How LLMs and transformers work

Next-token prediction, the transformer block, self-attention and its cost, position encoding, model variants and mixture-of-experts.

7 questions

  1. What is a large language model, and how does it actually generate text?
  2. Describe the transformer architecture at the level an application engineer should understand. Pro
  3. Explain self-attention conceptually. What problem does it solve? Pro
  4. What is the difference between encoder-only, decoder-only, and encoder-decoder transformer models, and where is each used? Pro
  5. Why is attention quadratic in sequence length, and what does that imply for long-context work? Pro
  6. What is a Mixture-of-Experts architecture, and why has it become standard for large models? Pro
  7. How do transformers represent token order, and what are rotary position embeddings (RoPE)? Pro

Tokens and tokenization

What tokens are, how BPE builds a vocabulary, why token counts drive cost and limits, language differences and counting tokens accurately.

5 questions

  1. What is a token, and why do models work with tokens instead of whole words or characters?
  2. Why do token counts matter so much in practice?
  3. How does byte-pair encoding (BPE) tokenization work? Pro
  4. Why does the same content cost different amounts in different languages, and why should engineers care? Pro
  5. How do you count tokens accurately before sending a request, and why not just estimate? Pro

Context windows and caching

What the context window holds, current sizes, quality loss as it fills, measuring effective context and structuring prompts for caching.

5 questions

  1. What is a context window?
  2. What happens to model quality as the context window fills up? Pro
  3. Compare context window sizes across the major 2026 models. What caveats apply? Pro
  4. What is prompt caching, and how do you structure prompts to exploit it? Pro
  5. Advertised context windows keep growing. How do you evaluate what a model can actually use? Pro

Sampling and decoding controls

Temperature, top-p, top-k, stop sequences, why temperature 0 is not deterministic, and other sampling methods and how they fail.

6 questions

  1. What does the temperature parameter control?
  2. How do temperature and top-p interact, and how should you set them in practice? Pro
  3. What is top-k sampling, and how does it compare with top-p? Pro
  4. What are stop sequences, and when would you use them? Pro
  5. Is temperature 0 deterministic? Explain why or why not. Pro
  6. Discuss sampling beyond temperature and top-p: failure modes and current practice. Pro

Training and alignment

Pretraining, scaling laws and perplexity, base versus instruct models, RLHF, DPO, RLAIF and their failure modes, and LoRA fine-tuning.

9 questions

  1. What is the difference between pretraining and post-training?
  2. Explain RLHF at a high level. Why is it needed? Pro
  3. What is the difference between a base model and an instruct or chat model, and when does it matter? Pro
  4. What are scaling laws, and how do they inform model size, data, and compute decisions? Pro
  5. What is LoRA, and how does parameter-efficient fine-tuning compare with full fine-tuning? Pro
  6. What is perplexity, and what does it tell you about a language model? Pro
  7. Compare DPO with PPO-based RLHF for preference tuning. Pro
  8. What are RLAIF and Constitutional AI? Pro
  9. What are the known failure modes of RLHF-style post-training? Pro

Hallucinations and knowledge limits

Why models hallucinate, knowledge cutoffs, causes and mitigations, measuring groundedness in production, and using logprobs as a confidence signal.

6 questions

  1. What is a hallucination, and why do LLMs hallucinate?
  2. What is a knowledge cutoff, and how should it influence how you build with a model? Pro
  3. What practical techniques reduce hallucinations in an LLM application? Pro
  4. Give a taxonomy of hallucination causes and match mitigations to each. Pro
  5. How would you measure and monitor hallucinations in a production LLM system? Pro
  6. Can token log probabilities be used to estimate model confidence, and what are the limits? Pro

Model landscape and multimodality

The 2026 model families, open-weight versus API models, when small models win, and how multimodal models handle images and what they cost.

5 questions

  1. What does it mean for a model to be multimodal? Pro
  2. What does the major model landscape look like in 2026? Pro
  3. What is the difference between open-weight and proprietary API models, and when would you choose each? Pro
  4. When does a small model beat a frontier model? Pro
  5. How do multimodal models process images, and what does that cost in tokens? Pro

Embeddings and retrieval

What embeddings are, how they power semantic search and RAG, choosing an embedding model, and when to pick RAG, long context or fine-tuning.

4 questions

  1. What are embeddings, in simple terms? Pro
  2. How do embeddings power semantic search and RAG? Pro
  3. How do you choose an embedding model in 2026? Pro
  4. When do you choose RAG, long context, or fine-tuning, and how do they combine? Pro

Reasoning models

What reasoning models are and when they help, test-time compute as a scaling axis, controlling thinking effort and trusting the visible chain of thought.

4 questions

  1. What are reasoning models, and when do they actually help? Pro
  2. What is test-time compute, and why did it become a major scaling axis? Pro
  3. How do you control how much a reasoning model thinks, and why does it matter? Pro
  4. How much should you trust a reasoning model's visible chain of thought? Pro

Inference performance and cost

The KV cache and shrinking it with shared key-value heads, quantization, speculative decoding, reducing latency, model routing and cascading, and the economics of high-volume LLM features.

7 questions

  1. What is the KV cache, and why does it dominate LLM inference economics? Pro
  2. What are the tradeoffs when quantizing a self-hosted model? Pro
  3. How would you design model routing or cascading to balance cost and quality? Pro
  4. What techniques reduce LLM inference latency, and which matter most? Pro
  5. Walk through the economics of a high-volume LLM feature and the levers for optimizing cost. Pro
  6. What is speculative decoding, and why doesn't it change the model's output? Pro
  7. What are multi-query and grouped-query attention, and what do they trade away? Pro
Practice · Questions

All questions

Showing of 58
Beginner 12
01

What is a large language model, and how does it actually generate text?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

A large language model (LLM) is a neural network trained on huge amounts of text to predict the next token.

The model reads the text so far, scores every vocabulary entry, and samples one token from the resulting probabilities.

tokens = encode(prompt)
while not done(tokens):
    logits = model(tokens)         # one score per vocabulary entry
    probs = softmax(logits[-1])    # next-token probabilities
    tokens.append(sample(probs))   # pick one, feed it back in
print(decode(tokens))

Autoregressive means each output becomes part of the next input.

The weights hold patterns, not a fact database, so fluent text is not proof of correctness.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is a token, and why do models work with tokens instead of whole words or characters?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A token is the unit of text a model reads and writes: usually a common word or a word piece. Models have a fixed vocabulary of tokens.

import tiktoken
enc = tiktoken.get_encoding("o200k_base")   # OpenAI GPT-4o-family encoding
ids = enc.encode("tokenization is unavoidable")
[enc.decode([i]) for i in ids]
# illustrative split: ['token', 'ization', ' is', ' unavoid', 'able'] -> 5 tokens, 3 words

Whole words fail because new words keep appearing, and any fixed word list would mark them unknown. Characters work, but sequences get much longer, so attention cost grows fast.

Tokens sit in between. A vocabulary of roughly 100k tokens covers any input, because rare words split into known pieces, down to single bytes if needed.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

Why do token counts matter so much in practice?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Tokens are the unit a model bills, limits and produces. So the token count of a request sets its cost, whether it fits, and how long it takes.

  • Cost. Providers charge per token, and output tokens usually cost several times more than input tokens.
  • Fit. The prompt plus the output must fit the context window, or the call errors or gets truncated.
  • Latency. The model produces output tokens one at a time, so time to finish tracks output length.

A small prompt change can double the bill across millions of calls. So trim old chat history, and set a real max_tokens on every request.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What is a context window?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

The context window is the most tokens a model can handle in one request. The window covers the system prompt, the conversation history, and the tokens the model generates.

A 200K window with a 190K prompt leaves about 10K for the reply, so max_tokens must fit that leftover space.

WINDOW = 200_000
prompt_tokens = count_tokens(messages)   # measure it, do not guess
max_tokens = min(4096, WINDOW - prompt_tokens - 500)   # keep a safety margin

Models are stateless and keep nothing between calls, so each request resends the whole history.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What does the temperature parameter control?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

Temperature controls how random the next-token pick is. It divides the logits, the raw scores the model gives each token, before softmax turns them into probabilities.

probs = softmax(logits / temperature)

A low temperature sharpens the distribution, so the top token wins almost every time. A high temperature flattens it, so unlikely tokens get picked more often. Typical settings fall into three bands:

  • 0 to 0.3 is near-greedy and more repeatable. Use it for extraction, classification and code or tool calls.
  • 0.7 to 1.0 is balanced, for chat, drafting and summaries.
  • Above 1.2 is very flat, with a risk of incoherent text. Use it for brainstorming or generating diverse candidates.

At exactly 0, implementations skip the division and pick the top token. Raising temperature to escape a wrong answer usually just yields a differently wrong one.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What is the difference between pretraining and post-training?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Pretraining builds general knowledge, and post-training teaches the model how to behave. In pretraining, the model learns to predict missing or next tokens across a huge dataset. The result is a base model that may only continue text, not answer requests.

Post-training then shapes that base model in stages:

  • Supervised fine-tuning (SFT) trains on written examples of good answers.
  • Preference optimization, through RLHF or DPO, then trains on ranked answer pairs that people prefer.

Pretraining takes far more data and compute than post-training. But post-training can add biases like excessive agreement or refusal.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

What is a hallucination, and why do LLMs hallucinate?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A hallucination is model output that sounds confident and fluent but is false or unsupported by any source: invented citations, fake API methods, wrong dates.

The model is trained to produce likely text, not verified facts. Knowledge sits compressed in the weights, so gaps get filled with something plausible.

Post-training rewards confident answers, so guessing often scores better than admitting ignorance.

Nothing in the API flags a hallucination. Grounding and verification stay the application's job.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What is a knowledge cutoff, and how should it influence how you build with a model?

Part of Pro
09

What does it mean for a model to be multimodal?

Part of Pro
10

What are embeddings, in simple terms?

Part of Pro
11

What does the major model landscape look like in 2026?

Part of Pro
12

What is the difference between open-weight and proprietary API models, and when would you choose each?

Part of Pro
Intermediate 22
13

Describe the transformer architecture at the level an application engineer should understand.

Part of Pro Visual
14

Explain self-attention conceptually. What problem does it solve?

Part of Pro Visual
15

How does byte-pair encoding (BPE) tokenization work?

Part of Pro Visual
16

Why does the same content cost different amounts in different languages, and why should engineers care?

Part of Pro
17

How do you count tokens accurately before sending a request, and why not just estimate?

Part of Pro
18

How do temperature and top-p interact, and how should you set them in practice?

Part of Pro Visual
19

What is top-k sampling, and how does it compare with top-p?

Part of Pro Visual
20

What are stop sequences, and when would you use them?

Part of Pro
21

What happens to model quality as the context window fills up?

Part of Pro
22

Compare context window sizes across the major 2026 models. What caveats apply?

Part of Pro
23

What is prompt caching, and how do you structure prompts to exploit it?

Part of Pro Visual
24

Explain RLHF at a high level. Why is it needed?

Part of Pro Visual
25

What is the difference between a base model and an instruct or chat model, and when does it matter?

Part of Pro
26

What are reasoning models, and when do they actually help?

Part of Pro
27

What is test-time compute, and why did it become a major scaling axis?

Part of Pro
28

What practical techniques reduce hallucinations in an LLM application?

Part of Pro
29

How do embeddings power semantic search and RAG?

Part of Pro Visual
30

How do you choose an embedding model in 2026?

Part of Pro
31

What are scaling laws, and how do they inform model size, data, and compute decisions?

Part of Pro
32

What is the difference between encoder-only, decoder-only, and encoder-decoder transformer models, and where is each used?

Part of Pro Visual
33

What is LoRA, and how does parameter-efficient fine-tuning compare with full fine-tuning?

Part of Pro
34

What is perplexity, and what does it tell you about a language model?

Part of Pro
Expert 24
35

Why is attention quadratic in sequence length, and what does that imply for long-context work?

Part of Pro
36

What is the KV cache, and why does it dominate LLM inference economics?

Part of Pro Visual
37

What is a Mixture-of-Experts architecture, and why has it become standard for large models?

Part of Pro Visual
38

What are the tradeoffs when quantizing a self-hosted model?

Part of Pro
39

Is temperature 0 deterministic? Explain why or why not.

Part of Pro Visual
40

Give a taxonomy of hallucination causes and match mitigations to each.

Part of Pro
41

How would you design model routing or cascading to balance cost and quality?

Part of Pro
42

When does a small model beat a frontier model?

Part of Pro
43

How do you control how much a reasoning model thinks, and why does it matter?

Part of Pro
44

Compare DPO with PPO-based RLHF for preference tuning.

Part of Pro Visual
45

What are RLAIF and Constitutional AI?

Part of Pro
46

How do multimodal models process images, and what does that cost in tokens?

Part of Pro Visual
47

Advertised context windows keep growing. How do you evaluate what a model can actually use?

Part of Pro
48

What techniques reduce LLM inference latency, and which matter most?

Part of Pro
49

How would you measure and monitor hallucinations in a production LLM system?

Part of Pro
50

Walk through the economics of a high-volume LLM feature and the levers for optimizing cost.

Part of Pro
51

Discuss sampling beyond temperature and top-p: failure modes and current practice.

Part of Pro
52

What are the known failure modes of RLHF-style post-training?

Part of Pro
53

When do you choose RAG, long context, or fine-tuning, and how do they combine?

Part of Pro
54

How much should you trust a reasoning model's visible chain of thought?

Part of Pro
55

Can token log probabilities be used to estimate model confidence, and what are the limits?

Part of Pro
56

How do transformers represent token order, and what are rotary position embeddings (RoPE)?

Part of Pro Visual
57

What is speculative decoding, and why doesn't it change the model's output?

Part of Pro Visual
58

What are multi-query and grouped-query attention, and what do they trade away?

Part of Pro Visual

No matches

Try a different filter or search term.

Know someone prepping for LLM Fundamentals? Send them this set.
Quick recap

LLM Fundamentals in pictures.

A quick recap of LLM Fundamentals in 38 short animated pictures, one idea at a time. About 9 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 33 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

51 of 58 LLM Fundamentals answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git