What is a large language model (LLM)?

Learning path, stage 1 of 5: How LLMs work · question 1 of 10

A large language model is a neural network, almost always a transformer, trained on a huge amount of text to predict the next token. Doing that well at scale gives it general abilities: answering questions, writing and editing code, summarising, translating and following instructions.

How it works, in one paragraph

Text is split into tokens. The model reads the tokens it has so far and outputs a probability for every possible next token. A decoding step picks one, appends it, and the loop repeats until a stop condition. Everything the model "knows" is stored in its weights (billions of numbers) learned during training. Nothing is looked up at run time unless you give it tools or retrieved documents.

The three stages that make a useful assistant

  • Pre-training: next-token prediction on web-scale text and code. This is where knowledge and general skill come from.
  • Instruction tuning (SFT): training on example prompts and good answers so it follows instructions.
  • Preference training: RLHF, RLAIF or DPO, so answers are helpful, honest and safe.

What interviewers want you to say

  • An LLM is stateless: each API call sees only the messages you send.
  • It has a knowledge cutoff and can hallucinate, so ground it (RAG, tools) when facts matter.
  • Capability grows with model size, data and compute (scaling laws), but so do cost and latency.

Sources

Code example

tsx
1// Calling an LLM is one HTTP request. Here with the Anthropic TypeScript SDK.
2import Anthropic from "@anthropic-ai/sdk";
3
4const client = new Anthropic(); // reads ANTHROPIC_API_KEY
5
6const response = await client.messages.create({
7 model: "claude-opus-5-5",
8 max_tokens: 1024,
9 messages: [{ role: "user", content: "Explain closures in one sentence." }],
10});
11
12// content is an array of blocks; narrow to text before reading
13for (const block of response.content) {
14 if (block.type === "text") console.log(block.text);
15}
16
17// The model is stateless: a follow-up must resend the earlier turns.

To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.

Open in study app