insideout Get Pro

What the words mean

The words of AI and quant engineering, and the lesson behind each.

AI engineering

A/B test

A live experiment where users are randomly split between two versions, and you compare an outcome you chose in advance. Offline tests ask "can it do the job?". An A/B test asks "does it help real users?".

Testing a prompt changeEvaluation · Pro

ablation

Removing (or switching off) one part of a system and measuring how much the score changes. The set of runs is an ablation study. The word comes from surgery, where it means removing tissue.

AblationsEvaluation · Pro

acceptance rate

The chance that the target model accepts a drafted token. It's high when the draft model is trained on similar data and the text is predictable (code, boilerplate, low temperature), and lower for creative, high-temperature text.

Drafting with a small modelInference and Serving · Pro

activation function

An activation function is the fixed rule a neuron applies to its total before passing it on. ReLU, short for rectified linear unit, is the one above: keep a positive total, and send out 0 for anything else.

One neuronNeural Networks

active parameters

Total parameters are every weight the model stores, all experts included, and set the memory. Active parameters are the weights one token uses, and set the compute per token. Qwen3-235B-A22B names both: 235B total, 22B active.

Mixture of expertsTransformers · Pro

Total parameters count every weight a model stores, and set its memory. Active parameters count the weights one token uses, the shared parts plus k experts per layer, and set its work.

Serving a mixture of expertsInference and Serving · Pro

Adam

Two running averages per weight, m of the slope and v of the squared slope, both corrected for starting at 0. Kingma and Ba's defaults: a rate of 0.001, β₁ = 0.9, β₂ = 0.999, and a tiny ε = 10⁻⁸ that avoids dividing by 0.

Momentum, Adam and learning-rate schedulesNeural Networks · Pro

An update rule that keeps two running averages for each weight: of its recent gradients, and of their squares. Each step moves the weight by the learning rate times the first average divided by the square root of the second, so weights with steady gradients move steadily and noisy ones move less. Most language models train with Adam or its variant AdamW.

Training a small GPT from zeroTransformers · Pro

AdamW

Adam with weight decay kept out of the division: each weight first shrinks by rate × decay × w, so all weights decay at the same rate. Loshchilov and Hutter proposed it in 2017. PyTorch's AdamW uses a decay of 0.01 unless you set one.

Momentum, Adam and learning-rate schedulesNeural Networks · Pro

advantage

An answer's reward minus the group average (here also divided by the spread) is its advantage. Group relative policy optimisation, GRPO, is the method above. DeepSeek introduced it in 2024. It needs no value model, which makes it lighter than PPO.

Rewarding checkable answersTraining and Tuning · Pro

agent

A workflow strings model calls and tools along a path written in your code. An agent lets the model choose each next step in a loop. Anthropic's "Building effective agents" (2024) calls both agentic systems.

Fixed workflow or open loopAgents

agent loop

The agent loop calls the model, runs any tool it asks for, appends the call and the result, and calls again. A model running in it with tools is an agent. Each reply's stop reason says why it stopped: tool_use, end_turn or max_tokens.

Observe, decide, actAgents

agent-computer interface

The set of tools an agent works through, and how each is named, described and shaped. It's Anthropic's term, by analogy with the human-computer interface: design tools for the jobs the agent does, not to mirror your API's endpoints.

Designing tools a model can useAgents

aggregate function

A function that turns many rows into one value, such as COUNT, SUM, AVG, MIN and MAX. With GROUP BY, it gives one value per group.

SQL queries: filter, join and groupEngineering Toolkit · Pro

aligned

An aligned instruction from a lower rung fits the higher rules, so the model follows it. A misaligned one works against them, so the model declines that part and carries on helping with the rest.

Who outranks whom in a promptPrompting

all-reduce

Data parallel training gives every GPU a full copy of the model and a different slice of each batch. An all-reduce sums a value across GPUs and hands every GPU the result. Gradient accumulation adds up gradients over several micro-batches before one update.

Training across many GPUsTraining and Tuning · Pro

all-to-all

Expert parallelism (EP) puts different experts on different GPUs, so each stores and reads only its share. Every MoE layer then runs an all-to-all: each GPU sends tokens to their experts' GPUs (the dispatch), and the results come back (the combine).

Serving a mixture of expertsInference and Serving · Pro

anchor

The written description of one level on a scale. Anchors give every grader the same picture of a 4, so their marks match more often. The share of replies two graders mark the same is their agreement.

RubricsEvaluation

answer relevance

Whether the answer responds to the question that was asked, regardless of where its facts came from.

Checking answers against sourcesSearch and Retrieval · Pro

arithmetic intensity

How many operations a piece of work does for each byte it moves in or out of memory. It's the number along the bottom of the roofline: left of the ridge point the reading sets the pace, right of it the arithmetic does.

Arithmetic intensityInference and Serving · Pro

associative recall

Storing pairs, such as names and phone numbers, and later returning the value for one key. Fixed-state layers fall behind attention here. In a phone-book test by Jelassi and colleagues (2024), a 410M transformer beat a 2.8B Mamba model once the book reached about 70 entries.

Linear attention and hybrid modelsTransformers · Pro

asymmetric quantization

The zero point is the integer that stands for real 0. Storing a scale and a zero point maps the real minimum and maximum onto the two ends of the integer range, so no codes go to waste. That's asymmetric quantization. Real 0 still lands exactly on an integer, so zeros come back exact.

Quantizing weightsInference and Serving · Pro

at-least-once

If you retry until you get a reply, every action happens at least once, and sometimes more. Getting exactly-once delivery over a network isn't possible in general, so the usual fix is to make doing it twice harmless.

Idempotency keysAgents · Pro

attention

Softmax turns scores into weights: raise e to each score, then divide by the total. Attention is the whole move: score the words, softmax the scores, then mix the words' vectors with the weights. A transformer does it for every word at once.

Context changes meaningTransformers

attention pattern

The grid of one head's weights over a piece of text. Reading patterns is the most common first step when people try to work out what a head does.

What trained heads learnTransformers · Pro

attention sink

A token, usually the first, that soaks up a large share of attention weight without the head reading much from it. It's a side effect of softmax, not a sign that the token matters.

What trained heads learnTransformers · Pro

AUC

Area under the ROC curve: the chance that a randomly chosen positive gets a higher score than a randomly chosen negative, with ties counted as half. 0.5 is a coin toss and 1.0 a perfect ranking. It doesn't depend on any threshold.

Measuring a classifierClassical Machine Learning · Pro

autograd

Short for automatic differentiation: values that record how they were made, plus a backward() that applies each operation's rule in turn. PyTorch's autograd works this way, on whole arrays of numbers at a time instead of single values.

Autograd you can step throughNeural Networks · Pro

autoregressive generation

Producing text one token at a time, where each new token is chosen from a forward pass over everything so far, including the tokens the model itself just wrote.

Autoregressive generationTransformers · Pro

AWQ

Activation-aware weight quantization. It measures input channel sizes on calibration data, searches for a scale per channel, multiplies salient weight channels up before rounding and divides their inputs down. Every weight stays in INT4.

GPTQ and AWQInference and Serving · Pro

backpropagation

The bookkeeping that works out every weight's slope in one pass backwards through the layers, using the chain rule from calculus. A later lesson, "The chain rule by hand", walks one small network through it number by number.

Updating weights with gradientsNeural Networks · Pro

bagging

Training many models, each on its own bootstrap sample of the rows (drawn at random with replacement, as many rows as the table has), and averaging their predictions. Short for bootstrap aggregating.

Random forests and gradient boostingClassical Machine Learning · Pro

base model

The model you have after pretraining. It continues text very well, but it doesn't answer you: ask it a question and it may carry on with more questions, as if it were writing a quiz. Teaching it to answer is the job of "Instruction tuning", later in this module.

PretrainingTraining and Tuning

baseline

The simplest thing you could do without a model, like flagging nobody or flagging everyone, scored the same way as the model. A model earns its place only by beating the best baseline on the number you care about.

Capstone: a tabular model end to endClassical Machine Learning · Pro

A baseline b is the reward you'd expect before seeing which answer came out. Use the advantage R − b in place of R. Any b that doesn't depend on the sampled answer keeps the average update, and a good one shrinks the noise.

Inside the RL step: policy gradients and PPOTraining and Tuning · Pro

The simplest reasonable system you compare against, run on the same test set with the same metric. The gain you report is the gap between your system and the baseline, not your system's raw score.

BaselinesEvaluation · Pro

batch

Batch inference scores every row on a schedule and stores the results for lookup. Online inference scores each request as it arrives, while the caller waits. Also called offline and real-time inference.

Capstone: a tabular model end to endClassical Machine Learning · Pro

batch invariance

A property of the maths kernels: giving the same result for a request whatever else is in its batch. Most fast kernels aren't batch-invariant. Some inference engines now offer batch-invariant modes, at some cost in speed.

Seeds, reproducibility and picking settingsTransformers · Pro

batching

Putting several requests into one forward pass, so they all share a single read of the weights. For memory-bound decode it multiplies the tokens a second at almost no cost in speed for each user.

Reading the prompt, writing the replyInference and Serving

Running several requests through the model in the same step so they share the cost of streaming the weights. The number of requests in a step is the batch size.

Throughput and Little's lawInference and Serving · Pro

behaviour test

A case written to test one behaviour. CheckList (Ribeiro, Wu, Guestrin and Singh, 2020) names three kinds: minimum functionality, invariance and directional. The last two need no answer key, only the output before and after an edit. Write them as ordinary test functions that run with the rest of the suite on every change.

Treating prompts like codeEvaluation · Pro

BERTScore

A reference-based score that matches words by the similarity of their embeddings (from a BERT-style model) instead of exact spelling. It gives paraphrases the credit that BLEU and ROUGE miss.

Overlap metrics: BLEU, ROUGE, BERTScoreEvaluation · Pro

BF16

Brain float 16, from Google Brain. FP32's 8 exponent bits with a 7-bit mantissa, so it's really the top half of an FP32 number. Most open models are trained and released in BF16, because training needs range more than it needs digits.

Number formatsInference and Serving · Pro

bi-encoder

An embedding model used for search. It encodes the question and each passage separately, then compares the two vectors. Fast, because passages are encoded once, ahead of time.

RerankingSearch and Retrieval · Pro

bias

Bias is error that stays however often you redraw the data: the model's average answer is off, because it's too simple for the pattern. Variance is how much a model's answers change from one sample of rows to another.

Training, validation and test setsClassical Machine Learning

A weight sets how much one input counts, and in which direction. The bias is added at the end, so the neuron can lean one way even when every input is 0. Training is the search for good values of both.

One neuronNeural Networks

bigram

Two neighbouring tokens, here two letters. A bigram model predicts the next token from the one before it, and nothing else.

A bigram language modelTokens and Embeddings · Pro

bit

Units of surprise. −ln p is in nats. −log₂ p, read "minus log base 2 of p", is in bits. To turn nats into bits, divide by ln 2, about 0.693.

Bits per byteTokens and Embeddings · Pro

bits per byte

A model's total loss on a text, in bits, divided by the text's length in bytes. Lower is better, and it means the same whatever tokenizer the model uses.

Bits per byteTokens and Embeddings · Pro

blended cost

The average cost per request across your models, each model's cost weighted by its share of traffic. It's the number your monthly bill is made of.

Routing requests between modelsProduction AI

BLEU

A translation score: clipped precision on runs of 1 to 4 words, combined with a geometric mean, times a penalty for being too short. Reported from 0 to 100. Use a standard library (sacrebleu) to compute it, because small changes in how words are split change the score.

Overlap metrics: BLEU, ROUGE, BERTScoreEvaluation · Pro

BM25

A keyword score that adds, for each search word, its IDF times a capped count. k1 sets how fast repeats stop paying; b sets how much length matters, from 0 (not at all) to 1 (fully). L is the length factor, 1 − b + b × length ÷ average.

Keyword search with TF-IDF and BM25Search and Retrieval

Bonferroni correction

Testing each of m results at α ÷ m, so the chance of even one false winner across all m stays at α or below. It's strict, so it also misses some real gains. A gentler rule, the false discovery rate of Benjamini and Hochberg, limits the share of flagged results that are false instead.

Multiple testing in experimentsEvaluation · Pro

bootstrap

Estimating how much a number would wobble by resampling your own data with replacement, many times, and recomputing it. The middle 95% of the results is a bootstrap confidence interval. Resample whole items (both models' results together), so the pairing is kept.

Is the new version really betterEvaluation · Pro

branch

A name that points at a commit and moves forward each time you commit on it. HEAD points at the branch you're on. git switch -c name makes one and switches to it.

Branches, merges and conflictsEngineering Toolkit · Pro

burn rate

The current error rate divided by the error rate the SLO allows. A burn rate of 1 uses the budget up in exactly the SLO window. A burn rate of 10 uses it ten times faster.

When to page someoneProduction AI · Pro

byte

A byte is a whole number from 0 to 255. UTF-8 is the standard rule for writing each character as one to four bytes, and for reading them back. Nearly every web page is stored this way.

Text as bytes, bytes as tokensTokens and Embeddings

byte pair encoding (BPE)

Training a tokenizer by merging. Start from the 256 byte tokens, count every pair of neighbouring tokens, merge the most common pair into a new token, and repeat for as many merges as you chose. GPT-2's and GPT-4's tokenizers were trained this way.

Training a BPE tokenizerTokens and Embeddings

byte-level tokenizer

A tokenizer whose starting vocabulary is the 256 byte values, so it can encode any text and never needs an unknown token. The tokenizers of GPT-2, GPT-4 and GPT-4o all start this way.

Text as bytes, bytes as tokensTokens and Embeddings

calibration

How well predicted probabilities match how often things really happen. Well calibrated: of the customers given 0.3, about 30% churn. A model can rank customers well and still be badly calibrated.

Logistic regressionClassical Machine Learning · Pro

A model is calibrated when its stated confidence matches how often it's right: of all the answers it gives at 90%, about 90% are correct. Expected calibration error (ECE) is the weighted average gap you just worked out. 0 is perfect.

What a model's probabilities are worthTransformers · Pro

How well a gate's confidence matches how often it's right. A calibrated gate's answers at about 0.9 are right about 9 times in 10. You check it on held-out labels, band by band. "What a model's probabilities are worth" in Transformers shows how to measure the gap and close it with temperature scaling.

Cheap decisions before expensive modelsProduction AI · Pro

calibration data

A small set of representative inputs (often a few hundred text samples) run through a model to collect activation statistics before quantizing. If your traffic is code, calibrate on code.

GPTQ and AWQInference and Serving · Pro

canary release

Sending a small share of traffic to a new version and comparing it against the rest (the control). Named after the canaries miners carried to warn of bad air. When a gate fails, an automated rollback sends all traffic back to the old version without waiting for a person.

Canary, shadow and rollbackProduction AI · Pro

canary token

A random string planted in the system prompt that has no reason to ever appear in a reply. If it shows up in the output, the prompt leaked, and your code can block the reply and log the attempt.

Defending against injectionProduction AI · Pro

cascade

Cheap model first, escalating to a stronger one only when the first answer fails a check. The share that escalates, the escalation rate, sets both the cost and the wait.

Routing requests between modelsProduction AI

catastrophic forgetting

Losing old skills while learning a new one, because the same weights get pushed hard toward the new data.

Instruction tuningTraining and Tuning · Pro

causal mask

The rule that each position may only attend to itself and earlier positions, done by adding minus infinity to the later scores before softmax. Drawn as a grid, the allowed cells form a triangle: the lower-left half, including the diagonal.

Masking future tokensTransformers · Pro

centroid

The average of a group of vectors: the middle point of the group. Classifying by nearest centroid is the simplest way to turn a handful of labelled examples into a classifier.

Semantic search and clusteringTokens and Embeddings · Pro

chain rule

When a change passes through several steps, the overall rate is the product of each step's rate. In calculus these rates are called derivatives.

The chain rule by handNeural Networks · Pro

chat template

The exact layout of roles and special tokens a model was tuned with. Each model family has its own, and you have to use the same one in training and in serving.

Instruction tuningTraining and Tuning · Pro

A chat template is the rule for flattening messages into one run of tokens: which markers open and close each message, and where the role name goes. The markers are special tokens: single tokens meant to come only from the template.

How a chat request is builtPrompting

chi-squared test

Tests of whether a column changed more than chance explains. The KS test (Kolmogorov-Smirnov) takes the widest gap in the share at or below each value. The chi-squared test adds up (seen − expected)² ÷ expected over the categories.

Drift and model monitoringProduction AI · Pro

chunk

A chunk is one piece of a document: the unit that gets indexed, retrieved and handed on. Chunk size is how long each chunk is, usually counted in tokens. Overlap is how much text neighbouring chunks share, so a fact near a cut still lands whole in at least one chunk. Overlap stores some text twice.

Chunk size and overlapSearch and Retrieval · Pro

chunk size

A chunk is one piece of a document: the unit that gets indexed, retrieved and handed on. Chunk size is how long each chunk is, usually counted in tokens. Overlap is how much text neighbouring chunks share, so a fact near a cut still lands whole in at least one chunk. Overlap stores some text twice.

Chunk size and overlapSearch and Retrieval · Pro

chunked prefill

Splitting a long prompt's prefill into pieces that ride along with other users' decode steps, so no single step gets huge. The chunk size comes from the step's token budget.

Continuous batchingInference and Serving · Pro

circuit breaker

A guard your code puts around a tool that counts recent failures. Past a threshold it trips, and for a set period calls are refused on the spot instead of being sent. When the period ends a single test request goes out: success resets the guard, failure trips it again.

When a tool call failsAgents · Pro

citation

A marker in the answer that points to the source passage a claim came from. Attribution is the general idea: every claim can be traced to a source.

Citing sourcesSearch and Retrieval · Pro

citation support

Whether the passage a sentence cites actually backs it up. The next lesson, "Checking answers against sources", asks the wider question: is each claim backed by anything that was retrieved at all?

Citing sourcesSearch and Retrieval · Pro

classification

Regression predicts a number: a rent, a delivery time, next month's sales. Classification predicts a category from a fixed list: spam or not, one of five teams. Both are supervised learning: every training example comes with its right answer, the label, attached.

Learning a function from examplesClassical Machine Learning

client

The host is the app you use: a chat app, an IDE, an agent. It holds the conversation, calls the model, and runs one MCP client per server it connects to. A server offers tools, resources and prompts. The model only talks to the host.

MCP end to endAgents · Pro

closed form

Least squares picks the parameters with the smallest sum of squared residuals, which is also the smallest MSE. For a line the answer has a closed form: a formula you compute directly, with no steps.

Linear regressionClassical Machine Learning

coefficient

A coefficient is the weight on one feature: how much the prediction changes when that feature rises by 1 and the others stay the same. R² is the share of the label's spread around its average that the model explains: 1 is perfect, 0 is no better than the average.

Linear regressionClassical Machine Learning

Cohen's kappa

A measure of agreement between two graders that subtracts the agreement expected by chance: (observed − chance) ÷ (1 − chance). 1 is perfect, 0 is no better than luck, and below 0 is worse. A common rough guide calls 0.41 to 0.60 moderate and above 0.80 strong. Agreement among graders in general is called inter-annotator agreement.

People as gradersEvaluation · Pro

coherence

Fluency: does each sentence read as natural language? Coherence: do the sentences fit together in a sensible order? Factuality (or faithfulness, when judged against a source): is every claim supported? Relevance: does it cover what matters for the task? SummEval, a widely used study of summary scoring, had expert raters score news summaries on these four, calling factuality "consistency".

Scoring generated textEvaluation · Pro

commit

A repository is a project whose history git keeps, in a .git folder inside it. A commit is a saved snapshot of the files you added, with an author, a time, a message and a link to the commit before it.

Commits and the staging areaEngineering Toolkit

community

A group of entities linked to each other more densely than to the rest of the graph, found by a community detection algorithm such as Leiden. Splitting each group again gives levels, from a few broad communities to many narrow ones.

Knowledge graphs and GraphRAGSearch and Retrieval · Pro

compaction

Replacing older parts of the history with a shorter summary once it passes a size limit, while keeping the task and recent turns intact.

Keeping an agent's window cleanAgents · Pro

compounding errors

When a run succeeds only if every step does, its chance of success is the product of the steps' chances. Small error rates per step grow into large failure rates over a long run.

Fixed workflow or open loopAgents

computation graph

The record of how a result was made. Each value is a node, linked to the values it was made from. Following the links back from the output reaches every input.

Autograd you can step throughNeural Networks · Pro

compute

A FLOP is one floating-point operation, an add or a multiply. A run's total is its compute. MFU, model FLOPs utilisation, is the share of the hardware's peak speed a run actually gets. Careful: FLOP/s, per second, is a speed, not an amount.

Scaling lawsTraining and Tuning

compute-bound

A pass is compute-bound when its arithmetic takes longer than reading its data, like prefill. It's memory-bound when reading takes longer, like decode. To tell which, compare its operations per byte with the GPU's own ratio.

Reading the prompt, writing the replyInference and Serving

compute-optimal

A model trained at the best split for its budget, about 20 tokens per parameter, is compute-optimal, or Chinchilla-optimal: the lowest loss for that much training compute.

Scaling lawsTraining and Tuning

condition number

Measure a direction's steepness by how fast its slope grows: 1 per unit of x, 100 per unit of y. The condition number is the steepest over the gentlest, 100 here. Plain steps need a rate below 2 ÷ the steepest, so the gentlest shrinks by at most 2% a step.

Momentum, Adam and learning-rate schedulesNeural Networks · Pro

confidence interval

A range around a measured score that would contain the true value most of the time (95% of the time, for a 95% interval). Report it next to every score. A score without one hides how little 100 items can tell you.

Is the new version really betterEvaluation · Pro

confidence threshold

The confidence threshold is the score a gate's answer must reach before the gate acts on it. Coverage is the share of requests that clear it and get handled by the gate. Raise the threshold, and coverage falls along with the gate's error rate.

Cheap decisions before expensive modelsProduction AI · Pro

confusion matrix

The table of a classifier's four counts: true positives, false positives, false negatives and true negatives. scikit-learn's confusion_matrix puts the real classes in rows and the predictions in columns, so for 0/1 labels it reads [[TN, FP], [FN, TP]].

Measuring a classifierClassical Machine Learning · Pro

The table of counts of true class against predicted class. For a yes/no task the four boxes are true positives (flagged and urgent, 40), false positives (flagged but not urgent, 30), false negatives (urgent but missed, 10) and true negatives (920).

The confusion matrixEvaluation · Pro

constitutional AI

Steering a model with a written list of principles (the constitution), using a model to critique and revise answers against it instead of asking people to label every example. Anthropic introduced it, and the same pattern scales down to one product's rules.

Learning from preferencesTraining and Tuning · Pro

constrained decoding

Masking the scores of rule-breaking tokens at every step, so the model can only produce output that fits a grammar: a JSON Schema, a regular expression, or a fixed list of choices. Also called constrained sampling or guided decoding. The edit itself is a logit mask.

Grammars that constrain decodingPrompting · Pro

container

A running instance of an image: a process that sees only the image's files and gets its own network. Delete it and anything it wrote is gone; the image is unchanged.

Containers and deployingEngineering Toolkit · Pro

context

Everything the model reads in one request: the system prompt, the tool definitions and the history so far. In an agent it grows each turn by that turn's tool call and tool result, and it has to fit in the model's context window.

Observe, decide, actAgents

context budget

The number of tokens you allow yourself per call, usually far below the window. Deciding what fills it is often called context engineering.

A budget for the context windowPrompting · Pro

context compression

Making the context smaller while keeping what the model needs. Summarizing, extracting and embedding are the three main kinds.

Fitting more into the windowPrompting · Pro

context confusion

A wrong answer caused by the other passages in the prompt: two versions of one rule, near-identical rules for different cases, or so much text that the passage that matters gets lost.

Why grounded answers still go wrongSearch and Retrieval · Pro

context engineering

Deciding what goes into the context on every turn: what to keep, trim, summarize, store outside, or leave out. The term took hold in 2025, as agents started running for hundreds of steps.

Keeping an agent's window cleanAgents · Pro

context file

A markdown file in the repo, such as AGENTS.md or CLAUDE.md, that a coding agent loads at the start of every session: commands, layout, conventions and what not to touch. It's sent with every request, so every line has a cost.

The harness around a coding agentAgents · Pro

context window

How far either side of a word you look for neighbours. Here it's 1. Real systems use somewhere from 2 to 10. A small window tends to group words that do the same job (cat, dog); a wide one also pulls in words from the same topic (cat, fish).

The distributional hypothesisTokens and Embeddings · Pro

The most tokens a model can read in one call, counting the system prompt, tools, history and the reply it's writing. For an agent, it's a budget that every step spends from.

Keeping an agent's window cleanAgents · Pro

contextual embedding

A vector for one use of a word, built from the word and the words around it. A static embedding gives one vector per word. A contextual embedding gives one per use, so the same word gets a new vector in every sentence.

Context changes meaningTransformers

continuous batching

Deciding who is in the batch again at every decode step, so a finished request's slot goes to a waiting one straight away. Also called iteration-level batching, from the Orca paper (2022). vLLM, SGLang and TensorRT-LLM all work this way by default.

Continuous batchingInference and Serving · Pro

contrastive loss

In-batch negatives are the other passages in a batch, used as each query's wrong answers. The contrastive loss is the cross-entropy of picking each query's own passage (score s⁺) from its row, where Σ adds up e^s over the row. van den Oord and colleagues named it InfoNCE in 2018.

How embedding models are trainedTokens and Embeddings · Pro

coordinated omission

An open-loop test sends requests at a set arrival rate whether or not earlier ones have finished, the way real traffic does. The looping kind is closed-loop. The under-counting it causes during slowdowns is called coordinated omission.

Designing a fair benchmarkInference and Serving · Pro

corpus

The whole pile of text a model trains on, also called its training data or pretraining mix. It's measured in tokens. In English a token is about 4 characters: Llama 3's tokenizer averages 3.94.

Building a pretraining datasetTraining and Tuning

cosine decay

Warmup raises the rate from 0 to its peak over the first steps. Cosine decay then lowers it along half a cosine wave to a floor, as progress runs from 0 to 1. The cosine shape comes from Loshchilov and Hutter's SGDR paper (2016).

Momentum, Adam and learning-rate schedulesNeural Networks · Pro

cosine similarity

The dot product of two vectors once both their lengths are divided out. It's the cosine of the angle between them, so it runs from 1 (same direction) through 0 (right angles) to −1 (opposite). Length plays no part.

Cosine similarity and the dot productTokens and Embeddings · Pro

An embedding is the list of numbers a model gives a text. Cosine similarity scores two embeddings by direction only: 1 for the same direction, 0 for unrelated, −1 for opposite.

Vector searchSearch and Retrieval

counter

A gauge is a reading of right now that can go up or down, like requests waiting. A counter only goes up, like tokens written, and what you use is its rate. A latency histogram is a set of counters: one per bucket, plus a sum and a count.

Running a model serverInference and Serving · Pro

coverage

The confidence threshold is the score a gate's answer must reach before the gate acts on it. Coverage is the share of requests that clear it and get handled by the gate. Raise the threshold, and coverage falls along with the gate's error rate.

Cheap decisions before expensive modelsProduction AI · Pro

cross-encoder

A model that scores one (question, passage) pair at a time by reading both together. More accurate than a bi-encoder, and much slower, since nothing can be computed ahead of time.

RerankingSearch and Retrieval · Pro

cross-entropy

The loss −ln(p), where p is the probability the network gave the right answer. Also called log loss. When the right answer is no, p is the probability of no: 1 minus the probability of yes.

Loss functionsNeural Networks

cross-entropy loss

The cross-entropy loss is −ln of the probability given to the right token, averaged over every position. The perplexity is e raised to that loss.

PretrainingTraining and Tuning

cross-validation

Cut the data into k folds; train on k − 1 of them and validate on the one left out, k times over, then average. Every row is validated once. Five and ten folds are the usual choices. Also called k-fold cross-validation.

Cross-validation and tuningClassical Machine Learning · Pro

data leakage

Information reaching the model during training that won't be there, or won't be the same, when it makes real predictions. It inflates every score you compute and disappears in production.

Data leakageClassical Machine Learning · Pro

data mix

The data mix is the share of training tokens each source gets. An epoch is one full pass over a source. Labs tune the mix by training small models on different mixes and comparing them.

Building a pretraining datasetTraining and Tuning

data parallel

Data parallel training gives every GPU a full copy of the model and a different slice of each batch. An all-reduce sums a value across GPUs and hands every GPU the result. Gradient accumulation adds up gradients over several micro-batches before one update.

Training across many GPUsTraining and Tuning · Pro

dead air

Silence on a call that nobody explains. Fill it while a tool runs with a status line: a recording your code plays, or a sentence the model writes before its tool call. Keep it neutral, "Let me check", never "Done", because the tool hasn't answered yet.

Voice agentsAgents · Pro

dead ReLU

A ReLU neuron whose total is negative for every input, so it always outputs 0 and never learns again. One big update that knocks its bias far below zero is a common cause.

Diagnosing a network that won't trainNeural Networks · Pro

decision threshold

The probability at or above which a classifier says yes. Most libraries use 0.5 unless told otherwise. The right value comes from what each kind of mistake costs.

Logistic regressionClassical Machine Learning · Pro

decision tree

A model that sends each row through a series of yes-or-no questions about its features, where each question depends on the answers before it. It predicts from the training rows that ended up in the same place.

Decision treesClassical Machine Learning · Pro

decode

Prefill is the first pass: it reads the whole prompt at once and produces the first reply token. Decode is everything after: one token per pass, each pass taking the token just made as its new input.

Reading the prompt, writing the replyInference and Serving

decoding

Encoding turns text into token IDs: write it as bytes, then apply the merges in the order they were learned. Decoding turns IDs back into text: join each token's bytes and read them as UTF-8. Decoding what you encoded gives back the original text.

Training a BPE tokenizerTokens and Embeddings

dense retrieval

Search by comparing embeddings. "Dense" because every number in an embedding carries something. BM25's view of a passage is sparse: a count for every word in the vocabulary, almost all of them 0.

Vector searchSearch and Retrieval

dependency

A package your code needs. Direct dependencies are the ones you list; transitive ones are what those need in turn, like numpy for pandas.

Setting up a Python projectEngineering Toolkit · Pro

dev set

A dev set (or validation set) is the data you check against while making choices. A test set is kept back and scored only for a final decision. Once choices are made by looking at a set, it has quietly become a dev set.

Multiple testing in experimentsEvaluation · Pro

digit splitting

A fixed rule for cutting numbers before any merges apply. Llama 1 and 2 split every number into single digits. The tokenizers of GPT-4 and GPT-4o cut runs of digits into chunks of up to three, starting from the left.

Tokenizer quirks: numbers, spelling, languagesTokens and Embeddings

distillation loss

The KL divergence KL(p ‖ q) measures how far a distribution q is from p: 0 when they match. Distillation lowers it between the teacher's softened p and the student's softened q, times T², usually plus a small weight w on the usual loss for the true label, at T = 1.

DistillationTraining and Tuning · Pro

distractor

Text in the prompt that looks relevant but doesn't help with the question. A 2024 study of retrieval found that passages related to the question but lacking the answer hurt accuracy more than random passages did.

A budget for the context windowPrompting · Pro

distributional hypothesis

The idea that words used in the same contexts tend to mean similar things. The linguist J. R. Firth put it this way in 1957: "You shall know a word by the company it keeps." Every method in this lesson leans on it.

The distributional hypothesisTokens and Embeddings · Pro

document frequency

A word's document frequency, n, is the number of passages that contain it. Its inverse document frequency, IDF, turns that into a weight that grows as the word gets rarer. With N passages in all:

Keyword search with TF-IDF and BM25Search and Retrieval

dot product

Multiply two vectors position by position and add up the products. Positive means they point roughly the same way, zero means they're at right angles (unrelated), negative means they point apart. Written a · b, read "a dot b".

Cosine similarity and the dot productTokens and Embeddings · Pro

DPO

Direct preference optimisation: training straight on preference pairs with the loss above, with no reward model and no RL loop. Only two models sit in memory: the one being trained and the frozen reference.

Learning from preferencesTraining and Tuning · Pro

durable execution

Running a workflow or agent so each step's result is saved as it finishes, and a crashed run resumes from its log instead of starting over. Tools like Temporal are built around this idea.

Idempotency keysAgents · Pro

dynamic batching

Batch on a size limit or a time limit, whichever hits first. It suits work where every request is about the same size, like embedding text or classifying it. For chat it still has the run-to-the-end problem.

Continuous batchingInference and Serving · Pro

early stopping

Setting aside part of the training rows, scoring the model on them after each round, and stopping when that score hasn't improved for a set number of rounds. scikit-learn's HistGradientBoosting holds back 10% and waits 10 rounds, and switches this on by itself when there are more than 10,000 rows.

Random forests and gradient boostingClassical Machine Learning · Pro

ECE

A model is calibrated when its stated confidence matches how often it's right: of all the answers it gives at 90%, about 90% are correct. Expected calibration error (ECE) is the weighted average gap you just worked out. 0 is perfect.

What a model's probabilities are worthTransformers · Pro

editable install

Installing a project with pip install -e ., so the environment imports it straight from your folder. Edits apply without reinstalling.

Setting up a Python projectEngineering Toolkit · Pro

elastic net

A penalty that mixes L1 and L2, with a setting for the share of each (l1_ratio in scikit-learn). It zeroes weak features like lasso and shares weight among related ones like ridge.

Regularisation with L1 and L2Classical Machine Learning · Pro

elicitation

A server asking the user for input partway through a call. Form mode shows a small form built from a JSON Schema. URL mode opens a web page, for anything secret such as a sign-in. The user can accept, decline or cancel.

MCP end to endAgents · Pro

embedding

The row of numbers for a token is its embedding, and the table is the embedding table (or embedding layer). It has one row per token in the vocabulary.

Looking up a token's vectorTokens and Embeddings · Pro

An embedding is the list of numbers a model gives a text. Cosine similarity scores two embeddings by direction only: 1 for the same direction, 0 for unrelated, −1 for opposite.

Vector searchSearch and Retrieval

encoding

Encoding turns text into token IDs: write it as bytes, then apply the merges in the order they were learned. Decoding turns IDs back into text: join each token's bytes and read them as UTF-8. Decoding what you encoded gives back the original text.

Training a BPE tokenizerTokens and Embeddings

end-of-turn detection

Deciding that the caller has finished, so the agent may reply. A silence threshold ends the turn after a set pause: shorter ones cut people off, longer ones slow every turn. A detector that also reads the words can wait through a pause and still answer a finished sentence quickly.

Voice agentsAgents · Pro

end-to-end latency (E2E)

The time from sending a request to receiving its last token, roughly TTFT + (output tokens − 1) × time per token. For output a program consumes whole, add the parsing and checking after it: that sum is the time until the answer is usable.

Time until the answer is usableInference and Serving · Pro

endpoint

One method and path an API answers, such as POST /runs, and the function behind it.

HTTP APIs with FastAPIEngineering Toolkit · Pro

entity resolution

Deciding which names refer to the same real thing, and merging them into one node. Cheap checks go first: exact match after lowercasing and dropping words like "Ltd", then embedding similarity above a threshold, then a model call for the doubtful pairs. Merging too eagerly is the opposite mistake: "Norfield Metals" and "Northfield Metal Works" may be two companies.

Knowledge graphs and GraphRAGSearch and Retrieval · Pro

environment variable

A named setting, like HOME or DATA_DIR, that each process gets a copy of when it starts. export adds a shell variable to the list that gets copied, and Python reads the list through os.environ.

Pipes, variables and scriptsEngineering Toolkit

epoch

The data mix is the share of training tokens each source gets. An epoch is one full pass over a source. Labs tune the mix by training small models on different mixes and comparing them.

Building a pretraining datasetTraining and Tuning

error analysis

Error analysis is reading outputs one by one, noting what went wrong, then grouping and counting the notes. Each pile is a failure mode: one way the system keeps going wrong, such as stale station data.

Read the failures firstEvaluation

Reading a sample of real traces, noting the first thing that went wrong in each, and counting the notes by kind, so you fix the most common failure first.

Traces you can debug fromAgents · Pro

error bar

The range a score could move if you reran it on fresh cases of the same kind: about two wobbles either way. "Is the new version really better" turns it into a proper confidence interval.

Specifying a good outputEvaluation

error budget

The SLI (service level indicator) is the measured number. The SLO (service level objective) is the target for it. The error budget is how much failure the target leaves room for. Teams often slow down releases when the budget runs low.

When to page someoneProduction AI · Pro

escalation

Passing a case the gate isn't sure about to something stronger: the large model, or a person. A gate that's unsure escalates instead of guessing, so every route needs somewhere to escalate to.

Cheap decisions before expensive modelsProduction AI · Pro

exact cache

A lookup table from a hash of the full request to the stored response. A hit needs every character to match, so it's safe, but "opening hours?" and "opening hours" miss each other. Trimming spaces and lowercasing before hashing helps a little.

Exact and semantic cachesProduction AI · Pro

exit code

The number a program returns when it ends: 0 for success, anything else for failure. The shell keeps the last one in $?, and &&, || and set -e act on it.

Pipes, variables and scriptsEngineering Toolkit

experiment tracking

Experiment tracking records every training run (code, data, settings, scores) so runs can be compared and rebuilt. A model registry lists the models you've released by version, each linked to the run that made it, and marks which one is live. In MLflow, serving can load whichever version holds an alias you control, such as champion, so rolling back means moving it to the old version.

Canary, shadow and rollbackProduction AI · Pro

expert parallelism

Expert parallelism (EP) puts different experts on different GPUs, so each stores and reads only its share. Every MoE layer then runs an all-to-all: each GPU sends tokens to their experts' GPUs (the dispatch), and the results come back (the combine).

Serving a mixture of expertsInference and Serving · Pro

experts touched per step

The average number of a layer's experts that some token in the step picks, when B tokens each pick k of E at random. It starts at k and nears E once B is a few times E ÷ k. ^B means multiplied by itself B times.

Serving a mixture of expertsInference and Serving · Pro

explained variance

The share of the total spread that a principal component keeps, here 90% and 10%. scikit-learn reports it as explained_variance_ratio_, and you usually keep enough components to reach a share you choose, such as 90%.

Clustering and PCAClassical Machine Learning · Pro

exploding gradients

Gradients that shrink (vanish) or grow (explode) as they pass back through many layers, because each layer scales them by a bit less, or a bit more, than 1.

Diagnosing a network that won't trainNeural Networks · Pro

exponent

The exponent bits pick a power of two, so they set the range: how big or how small a number can get. The mantissa bits are the digits, so they set the precision: how finely you can tell nearby numbers apart. Floating point formats differ only in how many bits go to each.

Number formatsInference and Serving · Pro

exponential backoff

With exponential backoff each wait is double the last, up to a ceiling. Jitter picks each wait at random below that amount ("full jitter" draws anywhere from zero up to it), so clients that failed at the same moment come back at different moments.

When a tool call failsAgents · Pro

exponential backoff with jitter

Doubling the longest wait before each retry (exponential backoff) and drawing the actual wait at random below it (jitter). Drawing it between 0 and the limit is full jitter, and a cap stops the limit growing forever.

When the main model is downProduction AI

F1

The harmonic mean of precision and recall, 2 × P × R ÷ (P + R), which is the same as 2 × TP ÷ (2 × TP + FP + FN). It's high only when both are high. It ignores true negatives and treats both kinds of mistake as equally bad.

Measuring a classifierClassical Machine Learning · Pro

Precision is true positives ÷ everything flagged (how much to trust a flag). Recall is true positives ÷ everything really positive (how much it catches). F1 combines them as 2 × P × R ÷ (P + R), which here is 2 × 0.57 × 0.8 ÷ 1.37 = 0.67. F1 is low if either one is low.

The confusion matrixEvaluation · Pro

factuality

Fluency: does each sentence read as natural language? Coherence: do the sentences fit together in a sensible order? Factuality (or faithfulness, when judged against a source): is every claim supported? Relevance: does it cover what matters for the task? SummEval, a widely used study of summary scoring, had expert raters score news summaries on these four, calling factuality "consistency".

Scoring generated textEvaluation · Pro

failure mode

Error analysis is reading outputs one by one, noting what went wrong, then grouping and counting the notes. Each pile is a failure mode: one way the system keeps going wrong, such as stale station data.

Read the failures firstEvaluation

faithfulness

Whether every claim in the answer is backed by the retrieved passages. Also called groundedness. An answer can be true in the world and still unfaithful, if nothing retrieved said it.

Checking answers against sourcesSearch and Retrieval · Pro

fallback chain

The ordered list of places a request goes when the one before it fails, all inside one deadline. Gateways, the proxies teams put in front of their models, let you write it as settings.

When the main model is downProduction AI

false negative

A false positive is a yes that should have been a no: a false alarm. A false negative is a no that should have been a yes: a miss. Their costs are rarely equal.

Measuring a classifierClassical Machine Learning · Pro

false positive

A false positive is a yes that should have been a no: a false alarm. A false negative is a no that should have been a yes: a miss. Their costs are rarely equal.

Measuring a classifierClassical Machine Learning · Pro

fan-in

The number of inputs a neuron reads. Starting-weight rules are built on it: about 1/√(fan-in) for tanh, known as Xavier or Glorot initialisation (the original averages fan-in and fan-out), and √2/√(fan-in) for ReLU, known as He initialisation, because ReLU zeroes about half its outputs.

Diagnosing a network that won't trainNeural Networks · Pro

fast-forward

A merge where the branch being merged into hasn't moved, so git only moves its label forward. No new commit is made.

Branches, merges and conflictsEngineering Toolkit · Pro

feature

A feature is a column you know at the moment you need a prediction, used as an input. The label is the column you want to predict: known for past rows, blank for new ones. Each row, features and label together, is one example.

Learning a function from examplesClassical Machine Learning

feature logging

Saving the exact feature values a model received live, with each request's id and time, for a sample of requests. You can then compare them with training code row by row, and later train on what the model really saw.

Feature stores and training-serving skewProduction AI · Pro

feature store

A system that keeps each feature's definition in one place and its values in two: an offline store with every past value and its time, for training rows built with as-of joins, and an online store with each customer's latest value, for fast lookups. Feast is an open-source one.

Feature stores and training-serving skewProduction AI · Pro

fertility

The average number of tokens a tokenizer uses per word. The lower it is for a language, the cheaper, faster and roomier a model is in that language. Measure it on real text, with the tokenizer of the model you'll use.

Tokenizer quirks: numbers, spelling, languagesTokens and Embeddings

few-shot prompting

Putting solved examples in the prompt. Each example is a shot: no examples is zero-shot, one is one-shot, and a handful is few-shot.

Few-shot examplesPrompting

fine-grained

Fine-grained experts are many narrow ones in place of a few wide ones, with more picked per token at the same compute. Shared experts run for every token, with no router.

Mixture of expertsTransformers · Pro

fine-tuning

Continuing to train an existing model on your own examples (usually input and ideal output pairs) so its behaviour changes. Often done with adapters such as LoRA, which train a small add-on instead of every weight.

Prompt, retrieve or fine-tuneTraining and Tuning · Pro

fine-tuning an embedding model

Training a ready-made model further on your own pairs, with the same contrastive loss, so it ranks your passages better. It counts only if held-out questions, split by passage, score better than before.

How embedding models are trainedTokens and Embeddings · Pro

fitting

A model is a function that turns features into a prediction. Its parameters are the numbers left open in it: one weight per feature, plus one on its own. Fitting, or training, sets them so the predictions on known examples come as close as they can to the labels.

Learning a function from examplesClassical Machine Learning

five workflow shapes

Prompt chaining feeds each call's output to the next. Routing labels the input and sends it to one handler. Parallelization runs calls at once, on slices or as votes. Orchestrator-workers lets one call plan the subtasks. Evaluator-optimizer loops a writer and a grader.

Fixed workflow or open loopAgents

fixed-budget experiment

Comparing training ideas by giving each the same wall-clock time on the same machine, then scoring the result. Whatever a change does to model size, batch size or speed, it has to pay for it inside the budget.

Fixed-budget experimentsTraining and Tuning · Pro

flag

An option after a command's name that changes what it does, starting with a dash, like -n 3 or -l. Many also have a long form with two dashes, like --lines=3.

Files and folders in the shellEngineering Toolkit

FlashAttention

The best-known tiled method (Dao and colleagues, 2022). It keeps each tile in the GPU's small fast on-chip memory instead of writing the grid out to main memory. Most serving and training code uses it or something like it.

The price of a long contextInference and Serving · Pro

FLOP

One floating-point operation: a single multiply or add on decimal numbers. Work is counted in FLOPs. Hardware speed is quoted in FLOP per second, usually written FLOPS, and modern GPUs reach hundreds of trillions (teraFLOPS, TFLOPS).

Prompt length on different GPUsInference and Serving · Pro

FLOPs

A FLOP is one floating-point operation, an add or a multiply. A run's total is its compute. MFU, model FLOPs utilisation, is the share of the hardware's peak speed a run actually gets. Careful: FLOP/s, per second, is a speed, not an amount.

Scaling lawsTraining and Tuning

fluency

Fluency: does each sentence read as natural language? Coherence: do the sentences fit together in a sensible order? Factuality (or faithfulness, when judged against a source): is every claim supported? Relevance: does it cover what matters for the task? SummEval, a widely used study of summary scoring, had expert raters score news summaries on these four, calling factuality "consistency".

Scoring generated textEvaluation · Pro

force push

A push that replaces the server's branch even though it isn't an ancestor of yours. Needed after a rebase. Use --force-with-lease, which refuses if the server has commits you haven't seen.

Rebasing, remotes and pull requestsEngineering Toolkit · Pro

foreign key

A column that holds another table's primary key, like orders.customer_id. It's how one row points at another.

SQL queries: filter, join and groupEngineering Toolkit · Pro

forward pass

A hidden layer sits between the inputs and the output. Its answers never appear in the data: the network makes up its own in-between questions, here "is either on?" and "are both on?". A forward pass is one run from inputs to output, a layer at a time.

Stacking neurons into layersNeural Networks

freshness checks

The checks a scheduled job runs on its inputs before it writes: the newest timestamp, today's row count against yesterday's, every expected source present. If one fails, the job says so plainly or doesn't publish.

When to page someoneProduction AI · Pro

FSDP

ZeRO (Rajbhandari and others, Microsoft, 2019) shards training state across data-parallel GPUs in three stages: Adam's state, then gradients, then weights. PyTorch's FSDP, fully sharded data parallel, is built on the same idea.

Training across many GPUsTraining and Tuning · Pro

full fine-tuning

Training every parameter of a pretrained model. It's the most flexible option and the most expensive one.

Adapters and LoRATraining and Tuning · Pro

gate

A rubric part that must pass for the reply to score at all. Fail it and the score is 0. Safety and privacy are the usual gates. The other parts are combined with weights.

RubricsEvaluation

A cheap decision step in front of an expensive one. It answers one question with a label from a fixed set plus a confidence, acts when the confidence is high enough, and passes everything else on. It's a fast path, never the only path.

Cheap decisions before expensive modelsProduction AI · Pro

gated recurrence

A layer that carries a fixed-size state from token to token and, before each update, scales it by a gate between 0 and 1 set by the current token. Mamba (Gu and Dao, 2023), a state-space model, has this shape, and so does Gated DeltaNet.

Linear attention and hybrid modelsTransformers · Pro

gauge

A gauge is a reading of right now that can go up or down, like requests waiting. A counter only goes up, like tokens written, and what you use is its rate. A latency histogram is a set of counters: one per bucket, plus a sum and a count.

Running a model serverInference and Serving · Pro

generalisation

How well a model does on new examples, not the ones it was fitted on. The only honest way to measure it is on rows the model never saw.

Learning a function from examplesClassical Machine Learning

Gini impurity

1 − Σ (share of each class)², summed over the classes. It's the chance that two rows drawn at random from the group, with replacement, have different labels: 0 for a pure group, 0.5 for an even mix of two classes.

Decision treesClassical Machine Learning · Pro

.gitignore

A file of patterns, one per line, for paths git should leave out. It only affects files git isn't tracking yet. A file that's already committed stays tracked until git rm --cached takes it out of the index.

Commits and the staging areaEngineering Toolkit

golden set

Your saved collection of test inputs and their expected results, covering the jobs the prompt must keep doing. Every prompt version runs against it. Add a case each time a bug reaches users, so that bug can't come back unnoticed.

Treating prompts like codeEvaluation · Pro

Goodhart's law

Reward hacking is a model scoring well on the reward without doing what the reward was meant to measure. Goodhart's law is the older idea from economics: when a measure becomes a target, it stops being a good measure.

Rewarding checkable answersTraining and Tuning · Pro

goodput

Requests per second that succeeded and met every latency target. Some dashboards give it as a share instead: 80% of requests were good. Multiply the share by the request rate to get the rate.

Goodput under errors and timeoutsInference and Serving · Pro

GPTQ

A post-training method that quantizes a layer one column at a time and updates the remaining weights to cancel each rounding error, measured on calibration inputs. The paper's maths uses the inputs' second-order statistics (a Hessian) to size the nudges.

GPTQ and AWQInference and Serving · Pro

graceful degradation

Running with fewer features instead of failing outright, decided in advance, feature by feature: a weaker model where its scores hold up, a hand-off to a person where they don't, and a clear message about what's off.

When the main model is downProduction AI

gradient

The slopes of the loss, one per weight, collected into a list. For one weight it's the single slope you just used.

Updating weights with gradientsNeural Networks · Pro

gradient accumulation

Data parallel training gives every GPU a full copy of the model and a different slice of each batch. An all-reduce sums a value across GPUs and hands every GPU the result. Gradient accumulation adds up gradients over several micro-batches before one update.

Training across many GPUsTraining and Tuning · Pro

gradient boosting

Adding small trees one after another, each fitted to what the model so far still gets wrong, and each scaled down by a learning rate before it's added. For squared error, what's left is the residuals. For other losses it's the slope (gradient) of the loss, which gives the method its name.

Random forests and gradient boostingClassical Machine Learning · Pro

gradient check

Comparing a gradient from the backward pass with an estimate from nudging, called a finite difference. They should agree to several decimal places. If they don't, the backward pass has a bug.

The chain rule by handNeural Networks · Pro

gradient descent

Gradient descent fits a model by repeated small steps: work out the gradient of the loss for every parameter, move each one a little against it, and repeat until the loss stops falling. The learning rate scales each step.

Linear regressionClassical Machine Learning

The loop: work out the gradient, move every weight a small step against its own slope, repeat. The size of the step is set by the learning rate, 0.075 above.

Updating weights with gradientsNeural Networks · Pro

GraphRAG

Retrieval over a graph built from the documents. In Microsoft Research's version, a model extracts the graph, every community gets a written summary, and questions about the whole collection (global questions) are answered from the summaries, batch by batch, then combined. Questions about particular entities (local questions) start from the matching entities and walk out from them.

Knowledge graphs and GraphRAGSearch and Retrieval · Pro

greedy decoding

Taking the top-ranked token at each step, with no dice roll. In code it's an argmax: max over the probabilities, or over the logits, since softmax keeps their order.

Turning logits into choicesTransformers · Pro

grounded answer

An answer built only from the passages in the prompt, so every claim can be traced back to one of them. The rest of this module is about making answers grounded, and checking that they are.

Answering from documentsSearch and Retrieval · Pro

group leakage

Rows from the same person (or patient, device or store) landing in both the training and the test rows, so the model is scored partly on people it has already seen. Split by group, for example with GroupKFold, to stop it.

Data leakageClassical Machine Learning · Pro

group split

A group split keeps all the rows of one customer, patient or house on the same side. A time split trains on older rows and tests on later ones, the way the model will be used: on a future it hasn't seen.

Training, validation and test setsClassical Machine Learning

group-wise quantization

One scale per output row is per-channel. One scale per fixed-size run of weights (often 128) is group-wise. Smaller groups mean finer rulers and more scales to store.

Quantizing weightsInference and Serving · Pro

grouped-query attention (GQA)

Query heads split into groups, with each group sharing one key head and one value head. With a single shared pair it's called multi-query attention (MQA), and one pair per head is multi-head attention (MHA). In the cache formula, count the key-and-value heads.

How big the cache getsInference and Serving

GRPO

An answer's reward minus the group average (here also divided by the spread) is its advantage. Group relative policy optimisation, GRPO, is the method above. DeepSeek introduced it in 2024. It needs no value model, which makes it lighter than PPO.

Rewarding checkable answersTraining and Tuning · Pro

guardrail

A criterion that must hold whatever happens to the main metric, such as "at least 90% of questions get an answer". Failing a guardrail blocks a change on its own. Some allow no failures at all: "never promise a refund the policy doesn't allow".

Specifying a good outputEvaluation

Any check your app runs around the model to keep it inside the lines: input filters, output filters, topic limits. Guardrails sit in code you control, so they keep working when the model is swapped.

Input and output filtersProduction AI · Pro

hard negative

A wrong passage that looks right: it shares the query's words, or the model already scores it high. Hard negatives are mined with BM25 or with the model itself, and added to the batch.

How embedding models are trainedTokens and Embeddings · Pro

harness

Everything around a model that turns its text into actions: the loop, the tool definitions, the system prompt, the permission checks and the choice of what goes into the context. Swap it and the same model behaves like a different agent.

The harness around a coding agentAgents · Pro

HBM

High-bandwidth memory: the stacked memory chips next to the GPU that hold the weights and KV cache. Its speed is the memory bandwidth on spec sheets, about 3.35 TB/s on an H100 SXM. The GPU also has much smaller, much faster memory on the chip itself, which good kernels use to avoid trips to HBM.

Arithmetic intensityInference and Serving · Pro

head

Each slice with its own attention is a head. Running many heads in parallel and joining their outputs is multi-head attention. The final grid that mixes them is the output projection, often written W_o.

Heads in parallelTransformers · Pro

Git's name for the commit you're on now, usually the newest commit of your branch. HEAD~1 is its parent, and HEAD~2 the commit before that.

Commits and the staging areaEngineering Toolkit

head size

The length of each head's query, key and value vectors. It's the model's width divided by its heads: 4,096 ÷ 32 = 128 for Llama 2 7B. Config files call the width hidden_size and the heads num_attention_heads, and some list head_dim directly.

How big the cache getsInference and Serving

health check

A cheap endpoint, such as GET /health, that answers 200 when the app is up. Hosts call it to decide when a new version is ready and whether a running one needs restarting.

Containers and deployingEngineering Toolkit · Pro

heavy hitters (H2O)

The tokens that have received the most attention, summed over every query so far. H2O, the Heavy-Hitter Oracle, splits each head's budget of B entries evenly between them and the most recent tokens.

Contexts that don't fitInference and Serving · Pro

held-out set

Examples kept out of training and used only to measure the model. A loss on held-out data tells you how well the model does on text it hasn't seen, which is the only kind it will meet in use.

Training a small GPT from zeroTransformers · Pro

hidden layer

A hidden layer sits between the inputs and the output. Its answers never appear in the data: the network makes up its own in-between questions, here "is either on?" and "are both on?". A forward pass is one run from inputs to output, a layer at a time.

Stacking neurons into layersNeural Networks

hill climbing

Trying one change at a time and keeping it only if the score beats the best so far. Each kept change becomes the starting point for the next.

An agent that runs experimentsAgents · Pro

HNSW

Hierarchical navigable small world: the layered neighbour graph above. Three settings matter. M is how many links each point keeps (often 16). ef_construction is how hard the build looks for good links. ef_search is how many candidates the bottom-layer search keeps in its list.

Indexes at scale with HNSWSearch and Retrieval · Pro

hook

Your own command that a coding agent runs on an event, such as just before a tool call. A hook that exits with code 2 blocks the call and tells the model why.

The harness around a coding agentAgents · Pro

host

The host is the app you use: a chat app, an IDE, an agent. It holds the conversation, calls the model, and runs one MCP client per server it connects to. A server offers tools, resources and prompts. The model only talks to the host.

MCP end to endAgents · Pro

HTTP method

The verb at the start of a request. GET reads, POST creates, PUT replaces, PATCH changes part of something and DELETE removes it.

HTTP APIs with FastAPIEngineering Toolkit · Pro

human in the loop

A person who approves a model's output before it takes effect. Here, a support agent reads every draft before it goes to a customer.

Capstone: a prompt pipeline for a support deskPrompting · Pro

hybrid model

A stack that mixes linear layers (linear attention, gated recurrences or state-space layers) with a few full-attention layers in a fixed pattern. Qwen chose 3 to 1, writing that linear attention is fast but weak at recall.

Linear attention and hybrid modelsTransformers · Pro

HyDE

Query rewriting has a model restate the user's question as one or more searches, phrased the way the documents are written. HyDE (hypothetical document embeddings) has a model draft an answer first, then searches with the draft's embedding instead of the question's. Each adds a model call before the search.

Why grounded answers still go wrongSearch and Retrieval · Pro

hyperparameter

A setting chosen before training rather than learned by it: C in logistic regression, the depth of a tree, k in k-means. Picked by comparing validation or cross-validation scores.

Cross-validation and tuningClassical Machine Learning · Pro

idempotent

An operation is idempotent if doing it twice leaves things the same as doing it once. An idempotency key is the label that lets a server turn a non-idempotent action, like a charge, into one.

Idempotency keysAgents · Pro

IDF

A word's document frequency, n, is the number of passages that contain it. Its inverse document frequency, IDF, turns that into a weight that grows as the word gets rarer. With N passages in all:

Keyword search with TF-IDF and BM25Search and Retrieval

image

A packaged, read-only filesystem (an operating system's basic files, Python, your packages and code) plus the command to start. Built from a Dockerfile, stored in a registry.

Containers and deployingEngineering Toolkit · Pro

imputation

Filling missing values with a stand-in, such as the column's median from the training rows. scikit-learn's SimpleImputer does it, and add_indicator=True adds a 0/1 column marking which rows were filled.

Preparing featuresClassical Machine Learning · Pro

in-batch negatives

In-batch negatives are the other passages in a batch, used as each query's wrong answers. The contrastive loss is the cross-entropy of picking each query's own passage (score s⁺) from its row, where Σ adds up e^s over the row. van den Oord and colleagues named it InfoNCE in 2018.

How embedding models are trainedTokens and Embeddings · Pro

in-context learning

Doing a task by following examples read in the prompt. Nothing is trained, so the skill lasts only as long as the examples stay in the prompt.

Few-shot examplesPrompting

incident commander

The one person in charge of an incident while it lasts. They keep the picture of what's happening, hand out the work, and decide; they don't do the hands-on fixing themselves.

When to page someoneProduction AI · Pro

incremental decoding

Decoding that runs only the newest token through the model at each step and reads everything earlier from the KV cache. Serving engines decode this way, and so does Hugging Face transformers unless you pass use_cache=False.

Caching keys and valuesInference and Serving

index

A sorted copy of some columns that points back at the rows, so the database can find matching rows without reading the whole table. It speeds up reads and slows down writes.

Window functions, indexes and safe queriesEngineering Toolkit · Pro

indirect prompt injection

Injection that reaches the model through material it pulls in as part of its task: a page it browses, an email it summarises, a retrieved chunk, a tool's reply. The person using the app never wrote it, and usually never sees it.

Poisoned documents and web pagesProduction AI · Pro

induction head

A head that finds an earlier copy of the current token and copies forward whatever came after it: "A B ... A" → predict "B". It needs a previous-token head in an earlier layer to work, so a model needs at least two layers to build one.

What trained heads learnTransformers · Pro

inertia

The total squared distance from each row to its centre, k-means' measure of how tight the groups are. Lower is tighter. scikit-learn reports it as inertia_.

Clustering and PCAClassical Machine Learning · Pro

input drift

Input drift is a change in what comes in: topics, length, language, kinds of user. Output drift is a change in what the model sends back: length, tone, refusals, format. Either can come with quality drift, a change in how often answers are right. That's the one that matters, and the hardest to measure.

Drift and model monitoringProduction AI · Pro

input schema

A tool definition is all the model knows of a tool: a name, a description and an input schema, the JSON Schema for its arguments. Anthropic's API calls the schema input_schema, OpenAI's parameters and MCP's inputSchema.

Designing tools a model can useAgents

instruction hardening

Writing the prompt so injected text has a harder time winning: fencing untrusted input, saying plainly that it's data, and restating the task after it. Worth doing, never enough on its own.

Defending against injectionProduction AI · Pro

instruction hierarchy

The order a model gives to instructions when they clash: the system prompt first, then the user. Text from tools, files and web pages has no authority at all. The higher one wins, on the point of the clash only.

Who outranks whom in a promptPrompting

instruction tuning (SFT)

Training a base model on request and answer pairs so it follows requests. It's also called supervised fine-tuning, or SFT. The result is an instruct model, or chat model.

Instruction tuningTraining and Tuning · Pro

inter-token latency (ITL)

The gap between two tokens in a stream. You'll also see time per output token (TPOT), which is usually the average gap over a whole reply. TPS is one second divided by that average.

First token and every token afterInference and Serving · Pro

interaction

When the effect of removing two parts together differs from the sum of removing each alone. Test pairs of parts that do similar jobs, because they're the ones most likely to hide behind each other.

AblationsEvaluation · Pro

Jaccard similarity

Shared runs divided by all the different runs is the Jaccard similarity. Comparing every pair among billions of documents is impossible, so MinHash squeezes each document's runs into a short fingerprint, and only documents whose fingerprints partly match get compared.

Building a pretraining datasetTraining and Tuning

jitter

With exponential backoff each wait is double the last, up to a ceiling. Jitter picks each wait at random below that amount ("full jitter" draws anywhere from zero up to it), so clients that failed at the same moment come back at different moments.

When a tool call failsAgents · Pro

join

Combining rows of two tables where a condition matches, usually a foreign key against a primary key. An inner join keeps matched rows only; a left join keeps every row of the first table.

SQL queries: filter, join and groupEngineering Toolkit · Pro

JSON

A text format for data: objects in {}, lists in [], strings in double quotes, numbers, true, false and null. Python's json module reads and writes it, and most APIs speak it.

HTTP APIs with FastAPIEngineering Toolkit · Pro

JSON Schema

A standard way to describe the shape of JSON: which keys, which types, which keys are required, which values are allowed (enum), and whether extra keys are forbidden (additionalProperties: false). Most model APIs accept it directly.

JSON that always parsesPrompting · Pro

k-means

Clustering that repeats two steps until nothing changes: assign each row to the nearest of k centres, then move each centre to the mean of its rows. You choose k.

Clustering and PCAClassical Machine Learning · Pro

This method. k is the number of groups you ask for. It finds groups but doesn't name them; you read a few items from each to see what it found.

Semantic search and clusteringTokens and Embeddings · Pro

key

The three roles in a soft lookup. The query is what you're asking for. Each key is what an entry offers to be matched against. Each value is what that entry hands back. Q, K and V for short.

Attention as a soft lookupTransformers

KL divergence

The KL divergence KL(p ‖ q) measures how far a distribution q is from p: 0 when they match. Distillation lowers it between the teacher's softened p and the student's softened q, times T², usually plus a small weight w on the usual loss for the true label, at T = 1.

DistillationTraining and Tuning · Pro

KL penalty

Reinforcement learning from human feedback: a reward model trained on preferences, then RL against it. The drift penalty is the KL penalty; KL divergence measures how far apart two models' probabilities are. The RL method used most often is PPO.

Learning from preferencesTraining and Tuning · Pro

knowledge graph

A triple is one fact written as (subject, relation, object), such as (Norfield Metals, supplies, brake disc). A knowledge graph is a set of triples stored as a graph: each thing (an entity) is a node, and each triple is an edge from subject to object that carries its relation, so "supplies" and "located in" are different kinds of edge.

Knowledge graphs and GraphRAGSearch and Retrieval · Pro

KS test

Tests of whether a column changed more than chance explains. The KS test (Kolmogorov-Smirnov) takes the widest gap in the share at or below each value. The chi-squared test adds up (seen − expected)² ÷ expected over the categories.

Drift and model monitoringProduction AI · Pro

KV cache

The stored keys and values of every earlier token, for every layer and every head. Prefill fills it for the prompt, and each decode step adds the newest token's keys and values.

Caching keys and valuesInference and Serving

KV cache eviction policy

The rule that decides which keys and values leave when a cache is full. Every policy loses something, since an evicted entry is gone for good. The budget sets the memory, and the policy sets what's lost.

Contexts that don't fitInference and Serving · Pro

KV cache size

What one token leaves behind, times the tokens in each request, times the number of requests. Every factor is a dial: double any one and the cache doubles.

How big the cache getsInference and Serving

KV cache usage

The share of the cache's blocks that hold some request's tokens, from 0 to 1 (vLLM's vllm:kv_cache_usage_perc). Near 1 with the preemption counter climbing means the engine admitted requests the cache can't carry to the end.

Running a model serverInference and Serving · Pro

label

A feature is a column you know at the moment you need a prediction, used as an input. The label is the column you want to predict: known for past rows, blank for new ones. Each row, features and label together, is one example.

Learning a function from examplesClassical Machine Learning

label space

The set of answers the examples allow, such as order, repair and return. With the format and the kind of input, it's much of what a few-shot prompt teaches.

Few-shot examplesPrompting

lasso

Linear regression with an L1 penalty, α times the sum of the weights' sizes. It pushes every weight towards 0 by a similar amount and sets the weakest to exactly 0, so it also picks features.

Regularisation with L1 and L2Classical Machine Learning · Pro

latency histogram

Counts of requests in fixed time buckets, kept by each server. You can add two servers' histograms bucket by bucket and read percentiles from the sum. The percentile is only as precise as the bucket it lands in.

Percentiles and the slow tailInference and Serving · Pro

layer

The result of one Dockerfile instruction, stored as a set of file changes. An image is a stack of layers, and unchanged layers are reused from the build cache.

Containers and deployingEngineering Toolkit · Pro

layer norm

That rescaling step, done on each token's vector separately. Llama models use a lighter version called RMSNorm, which skips subtracting the mean and only divides by the size.

Norm, attention, MLP, residualTransformers · Pro

leaf

A group at the bottom of a tree, where the questions stop. A classification leaf predicts its majority class, with its class shares as probabilities. A regression leaf predicts the average of its rows.

Decision treesClassical Machine Learning · Pro

learning rate

Gradient descent fits a model by repeated small steps: work out the gradient of the loss for every parameter, move each one a little against it, and repeat until the loss stops falling. The learning rate scales each step.

Linear regressionClassical Machine Learning

learning-rate schedule

How the step size changes over a run. Warmup followed by cosine decay is the most common shape. With progress running from 0 to 1 over the decay:

PretrainingTraining and Tuning

least privilege

Give the agent only the tools, and each tool only the permissions, that this task needs. The list of permitted tools is its allowlist; anything not on it is refused.

Limits on what an agent may doAgents · Pro

Give each tool, and the model behind it, only the access its job needs, and nothing more. When an injection succeeds, least privilege decides how small the damage stays.

Defending against injectionProduction AI · Pro

least squares

Least squares picks the parameters with the smallest sum of squared residuals, which is also the smallest MSE. For a line the answer has a closed form: a formula you compute directly, with no steps.

Linear regressionClassical Machine Learning

length bias

A judge's tendency to score longer answers higher whatever they say. Also called verbosity bias. Check for it by padding answers, as above, or by comparing scores for answers of different lengths that people rated equally.

How model graders are biasedEvaluation · Pro

lethal trifecta

Simon Willison's term for one model having access to private data, exposure to text an outsider could have written, and any channel that can carry data out. When a design has all three, assume injected text can steal the data. Cut one, or put a person in front of the channel out.

Poisoned documents and web pagesProduction AI · Pro

linear

A function is linear when its graph is a straight line, like w × t + b. Add linear functions, or feed one into another, and you get another linear one. An activation between layers stops the folding.

One neuronNeural Networks

linear attention

Attention whose score splits into a query part times a key part, φ(q) · φ(k), so it runs as a running sum. The softmax's e^(q · k) can't split. The state is a d × d grid per head. Katharopoulos and colleagues (2020) used φ(x) = elu(x) + 1, which keeps scores positive.

Linear attention and hybrid modelsTransformers · Pro

linear scaling rule

When the batch grows k times, multiply the learning rate by k and leave everything else alone. Reach the new rate with a gradual warmup, not a jump.

Training across many GPUsTraining and Tuning · Pro

linearly separable

A yes-or-no job is linearly separable when one straight line (or, with more inputs, one flat cut) can put every yes on one side and every no on the other. AND and OR are. XOR isn't.

Stacking neurons into layersNeural Networks

Little's law

Requests in flight = arrival rate × time each one spends inside. Written L = λ × W: L is the average number inside, λ (the Greek letter lambda) the average arrival rate, and W the average time each one spends inside. It works with averages, so the count at any one moment wobbles around L.

Throughput and Little's lawInference and Serving · Pro

LLM judge

A language model used to grade another model's output against a rubric. Also called LLM-as-a-judge. It's the usual way to score open-ended answers at scale, once you've checked it agrees with people.

Models as gradersEvaluation · Pro

load-balancing loss

An extra term in the training loss, smallest when tokens and router probability spread evenly over the experts. Also called the auxiliary loss. The Switch Transformer used α = 0.01.

Mixture of expertsTransformers · Pro

lock file

A file listing the exact version of every package, direct and transitive, so an environment can be rebuilt identically. Written by a tool, committed with the code.

Setting up a Python projectEngineering Toolkit · Pro

log loss

The average of −ln(the probability the model gave to what actually happened). 0 for a model that's always sure and always right, with no ceiling for one that's sure and wrong. Also called cross-entropy or logistic loss.

Logistic regressionClassical Machine Learning · Pro

log probability

The natural log of a token's probability, often called a logprob. 0.5 becomes about −0.69 and 0.01 becomes about −4.6. Many APIs can return logprobs for each generated token, and adding logprobs is the same as multiplying probabilities.

What a model's probabilities are worthTransformers · Pro

log-sum-exp

ln of the total of e^score over all scores, worked out as m + ln(total of e^(score − m)), with m the largest score. Same answer, no overflow. It's the second piece of the cross-entropy loss.

Backprop through softmax and cross-entropyNeural Networks · Pro

logistic regression

A weighted sum of the features passed through the sigmoid, read as the probability of the yes class. Despite the name, it's used to classify, not to predict a number.

Logistic regressionClassical Machine Learning · Pro

logits

The raw scores a network gives before they're turned into probabilities. Any size, either sign.

Backprop through softmax and cross-entropyNeural Networks · Pro

The raw scores, one per vocabulary token, before they're turned into probabilities. The grid that produces them is the output layer (also called the unembedding or LM head).

Logits and softmax over the vocabularyTransformers · Pro

long-term memory

The history in the context window is often called working memory: fast, visible to the model, small. A store that lasts across runs and is searched on demand is long-term memory.

What an agent remembersAgents · Pro

LoRA

LoRA (low-rank adaptation) trains two thin matrices, B and A, beside a frozen weight matrix. The rank r is their thin side. Ranks from 8 to 64 are common.

Adapters and LoRATraining and Tuning · Pro

loss

A loss is one number for how wrong a network is on some examples. Lower is better, and training searches for weights that make it small. Mean squared error, or MSE, is the loss you just worked out: square each error, then average.

Loss functionsNeural Networks

loss mask

The rule for which positions count toward the loss. In instruction tuning it covers the assistant's tokens only.

Instruction tuningTraining and Tuning · Pro

loss surface

The loss for every possible setting of the weights. With one weight it's a curve, with two it's a surface like a bowl, and with millions nobody can draw it. Training looks for a low spot on it.

Loss functionsNeural Networks

lost in the middle

The drop in accuracy when the needed information sits in the middle of a long prompt instead of near the start or end. Named after that 2023 paper. The pull toward the start is called primacy bias, and the pull toward the end recency bias.

Order effects in long promptsPrompting · Pro

macro average

The plain average of a metric across classes, so each class counts equally however rare it is. Accuracy (and the micro average) weight each ticket equally instead, so big classes dominate. scikit-learn's classification_report prints exactly this table, with the macro average and a weighted average underneath.

The confusion matrixEvaluation · Pro

majority label bias

Two tilts that examples add. Majority label bias pulls unsure answers toward the label most examples share. Recency bias pulls them toward the label of the last example.

Few-shot examplesPrompting

mantissa

The exponent bits pick a power of two, so they set the range: how big or how small a number can get. The mantissa bits are the digits, so they set the precision: how finely you can tell nearby numbers apart. Floating point formats differ only in how many bits go to each.

Number formatsInference and Serving · Pro

MCP server

A program or web service that offers tools, resources and prompts to an agent over the Model Context Protocol. A local one runs on your machine with your rights. Treat its descriptions and results as untrusted text.

The harness around a coding agentAgents · Pro

mean pooling

Turning many token vectors into one by averaging them, number by number. It's cheap and often decent, and it throws away word order completely.

Blind spots of cosine similarityTokens and Embeddings · Pro

mean squared error

A residual is actual minus predicted, for one row. The mean squared error, MSE, is the average of the squared residuals. Its square root is back in the label's units: a typical miss.

Linear regressionClassical Machine Learning

A loss is one number for how wrong a network is on some examples. Lower is better, and training searches for weights that make it small. Mean squared error, or MSE, is the loss you just worked out: square each error, then average.

Loss functionsNeural Networks

memory-bound

A pass is compute-bound when its arithmetic takes longer than reading its data, like prefill. It's memory-bound when reading takes longer, like decode. To tell which, compare its operations per byte with the GPU's own ratio.

Reading the prompt, writing the replyInference and Serving

merge commit

A commit with two parents, made when two branches have both moved on. It joins their histories without changing any commit that already existed.

Branches, merges and conflictsEngineering Toolkit · Pro

merge conflict

What happens when two branches changed the same lines: git stops the merge, writes both versions into the file between <<<<<<<, ======= and >>>>>>> markers, and waits for you to choose.

Branches, merges and conflictsEngineering Toolkit · Pro

merging

Adding B·A into W after training, so the tuned model is one ordinary matrix per layer with no extra cost when it runs.

Adapters and LoRATraining and Tuning · Pro

metadata filter

Fields stored next to each chunk (country, team, document type, date, who may see it), and a condition on those fields that a chunk must meet to be returned.

Filters and metadataSearch and Retrieval · Pro

metric

A metric is the number you compute, here the share of replies that pass. A threshold is the value it must reach. Both belong to a named test set: the fixed list of inputs you score on.

Specifying a good outputEvaluation

MFU

A FLOP is one floating-point operation, an add or a multiply. A run's total is its compute. MFU, model FLOPs utilisation, is the share of the hardware's peak speed a run actually gets. Careful: FLOP/s, per second, is a speed, not an amount.

Scaling lawsTraining and Tuning

MinHash

Shared runs divided by all the different runs is the Jaccard similarity. Comparing every pair among billions of documents is impossible, so MinHash squeezes each document's runs into a short fingerprint, and only documents whose fingerprints partly match get compared.

Building a pretraining datasetTraining and Tuning

misaligned instructions

An aligned instruction from a lower rung fits the higher rules, so the model follows it. A misaligned one works against them, so the model declines that part and carries on helping with the rest.

Who outranks whom in a promptPrompting

mixed precision

Storing different parts of one model in different formats, chosen by how sensitive each part is. llama.cpp's Q4_K_M files, for example, keep a few tensors at 6 bits and most at 4.

Layers that resist quantizationInference and Serving · Pro

mixed-precision quantization

Storing different parts of a model in different number formats. In an MoE, the experts hold most of the memory, so they get the fewest bits, while attention, the router and the embeddings keep more.

Serving a mixture of expertsInference and Serving · Pro

mixture of experts (MoE)

Several MLPs, the experts, plus a router that scores them for each token. Only the top k run, blended by their weights renormalised over the kept ones. It takes the place of the block's MLP.

Mixture of expertsTransformers · Pro

MLP

The per-token two-layer network inside each block, short for multilayer perceptron. Papers also call it the feed-forward network, or FFN. It holds most of a block's weights: in GPT-2 small, 2 × 768 × 3,072 ≈ 4.7 million, against about 2.4 million for attention.

Norm, attention, MLP, residualTransformers · Pro

model

A model is a function that turns features into a prediction. Its parameters are the numbers left open in it: one weight per feature, plus one on its own. Fitting, or training, sets them so the predictions on known examples come as close as they can to the labels.

Learning a function from examplesClassical Machine Learning

model bandwidth utilisation (MBU)

The bytes a decode step really reads per second (weights plus KV cache, times steps per second), divided by the GPU's peak memory bandwidth. It's the decode version of how close you are to the roof.

Reading a roofline chartInference and Serving · Pro

model registry

Experiment tracking records every training run (code, data, settings, scores) so runs can be compared and rebuilt. A model registry lists the models you've released by version, each linked to the run that made it, and marks which one is live. In MLflow, serving can load whichever version holds an alias you control, such as champion, so rolling back means moving it to the old version.

Canary, shadow and rollbackProduction AI · Pro

model router

The code that looks at each request and picks the model that answers it. Your app asks for an answer, and the router decides who gives it. Its quality is each model's accuracy on the requests it's sent, weighted by traffic.

Routing requests between modelsProduction AI

momentum

A velocity for each weight: β times the old velocity, plus the new slope. The weight moves by the learning rate times the velocity, so steady slopes count up to 1 ÷ (1 − β) times: 10 for β = 0.9. In PyTorch: torch.optim.SGD with momentum=0.9.

Momentum, Adam and learning-rate schedulesNeural Networks · Pro

MRR

Mean reciprocal rank: the average of 1 / (rank of the first relevant result) across a set of questions.

Measuring search with recall, MRR and NDCGSearch and Retrieval · Pro

multi-head attention

Each slice with its own attention is a head. Running many heads in parallel and joining their outputs is multi-head attention. The final grid that mixes them is the output projection, often written W_o.

Heads in parallelTransformers · Pro

multi-hop question

A question whose answer joins facts from two or more passages, where each fact leads to the next. Each step along a link is a hop. "Which products depend on Norfield Metals?" takes two: supplier to part, then part to product.

Knowledge graphs and GraphRAGSearch and Retrieval · Pro

multiple testing

Running many tests and paying attention to the ones that pass. The more you run, the more false winners you get. The chance of at least one across the batch is the family-wise error rate: 1 − (1 − α)ᵐ for m independent tests at level α (read "alpha", one test's false-alarm rate).

Multiple testing in experimentsEvaluation · Pro

NaN

Short for "not a number": what floating-point maths gives for things like 0 ÷ 0 or infinity minus infinity. Anything computed from a NaN is NaN too, so one bad value spreads through a whole network within a step or two.

Diagnosing a network that won't trainNeural Networks · Pro

nat

Units of surprise. −ln p is in nats. −log₂ p, read "minus log base 2 of p", is in bits. To turn nats into bits, divide by ln 2, about 0.693.

Bits per byteTokens and Embeddings · Pro

NDCG

Normalised discounted cumulative gain. Sum grade ÷ log₂(rank + 1) over the list, then divide by the same sum for the ideal order. log₂(3) is about 1.58, which is where the 0.63 for rank 2 comes from.

Measuring search with recall, MRR and NDCGSearch and Retrieval · Pro

needle in a haystack

A test that hides one fact (the needle) at a chosen depth in a long filler document (the haystack) and asks the model to find it. Run across many depths and lengths, it gives a grid of passes and misses.

Order effects in long promptsPrompting · Pro

negative log-likelihood

Minus the log of the probability a model gave to what actually happened, averaged over the data. It's the same number as the cross-entropy loss a network is trained to lower.

A bigram language modelTokens and Embeddings · Pro

nested cross-validation

Cross-validation wrapped around a search that itself uses cross-validation. The inner loop chooses the hyperparameters; the outer loop scores each choice on a fold the search never saw. It measures the procedure, not one fixed model.

Cross-validation and tuningClassical Machine Learning · Pro

next-token prediction

Guessing each token from the ones before it. It's self-supervised: the labels come from the text itself, so any text at all is training data, with nobody paid to label it.

PretrainingTraining and Tuning

noise floor

How much a score moves between runs of the same unchanged setup. A change that moves the score by less than this hasn't shown anything yet.

Fixed-budget experimentsTraining and Tuning · Pro

noisy neighbour

A customer whose heavy use slows down or blocks everyone else on shared capacity. A cap per team contains it: the bulk job just runs slower.

Spending limits per user and per teamProduction AI

normalizing

Dividing a vector by its length so its length becomes 1. The result is a unit vector. It keeps its direction and loses its size.

Cosine similarity and the dot productTokens and Embeddings · Pro

notification

MCP messages are JSON-RPC 2.0. A request has an id and a method, and gets one response with the same id, holding a result or an error. A notification has no id and gets no reply. Since 2026-07-28 only the client sends requests.

MCP end to endAgents · Pro

NULL

SQL's marker for a missing or unknown value. Any comparison with it is unknown, so test for it with IS NULL or IS NOT NULL.

SQL queries: filter, join and groupEngineering Toolkit · Pro

O(n)

Read it as "order n": grows in step with n. With a cache, a decode step does fixed weight work plus attention and reads that are O(n) in the n cached tokens. Without one, its weight work is O(n) too, and its attention, redone for every token, is O(n²).

Caching keys and valuesInference and Serving

O(n²)

Work that grows with the square of the length n. Read O(n²) aloud as "order n squared": double n and the work goes up about four times. Work that grows in step with n is linear, O(n).

The price of a long contextInference and Serving · Pro

odds

The chance something happens divided by the chance it doesn't, p ÷ (1 − p). Their natural log is the log-odds, which is the weighted sum that logistic regression adds up before the sigmoid.

Logistic regressionClassical Machine Learning · Pro

one-hot

The right answer written as a list with a 1 in its place and 0 everywhere else, like (1, 0, 0) for tea.

Backprop through softmax and cross-entropyNeural Networks · Pro

one-hot encoding

Turning a column of categories into one 0/1 column per category, so each row has a single 1. scikit-learn's OneHotEncoder does it and remembers the categories it saw in training.

Preparing featuresClassical Machine Learning · Pro

online inference

Batch inference scores every row on a schedule and stores the results for lookup. Online inference scores each request as it arrives, while the caller waits. Also called offline and real-time inference.

Capstone: a tabular model end to endClassical Machine Learning · Pro

open-ended task

A task where you can't list the steps, or say how many there will be, before you see the input. That's the case Anthropic gives for an agent. Anything else gets a workflow, or one well-prompted call.

Fixed workflow or open loopAgents

open-loop load

An open-loop test sends requests at a set arrival rate whether or not earlier ones have finished, the way real traffic does. The looping kind is closed-loop. The under-counting it causes during slowdowns is called coordinated omission.

Designing a fair benchmarkInference and Serving · Pro

orchestrator

The lead is the orchestrator (some frameworks say supervisor). Each helper is a subagent: a full agent loop started by the orchestrator, given a narrow task and a fresh context, that returns a condensed result.

Several agents on one taskAgents · Pro

out-of-bag score

A forest's score in which each row is predicted only by the trees that never trained on it. In scikit-learn, pass oob_score=True and read oob_score_ after fitting.

Random forests and gradient boostingClassical Machine Learning · Pro

out-of-fold probability

The probability a model gives an example when it was trained without that example, usually by cross-validation. Ranking examples by the probability their own label gets is the idea behind confident learning (Northcutt, Jiang and Chuang), which also sets a cut-off for each class, so a model overconfident about one class doesn't flood the list.

People as gradersEvaluation · Pro

outlier features

Hidden dimensions whose activations are consistently much larger than the rest, across tokens and layers. They are why naive INT8 activations break large models, and why newer methods look at activations before they quantize weights.

Layers that resist quantizationInference and Serving · Pro

output drift

Input drift is a change in what comes in: topics, length, language, kinds of user. Output drift is a change in what the model sends back: length, tone, refusals, format. Either can come with quality drift, a change in how often answers are right. That's the one that matters, and the hardest to measure.

Drift and model monitoringProduction AI · Pro

overfitting

Overfitting is fitting the noise in the training rows along with the pattern: training error keeps falling while error on new data rises. Underfitting is a model too simple for the pattern: error is high on training and new data alike.

Training, validation and test setsClassical Machine Learning

Training loss falling while held-out loss rises. The model is storing the examples it has seen rather than rules that work on new ones.

Training a small GPT from zeroTransformers · Pro

When a model gets better on its training data and worse on data it hasn't seen. The validation set exists to catch it. An epoch is one full pass over the training data.

A fine-tuning run end to endTraining and Tuning · Pro

overlap

A chunk is one piece of a document: the unit that gets indexed, retrieved and handed on. Chunk size is how long each chunk is, usually counted in tokens. Overlap is how much text neighbouring chunks share, so a fact near a cut still lands whole in at least one chunk. Overlap stores some text twice.

Chunk size and overlapSearch and Retrieval · Pro

overtraining

Training a model on far more than the compute-optimal 20 tokens per parameter. It costs more once, then less on every token the model serves.

Scaling lawsTraining and Tuning

p50, p95 and p99

Percentiles. p95 is the time that 95% of requests beat. p50 is the median, the typical case. The slow end of the distribution (p95, p99 and beyond) is called the tail, and the times out there are tail latency.

Percentiles and the slow tailInference and Serving · Pro

paged KV cache

Cache memory cut into fixed-size blocks and handed to a request one block at a time as it grows. A small table per request lists which blocks hold its tokens, so they don't need to sit side by side. vLLM introduced it as PagedAttention (Kwon and colleagues, 2023), with 16 tokens a block as its default.

How big the cache getsInference and Serving

paired comparison

Comparing two systems item by item on the same test set, so that only the items where they disagree carry information. It's far more sensitive than comparing two separate totals. The coin-flip check above is called a sign test (or McNemar's test).

Is the new version really betterEvaluation · Pro

pairwise

Pointwise judging scores each answer on its own. Pairwise judging shows two answers side by side and asks for a winner (or a tie). Pairwise results are reported as a win rate: the share of questions where B beat A.

Models as gradersEvaluation · Pro

parameters

A model is a function that turns features into a prediction. Its parameters are the numbers left open in it: one weight per feature, plus one on its own. Fitting, or training, sets them so the predictions on known examples come as close as they can to the labels.

Learning a function from examplesClassical Machine Learning

Every weight and every bias in a network: the numbers training changes. A layer holds its number of neurons times one more than its number of inputs.

Stacking neurons into layersNeural Networks

pass@k

pass@k ("pass at k"): the share of tasks where at least one of k runs succeeded. pass^k ("pass hat k", from the τ-bench paper): the share where all k runs succeeded. The first measures what's possible; the second measures reliability.

Scoring agentsAgents · Pro

pass^k

pass@k ("pass at k"): the share of tasks where at least one of k runs succeeded. pass^k ("pass hat k", from the τ-bench paper): the share where all k runs succeeded. The first measures what's possible; the second measures reliability.

Scoring agentsAgents · Pro

path

The working directory is the folder the shell is in now, which pwd prints. A path names a file or folder by its route. It's absolute if it starts with /, and relative to the working directory if not. .. means one level up, and ~ your home folder.

Files and folders in the shellEngineering Toolkit

per-channel quantization

One scale per output row is per-channel. One scale per fixed-size run of weights (often 128) is group-wise. Smaller groups mean finer rulers and more scales to store.

Quantizing weightsInference and Serving · Pro

perceptron

This exact machine: weights, a bias and a hard yes/no cut. Frank Rosenblatt built one in 1958. The nudge you just did is the perceptron learning rule.

Updating weights with gradientsNeural Networks · Pro

permanent errors

A transient error may clear up by itself, so waiting and trying again can work: timeouts, 429, and the 5xx family such as 500, 502, 503 and 504. A permanent error comes back the same however often you ask: a malformed request (400), something that doesn't exist (404), or missing rights (401, 403). Retry the first kind automatically; hand the second straight to the model.

When a tool call failsAgents · Pro

permutation importance

How much a model's score on held-out rows drops when you shuffle one column, which breaks its link to the label but keeps its values. A column the model doesn't really use costs nothing to shuffle. scikit-learn has it as permutation_importance.

Random forests and gradient boostingClassical Machine Learning · Pro

perplexity

The number of equally likely choices the model is, on average, picking between at each token. Here it's 4. Lower is better. Formally it's e raised to the average negative log probability of the real tokens.

What a model's probabilities are worthTransformers · Pro

The cross-entropy loss is −ln of the probability given to the right token, averaged over every position. The perplexity is e raised to that loss.

PretrainingTraining and Tuning

pipe

The | between two commands. The first command's standard output becomes the second one's input. Standard error doesn't go down the pipe: it still goes to the screen.

Pipes, variables and scriptsEngineering Toolkit

pipeline

A chain of preparation steps ending in a model, fitted and used as one object. scikit-learn's Pipeline, with ColumnTransformer for different steps on different columns, makes sure every step learns only from the rows it's fitted on.

Preparing featuresClassical Machine Learning · Pro

point-in-time correct join

Joining each training row to the latest value recorded at or before the row's own time, never after. It's also called an as-of join.

Feature stores and training-serving skewProduction AI · Pro

pointwise

Pointwise judging scores each answer on its own. Pairwise judging shows two answers side by side and asks for a winner (or a tie). Pairwise results are reported as a win rate: the share of questions where B beat A.

Models as gradersEvaluation · Pro

policy gradient

A policy gradient method changes the weights θ to raise the average reward. The simplest, REINFORCE (Williams, 1992), samples an action, scores it with a reward R, and steps along ∇ ln π(action), read "the gradient of the action's log-probability". α is the step size.

Inside the RL step: policy gradients and PPOTraining and Tuning · Pro

population stability index (PSI)

One number for how far a distribution has moved from a baseline: the sum, over groups, of the change in share times the log of the ratio of shares. Zero means no change. A rule of thumb from credit scoring: under 0.1 is small, over 0.25 is large.

Drift and model monitoringProduction AI · Pro

port publishing

Connecting a port on your machine to a port inside a container, with -p host:container. Without it, nothing outside the container can reach the app.

Containers and deployingEngineering Toolkit · Pro

position bias

A judge's habit of favouring an answer because of where it appears, not what it says. The standard fix is to judge every pair in both orders and count a pair whose winner flips with the order as a tie.

How model graders are biasedEvaluation · Pro

position embedding

A learned row for each slot in the sequence (slot 0, slot 1, and so on), summed with the token's own vector before the first block. GPT-2's table has 1,024 of these rows.

Encoding word order and RoPETransformers · Pro

post-filter

Post-filtering searches first, then drops results that fail the condition. Pre-filtering applies the condition first, then searches only what's left.

Filters and metadataSearch and Retrieval · Pro

post-training quantization (PTQ)

Quantizing a model after training, by rounding the way this lesson does, with no retraining. The alternative, quantization-aware training, lets the model practise with rounding during training, and costs a training run.

Quantizing weightsInference and Serving · Pro

PPO's clipped objective

PPO, proximal policy optimisation (Schulman and others, 2017), raises this term for each sampled token, with r its new-to-old ratio and A its advantage. The paper used ε = 0.2.

Inside the RL step: policy gradients and PPOTraining and Tuning · Pro

pre-filter

Post-filtering searches first, then drops results that fail the condition. Pre-filtering applies the condition first, then searches only what's left.

Filters and metadataSearch and Retrieval · Pro

pre-tokenization

Cutting text into chunks before BPE runs: usually a word with the space in front of it, a run of digits, or a run of punctuation. Merges only happen inside a chunk, so no token runs across two words.

Tokenizer quirks: numbers, spelling, languagesTokens and Embeddings

precision

Precision is TP ÷ (TP + FP): the share of yes answers that were right. Recall is TP ÷ (TP + FN): the share of real positives that were found. Recall is also called the true positive rate, or sensitivity.

Measuring a classifierClassical Machine Learning · Pro

You met them in "Measuring a classifier". For a check graded against your notes, precision is the share of its flags that are real, and recall is the share of real cases it flags.

Read the failures firstEvaluation

Precision is true positives ÷ everything flagged (how much to trust a flag). Recall is true positives ÷ everything really positive (how much it catches). F1 combines them as 2 × P × R ÷ (P + R), which here is 2 × 0.57 × 0.8 ÷ 1.37 = 0.67. F1 is low if either one is low.

The confusion matrixEvaluation · Pro

Recall asks: of the passages you needed, how many made it into your list? Precision asks: of the passages in your list, how many are actually useful? The first stage aims for recall. The reranker aims for precision.

RerankingSearch and Retrieval · Pro

precision-recall curve

Precision against recall, one point per threshold. More telling than ROC when positives are rare, because false alarms show at full size. Summed up by average precision, where random guessing scores the share of positives.

Measuring a classifierClassical Machine Learning · Pro

precision@k

The share of the top k that is marked relevant. Here, 1 of the top 3: about 0.33. It goes down when you pad the prompt with filler.

Measuring search with recall, MRR and NDCGSearch and Retrieval · Pro

prediction drift

A change in what a model outputs: the share it puts in each class, or the spread of its scores. It shows up the day the inputs move, long before any labels arrive.

Drift and model monitoringProduction AI · Pro

preemption

Pausing a running request to free its cache blocks for others, then running it again later. vLLM by default recomputes the dropped cache when the request comes back. The user sees their stream stop for a while, and the GPU does the prefill twice.

Continuous batchingInference and Serving · Pro

preference pair

One prompt with two answers, marked chosen and rejected. Preference data is a big pile of these, labelled by people or by another model acting as judge.

Learning from preferencesTraining and Tuning · Pro

prefill

Prefill is the first pass: it reads the whole prompt at once and produces the first reply token. Decode is everything after: one token per pass, each pass taking the token just made as its new input.

Reading the prompt, writing the replyInference and Serving

Writing the first characters of the assistant's reply yourself, after the open turn, so the model carries on from them. It fixes how a reply starts: a brace for JSON, or the first words of a set answer.

How a chat request is builtPrompting

prefix caching

Holding on to the KV cache built for the start of a prompt after its request is done, so a later request that begins with exactly the same tokens skips prefill for that part. Prefill then runs only on what's new.

Prefix cachingInference and Serving · Pro

primary key

A column whose value is different in every row, so it names exactly one row, like the id of a customer. The database refuses a second row with the same key.

SQL queries: filter, join and groupEngineering Toolkit · Pro

principal component analysis

Finding new columns that are weighted sums of the old ones, chosen in order: the first along the direction of most spread, each next one at right angles to the earlier ones and along the most spread left over. Keep the first few to describe each row with fewer numbers. Short form PCA; the new columns are the principal components.

Clustering and PCAClassical Machine Learning · Pro

projection

Multiplying a vector by a grid of weights to get a new vector, as in "the query projection". W_Q, W_K and W_V are learned in training like every other weight, and every word goes through the same three grids.

Attention as a soft lookupTransformers

prompt injection

Instructions planted in text a model reads, such as a web page, an email or a tool result, in the hope that it obeys them. The first defence is the ladder: that text is information, with no right to give orders.

Who outranks whom in a promptPrompting

Text that is supposed to be data, written so the model treats it as instructions and drops or overrides the ones you gave it. The name comes from SQL injection, where data typed into a form gets run as a database command.

How prompt injection worksProduction AI · Pro

prompt version

One fixed copy of a prompt and its settings, with a label you can point to. When an answer looks wrong, the version in the log tells you exactly which text produced it.

Treating prompts like codeEvaluation · Pro

pull request

A request on a site such as GitHub or GitLab (where it's called a merge request) to merge one branch into another, with a page for the diff, review comments and automated checks.

Rebasing, remotes and pull requestsEngineering Toolkit · Pro

Pydantic model

A Python class, based on BaseModel, whose typed fields describe valid data. Creating one from raw input converts what it can and raises a clear error for what it can't. FastAPI uses them to check requests and shape responses.

HTTP APIs with FastAPIEngineering Toolkit · Pro

QLoRA

LoRA on top of a base model whose frozen weights are stored in 4 bits. Storing numbers in fewer bits like this is called quantisation.

Adapters and LoRATraining and Tuning · Pro

quadratic cost

Work that grows with the square of the length n. Read O(n²) aloud as "order n squared": double n and the work goes up about four times. Work that grows in step with n is linear, O(n).

The price of a long contextInference and Serving · Pro

quality filter

Any step that scores documents and drops the low ones: hand-written rules, or a trained classifier. Each one removes something you didn't want, and a little you did.

Building a pretraining datasetTraining and Tuning

quantization

Storing vectors with fewer bits per number. It saves memory and speeds up comparisons, and costs some accuracy.

Indexes at scale with HNSWSearch and Retrieval · Pro

query

The three roles in a soft lookup. The query is what you're asking for. Each key is what an entry offers to be matched against. Each value is what that entry hands back. Q, K and V for short.

Attention as a soft lookupTransformers

query plan

The steps a database chooses to run a query: which tables to scan, which indexes to use, in what order. EXPLAIN QUERY PLAN in SQLite and EXPLAIN in Postgres show it.

Window functions, indexes and safe queriesEngineering Toolkit · Pro

query rewriting

Query rewriting has a model restate the user's question as one or more searches, phrased the way the documents are written. HyDE (hypothetical document embeddings) has a model draft an answer first, then searches with the draft's embedding instead of the question's. Each adds a model call before the search.

Why grounded answers still go wrongSearch and Retrieval · Pro

queue-depth autoscaling

Adding servers when the average number of requests waiting per server passes a target. The target is the wait you'll accept times what one full server finishes a second, so the rule keeps servers full with a short line.

Running a model serverInference and Serving · Pro

R²

A coefficient is the weight on one feature: how much the prediction changes when that feature rises by 1 and the others stay the same. R² is the share of the label's spread around its average that the model explains: 1 is perfect, 0 is no better than the average.

Linear regressionClassical Machine Learning

RadixAttention

SGLang's name for keeping cached prefixes in a radix tree (a tree where each branch holds a run of tokens) and matching new requests against it. vLLM's version is called automatic prefix caching.

Prefix cachingInference and Serving · Pro

RAG

Retrieval-augmented generation: answer a question by running a search first, then putting the passages it finds into the prompt beside the question, so the model writes from them. The search side is called the retriever.

Answering from documentsSearch and Retrieval · Pro

random forest

Bagged decision trees in which each split may only use a random subset of the columns. The forest's prediction is the average of its trees' predictions (for classes, the average probability).

Random forests and gradient boostingClassical Machine Learning · Pro

rank

LoRA (low-rank adaptation) trains two thin matrices, B and A, beside a frozen weight matrix. The rank r is their thin side. Ranks from 8 to 64 are common.

Adapters and LoRATraining and Tuning · Pro

reasoning model

A reasoning model is trained to write out long working before it answers. Test-time compute is what it spends while running: more thinking tokens per question. OpenAI's o1 (2024) showed accuracy rising steadily as a model was given more of it.

Rewarding checkable answersTraining and Tuning · Pro

rebase

Moving a branch's own commits so they start from a different commit, by replaying them one at a time. The changes are the same; the commits, and their ids, are new.

Rebasing, remotes and pull requestsEngineering Toolkit · Pro

recall

Precision is TP ÷ (TP + FP): the share of yes answers that were right. Recall is TP ÷ (TP + FN): the share of real positives that were found. Recall is also called the true positive rate, or sensitivity.

Measuring a classifierClassical Machine Learning · Pro

You met them in "Measuring a classifier". For a check graded against your notes, precision is the share of its flags that are real, and recall is the share of real cases it flags.

Read the failures firstEvaluation

Precision is true positives ÷ everything flagged (how much to trust a flag). Recall is true positives ÷ everything really positive (how much it catches). F1 combines them as 2 × P × R ÷ (P + R), which here is 2 × 0.57 × 0.8 ÷ 1.37 = 0.67. F1 is low if either one is low.

The confusion matrixEvaluation · Pro

Recall asks: of the passages you needed, how many made it into your list? Precision asks: of the passages in your list, how many are actually useful? The first stage aims for recall. The reranker aims for precision.

RerankingSearch and Retrieval · Pro

recall@k

The share of the right passages that appear in the top k results, averaged over the test questions. With one right passage per question, it's the share of questions whose passage made the top k.

Combining keyword and vector searchSearch and Retrieval

recency bias

Two tilts that examples add. Majority label bias pulls unsure answers toward the label most examples share. Recency bias pulls them toward the label of the last example.

Few-shot examplesPrompting

reciprocal rank fusion (RRF)

Score each passage by adding 1 ÷ (k + rank) over every list it appears in, then sort. k = 60 comes from the 2009 paper that introduced RRF, whose authors found it near the best and the exact choice not critical.

Combining keyword and vector searchSearch and Retrieval

recursive

Done to a folder and everything inside it, at every level. cp -R copies a folder this way and rm -r deletes one. cp -r works too, but the Mac's manual for cp advises -R.

Files and folders in the shellEngineering Toolkit

recursive splitting

Try the biggest natural boundary first (section breaks, then paragraphs, then sentences, then words), and only drop to a smaller one when a piece is still over the size limit. It's the usual default in text-splitting libraries, such as LangChain's RecursiveCharacterTextSplitter.

Chunk size and overlapSearch and Retrieval · Pro

reference-free evaluation

Scoring an output without a gold answer to compare against, by checking it against the input, the source documents and a rubric instead. Most evaluation of chat assistants and open-ended generation works this way.

Scoring generated textEvaluation · Pro

reflog

Your repository's private log of every commit HEAD has pointed to, newest first. It's the way back from a bad reset, rebase or branch delete. It isn't shared by push, and it can't help with changes that were never committed.

Undoing things in GitEngineering Toolkit · Pro

regression

Regression predicts a number: a rent, a delivery time, next month's sales. Classification predicts a category from a fixed list: spam or not, one of five teams. Both are supervised learning: every training example comes with its right answer, the label, attached.

Learning a function from examplesClassical Machine Learning

Something that used to work and stops working after a change. A regression test reruns old cases to check that the new version still does everything the old one did.

Treating prompts like codeEvaluation · Pro

regression eval

A test set for abilities you already had and must not lose. Run it on every new model, prompt or fine-tune, beside the eval for whatever you were trying to improve.

A fine-tuning run end to endTraining and Tuning · Pro

regularisation

Adding a charge for large weights to the score a model is fitted on, so it prefers simpler answers. Its strength, α, is a setting you choose, not a number the fit learns.

Regularisation with L1 and L2Classical Machine Learning · Pro

REINFORCE

A policy gradient method changes the weights θ to raise the average reward. The simplest, REINFORCE (Williams, 1992), samples an action, scores it with a reward R, and steps along ∇ ln π(action), read "the gradient of the action's log-probability". α is the step size.

Inside the RL step: policy gradients and PPOTraining and Tuning · Pro

rejection sampling

Accept a sample from one distribution with probability target ÷ proposal (capped at 1), and fall back to the leftover when you reject. Speculative decoding uses it so the output follows the big model's distribution exactly.

Drafting with a small modelInference and Serving · Pro

relevance

Fluency: does each sentence read as natural language? Coherence: do the sentences fit together in a sensible order? Factuality (or faithfulness, when judged against a source): is every claim supported? Relevance: does it cover what matters for the task? SummEval, a widely used study of summary scoring, had expert raters score news summaries on these four, calling factuality "consistency".

Scoring generated textEvaluation · Pro

relevance labels

The passages a person has marked as right for a question, sometimes with grades (here 2 for "answers it", 1 for "related"). A set of questions with labels is a test set, and every metric in this lesson compares a ranked list against it.

Measuring search with recall, MRR and NDCGSearch and Retrieval · Pro

ReLU

An activation function is the fixed rule a neuron applies to its total before passing it on. ReLU, short for rectified linear unit, is the one above: keep a positive total, and send out 0 for anything else.

One neuronNeural Networks

remote

Another copy of the repository that you push to and fetch from, known by a short name. origin is the usual name for the one you cloned from or first pushed to.

Rebasing, remotes and pull requestsEngineering Toolkit · Pro

remote-tracking branch

A label like origin/main that records where a branch on the remote was the last time you fetched. Only fetch, pull and push move it.

Rebasing, remotes and pull requestsEngineering Toolkit · Pro

repository

A repository is a project whose history git keeps, in a .git folder inside it. A commit is a saved snapshot of the files you added, with an author, a time, a message and a link to the commit before it.

Commits and the staging areaEngineering Toolkit

request

MCP messages are JSON-RPC 2.0. A request has an id and a method, and gets one response with the same id, holding a result or an error. A notification has no id and gets no reply. Since 2026-07-28 only the client sends requests.

MCP end to endAgents · Pro

reset

Moving the current branch back to an earlier commit. --soft keeps the changes staged, the default (mixed) keeps them in your files, and --hard throws them away.

Undoing things in GitEngineering Toolkit · Pro

residual

A residual is actual minus predicted, for one row. The mean squared error, MSE, is the average of the squared residuals. Its square root is back in the label's units: a typical miss.

Linear regressionClassical Machine Learning

residual connection

The "add the input back" path around each sublayer. The running vector that every layer reads from and adds to is called the residual stream.

Norm, attention, MLP, residualTransformers · Pro

response

MCP messages are JSON-RPC 2.0. A request has an id and a method, and gets one response with the same id, holding a result or an error. A notification has no id and gets no reply. Since 2026-07-28 only the client sends requests.

MCP end to endAgents · Pro

resumable checkpoint

Everything the next step depends on: the weights, the optimizer state, the step count, the data position and the random-number state. Restore all of it and the run continues as if it never stopped. A weights-only checkpoint is for serving, not for resuming.

Training across many GPUsTraining and Tuning · Pro

revert

A new commit that applies the opposite of an earlier one. It undoes the change without rewriting history, so it's the safe undo for shared branches.

Undoing things in GitEngineering Toolkit · Pro

reward hacking

Reward hacking is a model scoring well on the reward without doing what the reward was meant to measure. Goodhart's law is the older idea from economics: when a measure becomes a target, it stops being a good measure.

Rewarding checkable answersTraining and Tuning · Pro

An optimiser raising its score in a way that misses what the score was meant to measure, such as shrinking the test instead of improving the model. DeepMind collects examples of it under the name specification gaming. Agents are strong optimisers, so keep the score's own code out of their reach.

An agent that runs experimentsAgents · Pro

reward model

A model that reads a prompt and an answer and outputs one number, trained on preference pairs so preferred answers score higher. It stands in for a person who can't sit and judge millions of answers.

Learning from preferencesTraining and Tuning · Pro

ridge

Linear regression with an L2 penalty, α times the sum of the squared weights. It shrinks every weight towards 0 in proportion to its size, and shares weight evenly between near-copy columns.

Regularisation with L1 and L2Classical Machine Learning · Pro

ridge point

Where the slope meets the flat part: peak operations per second divided by memory bandwidth. About 296 operations per byte on an H100. Jobs to the left are memory-bound, jobs to the right compute-bound.

Reading a roofline chartInference and Serving · Pro

RLHF

Reinforcement learning from human feedback: a reward model trained on preferences, then RL against it. The drift penalty is the KL penalty; KL divergence measures how far apart two models' probabilities are. The RL method used most often is PPO.

Learning from preferencesTraining and Tuning · Pro

ROC curve

True positive rate against false positive rate, one point per threshold. The closer it hugs the top-left corner, the better the model separates the two classes. ROC stands for receiver operating characteristic, a name from early radar work.

Measuring a classifierClassical Machine Learning · Pro

rolling buffer cache

A cache of a fixed W slots. The keys and values of the token at position i go in slot i mod W (the remainder after dividing i by W), over the token W places back. The cache stops growing once the text passes W tokens.

Contexts that don't fitInference and Serving · Pro

rolling summary

A short summary of the older part of a conversation, updated as the chat grows and sent in place of those old turns. Recent turns stay word for word.

Fitting more into the windowPrompting · Pro

roofline

That picture: the best possible speed for any job, as the lower of the memory slope and the compute ceiling. It comes from a 2009 paper by Samuel Williams, Andrew Waterman and David Patterson. Any real job sits on or below the roof.

Reading a roofline chartInference and Serving · Pro

RoPE

Rotary position embedding. Queries and keys are rotated by an angle proportional to their position, so attention scores depend on the distance between tokens rather than where they sit. Real models rotate many pairs of numbers, each pair at its own speed.

Encoding word order and RoPETransformers · Pro

ROUGE

A family of scores from summarization research that measure how much of the reference shows up in the output. ROUGE-1 counts single words, as above. ROUGE-2 counts pairs of words, and ROUGE-L uses the longest run of words that appear in the same order. Libraries usually report recall, precision and F1 for each.

Overlap metrics: BLEU, ROUGE, BERTScoreEvaluation · Pro

RPM

Requests per minute and tokens per minute. Your account has both, often with input and output tokens counted apart. Whichever you run out of first is the one that throttles you.

Spending limits per user and per teamProduction AI

rubric

A scoring guide that splits quality into named parts, often called criteria or dimensions, and says how to mark each. Every grader, person or model, gets the same rubric.

RubricsEvaluation

sandbox

An isolated place to run untrusted actions, such as code the agent wrote, where the worst outcome is contained and thrown away with the sandbox.

Limits on what an agent may doAgents · Pro

saturated

A neuron pushed so far that its output sits near its limits (±1 for tanh, 0 or 1 for sigmoid) and barely moves when its total changes. Almost no gradient gets through it.

Diagnosing a network that won't trainNeural Networks · Pro

A softmax is saturated when one weight sits near 1 and the rest near 0, so changing the scores a little barely changes the weights. Almost no gradient gets back to the scores. You met the word for tanh and sigmoid neurons in Neural Networks.

Why the scores are scaledTransformers

saturation

A server is saturated when it already runs as many requests as it can hold, so every extra arrival waits. On a dashboard: running flat at its cap, waiting climbing, TTFT climbing with it, time per output token flat.

Running a model serverInference and Serving · Pro

scale

The scale is the real value of one integer step. Choosing it from the largest absolute weight, so that 0 stays at integer 0 and the range reaches equally far both ways, is symmetric quantization. Multiplying an integer by the scale to get a real number back is dequantization.

Quantizing weightsInference and Serving · Pro

scaled dot-product attention

The attention from the 2017 paper "Attention Is All You Need", and PyTorch's default. Q Kᵀ is every query dotted with every key, where Kᵀ is K turned on its side. Divide by √d, softmax each row, then multiply by V.

Why the scores are scaledTransformers

scaling law

A rule, fitted from many training runs, for how loss falls as you add parameters, data or compute. Chinchilla's version, with N parameters and D tokens:

Scaling lawsTraining and Tuning

secret

A value that grants access, such as an API key, a password or a database address with credentials in it. Kept out of code, images and repositories, and handed to the app at start time by the host.

Containers and deployingEngineering Toolkit · Pro

seed

The starting number for the random number generator. Fix the seed and the stream of u values is fixed, so the draws are too. Numbers made this way are called pseudo-random.

Seeds, reproducibility and picking settingsTransformers · Pro

self-attention

Attention where the queries, keys and values all come from the same sentence, so every word looks at every word, itself included. The weights for every pair of words form a square grid, the attention matrix, whose rows each add up to 1.

Attention as a soft lookupTransformers

self-consistency

Sampling several answers to the same question at temperature above 0 and taking a majority vote over the final answers. It trades more tokens for better accuracy on reasoning tasks.

Seeds, reproducibility and picking settingsTransformers · Pro

self-correction

A model reviewing and revising its own output. With no outside feedback it rarely helps on reasoning and can make answers worse. With feedback from a test, a compiler or another check, it's how agent loops improve.

Knowing when to stopAgents · Pro

self-preference

A judge rating outputs from its own model, or its own model family, higher than equally good outputs from others. Also called self-enhancement bias.

How model graders are biasedEvaluation · Pro

semantic cache

A cache that matches on meaning (embedding similarity above a threshold) instead of exact text. It catches far more repeats than an exact cache, and it can be wrong.

Exact and semantic cachesProduction AI · Pro

semantic chunking

Cutting where the similarity between neighbouring sentences drops, so each chunk stays on one topic. It costs an embedding per sentence at indexing time.

Chunk size and overlapSearch and Retrieval · Pro

sequence-level distillation

Fine-tuning a student on answers the teacher wrote, not on its probabilities. It needs only the teacher's text, so any model you can query can teach. Sampling several answers and keeping only those a checker passes is called rejection sampling.

DistillationTraining and Tuning · Pro

server

The host is the app you use: a chat app, an IDE, an agent. It holds the conversation, calls the model, and runs one MCP client per server it connects to. A server offers tools, resources and prompts. The model only talks to the host.

MCP end to endAgents · Pro

shadow mode

Running a new version on a copy of live traffic without showing its output. It costs you a second model call for every shadowed request, so teams often shadow a sample.

Canary, shadow and rollbackProduction AI · Pro

shared experts

Fine-grained experts are many narrow ones in place of a few wide ones, with more picked per token at the same compute. Shared experts run for every token, with no router.

Mixture of expertsTransformers · Pro

sigmoid

The S-shaped function 1 ÷ (1 + e^(−z)). It maps any number into the range 0 to 1, and sends 0 to exactly 0.5. Also called the logistic function.

Logistic regressionClassical Machine Learning · Pro

silhouette score

For each row, a is its average distance to the rest of its own cluster and b its average distance to the nearest other cluster; its silhouette is (b − a) ÷ the larger of the two. It runs from −1 to 1, and you average it over all rows. A row 2 from its own group and 8 from the next scores (8 − 2) ÷ 8 = 0.75.

Clustering and PCAClassical Machine Learning · Pro

skill

A folder with a SKILL.md file: a name and description the agent always sees, and instructions (plus any scripts or reference files) it loads only when a task matches the description.

The harness around a coding agentAgents · Pro

skip-gram with negative sampling

This version of word2vec. Skip-gram means guessing the neighbours from the middle word. Negative sampling means adding a few random fake pairs to push against, instead of scoring every word in the vocabulary each time.

The distributional hypothesisTokens and Embeddings · Pro

SLI

The SLI (service level indicator) is the measured number. The SLO (service level objective) is the target for it. The error budget is how much failure the target leaves room for. Teams often slow down releases when the budget runs low.

When to page someoneProduction AI · Pro

slice

A subset of the data picked out by something known about each input, such as a language, a kind of question or a type of customer, and scored on its own. A system can get better overall while one slice gets worse.

Read the failures firstEvaluation

sliding-window attention

Each token attends only to a fixed number of recent tokens instead of all of them. Its cache, and each step's attention work, stay a fixed size however long the text gets. Information from further back can still reach a token, but only by hopping through other tokens, layer by layer, so many models mix window layers with full-attention layers to keep a long reach.

The price of a long contextInference and Serving · Pro

SLO

Service level objective: the targets you promise, written as numbers. "TTFT under 0.5 s and token gap under 25 ms" is an SLO. Often it's stated for a percentile, such as "p99 TTFT under 0.8 s".

Goodput under errors and timeoutsInference and Serving · Pro

The SLI (service level indicator) is the measured number. The SLO (service level objective) is the target for it. The error budget is how much failure the target leaves room for. Teams often slow down releases when the budget runs low.

When to page someoneProduction AI · Pro

smoothing

Adding a small count to every cell of the table so nothing gets probability 0. The more you add, the closer every row moves to an even spread.

A bigram language modelTokens and Embeddings · Pro

snapshot date

The day a training row pretends to stand on. Features use only what was known by then, and the label comes from a fixed window after it.

Capstone: a tabular model end to endClassical Machine Learning · Pro

soft targets

The big model is the teacher, and the small one being trained is the student. The teacher's probabilities are soft targets, softened by dividing each logit z by a temperature T before the softmax. T = 1 is the usual softmax, and higher T flattens it.

DistillationTraining and Tuning · Pro

softmax

The recipe above: work out e^logit for each logit, then divide each by their total. Bigger logits get more of the probability.

Backprop through softmax and cross-entropyNeural Networks · Pro

Softmax turns scores into weights: raise e to each score, then divide by the total. Attention is the whole move: score the words, softmax the scores, then mix the words' vectors with the weights. A transformer does it for every word at once.

Context changes meaningTransformers

span

One timed unit of work inside a trace, with a parent, a start, an end and a set of attributes. OpenTelemetry's GenAI conventions give standard attribute names, such as gen_ai.request.model and gen_ai.usage.input_tokens, so different tools can read the same traces.

Traces you can debug fromAgents · Pro

special token

A chat template is the rule for flattening messages into one run of tokens: which markers open and close each message, and where the role name goes. The markers are special tokens: single tokens meant to come only from the template.

How a chat request is builtPrompting

speculative decoding

A small draft model guesses several tokens, and the big target model checks them all in one forward pass, keeping the longest run it agrees with plus one token of its own.

Drafting with a small modelInference and Serving · Pro

speedrun

A fixed target on fixed hardware, scored by the time it takes to reach it. Fixed-budget experiments fix the time and score the result. Speedruns fix the result and score the time.

Fixed-budget experimentsTraining and Tuning · Pro

split

One question at a node of a tree, of the form "feature ≤ value?". For a number column, the candidate values are midpoints between neighbouring values in the training data.

Decision treesClassical Machine Learning · Pro

SQL injection

Text from a user that changes the meaning of a query because it was pasted into the SQL. Placeholders prevent it.

Window functions, indexes and safe queriesEngineering Toolkit · Pro

staging area

The changes that go into the next commit, also called the index. git add puts a file's current version there, and git commit saves it. The files on disk, with all your edits, are the working tree.

Commits and the staging areaEngineering Toolkit

standard error

The two streams a program writes to: results to standard output (stream 1), warnings and errors to standard error (stream 2). > sends stream 1 to a file, replacing what was in it, >> adds to the end instead, and 2> sends stream 2.

Pipes, variables and scriptsEngineering Toolkit

standard output

The two streams a program writes to: results to standard output (stream 1), warnings and errors to standard error (stream 2). > sends stream 1 to a file, replacing what was in it, >> adds to the end instead, and 2> sends stream 2.

Pipes, variables and scriptsEngineering Toolkit

standardisation

Rescaling a column to average 0 and spread 1: subtract the column's mean and divide by its standard deviation, both measured on the training rows. A $95 bill, when the average is $65 and the spread is $30, becomes 1.0. scikit-learn calls it StandardScaler.

Preparing featuresClassical Machine Learning · Pro

stash

A shelf for uncommitted changes. git stash saves them and cleans the working tree, git stash list shows what's on the shelf, and git stash pop puts the newest back.

Undoing things in GitEngineering Toolkit · Pro

stateless

A model call is stateless: it depends only on what you send in that call. All memory in an agent is something your code keeps and decides to send.

What an agent remembersAgents · Pro

static batching

Form a batch, run it until every request in it is done, then form the next. Easy to build. Wasteful when output lengths vary, which for chat they always do.

Continuous batchingInference and Serving · Pro

static embedding

One fixed vector per word, learned once from a big pile of text. word2vec and GloVe both make these. "Static" because the vector stays the same whatever sentence the word is in.

The distributional hypothesisTokens and Embeddings · Pro

status code

The three-digit number at the top of an HTTP response: 2xx for success, 3xx for look elsewhere, 4xx for a problem with the request, 5xx for a problem on the server.

HTTP APIs with FastAPIEngineering Toolkit · Pro

step limit

The most loop iterations your code allows in one run. Its cousins are the token budget and the deadline. Hitting any of them is a normal, planned ending, not a crash: the run stops cleanly and reports where it got to.

Knowing when to stopAgents · Pro

stop reason

The agent loop calls the model, runs any tool it asks for, appends the call and the result, and calls again. A model running in it with tools is an agent. Each reply's stop reason says why it stopped: tool_use, end_turn or max_tokens.

Observe, decide, actAgents

stop token

A special vocabulary entry the model can pick to end its output. Also called the end-of-sequence (EOS) token. When it's picked, the loop stops and the token itself isn't shown to you.

Autoregressive generationTransformers · Pro

The special token that ends a reply: <|im_end|> for Qwen2.5, <|eot_id|> for Llama 3. The server stops generating when the model writes it. Set the wrong one, and the model writes on past the end of its reply.

How a chat request is builtPrompting

stratified k-fold

Folds built so each one holds the same share of every class as the whole dataset. scikit-learn's StratifiedKFold, and the default for classifiers in its search tools.

Cross-validation and tuningClassical Machine Learning · Pro

streaming

Sending each token (or small group of tokens) to the client as soon as it's made, instead of waiting for the full reply. HTTP APIs usually do this with server-sent events: one small message per chunk on a connection that stays open.

First token and every token afterInference and Serving · Pro

streaming text to speech

Feeding the reply to the speech engine in pieces as the model writes it, and playing audio as it comes back. Smaller pieces start sooner but can sound worse: ElevenLabs' docs say more text gives better audio.

Voice agentsAgents · Pro

StreamingLLM

A cache that keeps the first few tokens, the attention sinks, plus a rolling window of recent ones (Xiao and colleagues, 2023). Positions are counted inside the cache, not the original text. With no retraining, it kept Llama-2, MPT, Falcon and Pythia stable over 4 million tokens.

Contexts that don't fitInference and Serving · Pro

structured outputs

An API feature where you pass a JSON Schema and the reply is guaranteed to match it. It usually works by constrained decoding, which the next lesson, "Grammars that constrain decoding", takes apart. Function calling (also called tool use) runs on the same schemas, and "Letting the model call functions" covers the loop around it.

JSON that always parsesPrompting · Pro

student

The big model is the teacher, and the small one being trained is the student. The teacher's probabilities are soft targets, softened by dividing each logit z by a temperature T before the softmax. T = 1 is the usual softmax, and higher T flattens it.

DistillationTraining and Tuning · Pro

subagent

The lead is the orchestrator (some frameworks say supervisor). Each helper is a subagent: a full agent loop started by the orchestrator, given a narrow task and a fresh context, that returns a condensed result.

Several agents on one taskAgents · Pro

A helper agent with its own instructions, tool list and fresh context window. The main agent sends it a task and gets back only its final report, so the helper's reading never fills the main window.

The harness around a coding agentAgents · Pro

subword token

A token for a piece of a word, like ing or un. With bytes plus subword tokens, common words come out whole, rare words come out in pieces, and nothing is unknown.

Training a BPE tokenizerTokens and Embeddings

success criterion

A written statement of one thing a good output must do, worded so that two people checking it give the same mark. A system usually needs a few, one for each way it can fail.

Specifying a good outputEvaluation

supervised learning

Regression predicts a number: a rent, a delivery time, next month's sales. Classification predicts a category from a fixed list: spam or not, one of five teams. Both are supervised learning: every training example comes with its right answer, the label, attached.

Learning a function from examplesClassical Machine Learning

symmetric quantization

The scale is the real value of one integer step. Choosing it from the largest absolute weight, so that 0 stays at integer 0 and the range reaches equally far both ways, is symmetric quantization. Multiplying an integer by the scale to get a real number back is dequantization.

Quantizing weightsInference and Serving · Pro

symptom-based alerting

Paging on what users experience (errors, latency, broken answers) rather than on internal causes. Cause signals still matter, for finding the problem once a symptom alert has fired.

When to page someoneProduction AI · Pro

system prompt

The message you, the developer, put at the top of every request: the bot's job, its limits and its style. The customer never sees it. Anthropic's API takes it as a separate system field, and OpenAI's calls the role developer.

How a chat request is builtPrompting

system prompt extraction

Getting a model to reveal its hidden system prompt. Training makes it rarer, but a small chance per try adds up over many tries. Here p is the chance one try works and n the number of tries.

Who outranks whom in a promptPrompting

target encoding

Replacing each category with the average label for that category in the training rows, pulled toward the overall average for small categories, and computed out of fold so no row sees its own label.

Preparing featuresClassical Machine Learning · Pro

target leakage

Leakage through a feature that is filled in or changed because of the outcome: recorded after it, or by the process that handles it.

Data leakageClassical Machine Learning · Pro

task completion

Whether the output did the job it was meant to do, checked by the outcome rather than the wording. It's harder to measure than text similarity, and much closer to what users care about.

Testing a prompt changeEvaluation · Pro

Whether the run left the world in the state the task asked for, checked by code after the run: a database row, a passing test suite, a file with the right contents.

Scoring agentsAgents · Pro

teacher

The big model is the teacher, and the small one being trained is the student. The teacher's probabilities are soft targets, softened by dividing each logit z by a temperature T before the softmax. T = 1 is the usual softmax, and higher T flattens it.

DistillationTraining and Tuning · Pro

temperature

A number τ (tau) that every score is divided by before the softmax. A small τ makes the guess sharp and focuses the loss on near misses. E5 trained with τ = 0.01. The sentence-transformers library defaults to 0.05, set as its inverse, a scale of 20.

How embedding models are trainedTokens and Embeddings · Pro

Written T. Every logit is divided by T before softmax. At T = 1 the model's own probabilities come through unchanged. A smaller T widens the gaps, so the leaders gain; a bigger T narrows them, so the odds even out.

Turning logits into choicesTransformers · Pro

temperature scaling

Fitting one temperature on a held-out set so the model's confidence matches its accuracy, then using that temperature from then on. It's the same division you met in "Turning logits into choices", used to fix calibration rather than to sample.

What a model's probabilities are worthTransformers · Pro

term frequency

A word's term frequency, tf, is how many times it appears in one passage. TF-IDF scores a passage by adding up tf × IDF over the search words.

Keyword search with TF-IDF and BM25Search and Retrieval

test set

The training set is the rows a model is fitted on. The validation set is rows kept out of fitting and used to choose: which model, which degree, which settings. The test set is kept out of everything until the end, then scored once to estimate how the choice will do on new data.

Training, validation and test setsClassical Machine Learning

Examples kept out of training and used only to measure. A network can score perfectly on the examples it trained on and still fail on new ones. Only unseen examples show whether it learned the shape.

Train a classifier on your own autogradNeural Networks · Pro

A dev set (or validation set) is the data you check against while making choices. A test set is kept back and scored only for a final decision. Once choices are made by looking at a set, it has quietly become a dev set.

Multiple testing in experimentsEvaluation · Pro

test-time compute

A reasoning model is trained to write out long working before it answers. Test-time compute is what it spends while running: more thinking tokens per question. OpenAI's o1 (2024) showed accuracy rising steadily as a model was given more of it.

Rewarding checkable answersTraining and Tuning · Pro

TF-IDF

A word's term frequency, tf, is how many times it appears in one passage. TF-IDF scores a passage by adding up tf × IDF over the search words.

Keyword search with TF-IDF and BM25Search and Retrieval

three pillars

Logs, metrics and traces, the usual name for the three kinds of telemetry. Each piece inside a trace is a span, with a start time, an end time and its own details.

Logs, metrics and tracesProduction AI · Pro

threshold

A metric is the number you compute, here the share of replies that pass. A threshold is the value it must reach. Both belong to a named test set: the fixed list of inputs you score on.

Specifying a good outputEvaluation

throughput

How much work the whole server finishes per second, counted across all users. Usually given as requests per second or output tokens per second. TPS is one user's speed. Throughput is everyone's added together.

Throughput and Little's lawInference and Serving · Pro

time split

A group split keeps all the rows of one customer, patient or house on the same side. A time split trains on older rows and tests on later ones, the way the model will be used: on a future it hasn't seen.

Training, validation and test setsClassical Machine Learning

time to first audio

The time from the caller's last word to the first sound of the reply. In a pipeline it's the sum of the stages, so log each one, and watch the median and the slowest turns.

Voice agentsAgents · Pro

time to first token (TTFT)

The blank-screen wait. The clock starts when the request leaves the client and stops when the reply's first token shows up there. In the stopwatch above it's 0.6 seconds.

First token and every token afterInference and Serving · Pro

token

A token is one of the pieces a tokenizer cuts text into. The vocabulary is the fixed list of tokens it knows. A token's place on that list is its token ID, the number the model receives.

Text as bytes, bytes as tokensTokens and Embeddings

token boundary

Where one token ends and the next begins. A model gets each token as one ID, so it can see the boundaries between tokens but not the letters inside one. Tasks about letters work better when each letter is its own token.

Tokenizer quirks: numbers, spelling, languagesTokens and Embeddings

token bucket

A rate limiter with two settings: a capacity, which sets the biggest burst, and a refill rate, which sets the long-run average. Anthropic's API uses one, so its limits refill continuously instead of resetting each minute.

Spending limits per user and per teamProduction AI

token budget

A ceiling on the tokens, or the money, something may spend: one call, one task, one user per day, the whole app per month. A request that would go over is stopped, moved to a cheaper model or held until someone confirms.

Spending limits per user and per teamProduction AI

tokens per second (TPS)

How fast the reply comes out once it has started: the tokens after the first, divided by the time they took. Above, 199 tokens in 4.975 seconds is 40 TPS. Some tools quote the same thing the other way up, as milliseconds per token (25 ms here).

First token and every token afterInference and Serving · Pro

tool call

The model's reply when it wants a function run: the function's name, its arguments as a JSON object, and an id to match the answer to. Providers call the feature function calling or tool use. They mean one idea.

Letting the model call functionsPrompting · Pro

A tool call is the model's request to run a tool: a name, JSON input and an id. A tool result is your code's answer, sent back with the same id. The model only writes the call. Your code decides whether to run it.

Observe, decide, actAgents

tool definition

What you send so the model knows a tool exists: a name, a description and a JSON Schema for the arguments. Providers usually turn these into prompt text behind the scenes, so they take up room in the window like anything else.

Letting the model call functionsPrompting · Pro

A tool definition is all the model knows of a tool: a name, a description and an input schema, the JSON Schema for its arguments. Anthropic's API calls the schema input_schema, OpenAI's parameters and MCP's inputSchema.

Designing tools a model can useAgents

tool description

The plain text that tells the model what a tool does, what goes in, what comes out, and when to use a different tool. The model reads it every time it picks a tool, so it works like a prompt.

Designing tools a model can useAgents

tool execution error

A tool that ran, or checked its input, and failed. It comes back as a normal result marked as an error, isError: true in MCP or is_error: true in Anthropic's API, saying what to fix. A call that can't be routed, like an unknown tool, gets a JSON-RPC protocol error instead.

Designing tools a model can useAgents

tool poisoning

Instructions hidden in a tool's description, written for the model, not the user. A rug pull delivers them later, when a server you approved changes its tools. The host's defence: pin each definition, and ask again when it changes.

MCP end to endAgents · Pro

tool result

Your reply to a tool call: the function's output, marked with the call's id. To the model it's more prompt text, so whatever a result contains gets read, including text someone planted there (Production AI covers that in "Poisoned documents and web pages").

Letting the model call functionsPrompting · Pro

A tool call is the model's request to run a tool: a name, JSON input and an id. A tool result is your code's answer, sent back with the same id. The model only writes the call. Your code decides whether to run it.

Observe, decide, actAgents

top-k sampling

Keep only the k most likely tokens, rescale them to add up to 1, and sample from those. k = 1 is greedy decoding. The sample texts in the GPT-2 paper used k = 40, and values in the tens are common.

Cutting the tail with top-k and top-pTransformers · Pro

top-p (nucleus) sampling

Sampling from the head of the sorted list: tokens are kept from the top until their running total reaches p, the rest are dropped, and the kept ones are rescaled. The kept group is called the nucleus. It comes from Holtzman et al. (2019), the same paper that showed greedy text looping.

Cutting the tail with top-k and top-pTransformers · Pro

topological order

A list of a graph's nodes in which every node comes after all the nodes it was made from. backward() walks it in reverse.

Autograd you can step throughNeural Networks · Pro

total

Total parameters are every weight the model stores, all experts included, and set the memory. Active parameters are the weights one token uses, and set the compute per token. Qwen3-235B-A22B names both: 235B total, 22B active.

Mixture of expertsTransformers · Pro

Total parameters count every weight a model stores, and set its memory. Active parameters count the weights one token uses, the shared parts plus k experts per layer, and set its work.

Serving a mixture of expertsInference and Serving · Pro

TPM

Requests per minute and tokens per minute. Your account has both, often with input and output tokens counted apart. Whichever you run out of first is the one that throttles you.

Spending limits per user and per teamProduction AI

TPOT

The wait before a reply starts is the time to first token (TTFT), mostly prefill. The gap between later tokens is the time per output token (TPOT), one decode step. With one user on one GPU, a step can't beat the weight bytes divided by the memory bandwidth, the bytes a second the GPU can read:

Reading the prompt, writing the replyInference and Serving

trace

The full record of one run: every model call, tool call, retry and decision, in order and nested, with timings, inputs and outputs. It's the main tool for debugging an agent.

Traces you can debug fromAgents · Pro

training set

The training set is the rows a model is fitted on. The validation set is rows kept out of fitting and used to choose: which model, which degree, which settings. The test set is kept out of everything until the end, then scored once to estimate how the choice will do on new data.

Training, validation and test setsClassical Machine Learning

training-serving skew

A difference between the feature values a model trained on and the ones it gets live, for the same case. The usual cause is one feature computed by two pieces of code.

Feature stores and training-serving skewProduction AI · Pro

trajectory

The sequence of steps a run took: each model decision, tool call and result. Trajectory evaluation scores that path; outcome evaluation scores only where it ended.

Scoring agentsAgents · Pro

transaction

A group of changes the database applies all together or not at all. commit makes them permanent; an error or rollback undoes every one.

Window functions, indexes and safe queriesEngineering Toolkit · Pro

transient error

A failure caused by the provider's state at that moment, not by your request: a timeout, a 429, a 500 or a 529. Retry these. Most other 4xx errors, such as 400 and 401, mean the request or the account needs fixing.

When the main model is downProduction AI

transient errors

A transient error may clear up by itself, so waiting and trying again can work: timeouts, 429, and the 5xx family such as 500, 502, 503 and 504. A permanent error comes back the same however often you ask: a malformed request (400), something that doesn't exist (404), or missing rights (401, 403). Retry the first kind automatically; hand the second straight to the model.

When a tool call failsAgents · Pro

tree depth

The largest number of questions any row answers on its way to a leaf. Deeper trees carve finer groups, and overfit sooner. scikit-learn's max_depth caps it.

Decision treesClassical Machine Learning · Pro

triple

A triple is one fact written as (subject, relation, object), such as (Norfield Metals, supplies, brake disc). A knowledge graph is a set of triples stored as a graph: each thing (an entity) is a node, and each triple is an edge from subject to object that carries its relation, so "supplies" and "located in" are different kinds of edge.

Knowledge graphs and GraphRAGSearch and Retrieval · Pro

TTFT

The wait before a reply starts is the time to first token (TTFT), mostly prefill. The gap between later tokens is the time per output token (TPOT), one decode step. With one user on one GPU, a step can't beat the weight bytes divided by the memory bandwidth, the bytes a second the GPU can read:

Reading the prompt, writing the replyInference and Serving

underfitting

Overfitting is fitting the noise in the training rows along with the pattern: training error keeps falling while error on new data rises. Underfitting is a model too simple for the pattern: error is high on training and new data alike.

Training, validation and test setsClassical Machine Learning

unit test

A small, fast test of one function with a known input and a known answer. pytest runs every function named test_ in files named test_*.py.

Setting up a Python projectEngineering Toolkit · Pro

unsupervised learning

Learning from features alone, with no label to predict. The two common jobs are finding groups of similar rows (clustering) and finding a shorter description of the columns, as PCA does.

Clustering and PCAClassical Machine Learning · Pro

UTF-8

A byte is a whole number from 0 to 255. UTF-8 is the standard rule for writing each character as one to four bytes, and for reading them back. Nearly every web page is stored this way.

Text as bytes, bytes as tokensTokens and Embeddings

utilisation

The share of paid GPU time that does useful work. Cost per token on your own hardware is price ÷ (peak throughput × utilisation), so halving utilisation doubles what every token costs.

Pricing a single requestInference and Serving · Pro

validation set

The training set is the rows a model is fitted on. The validation set is rows kept out of fitting and used to choose: which model, which degree, which settings. The test set is kept out of everything until the end, then scored once to estimate how the choice will do on new data.

Training, validation and test setsClassical Machine Learning

value

The three roles in a soft lookup. The query is what you're asking for. Each key is what an entry offers to be matched against. Each value is what that entry hands back. Q, K and V for short.

Attention as a soft lookupTransformers

vanishing

Gradients that shrink (vanish) or grow (explode) as they pass back through many layers, because each layer scales them by a bit less, or a bit more, than 1.

Diagnosing a network that won't trainNeural Networks · Pro

variance

Bias is error that stays however often you redraw the data: the model's average answer is off, because it's too simple for the pattern. Variance is how much a model's answers change from one sample of rows to another.

Training, validation and test setsClassical Machine Learning

The spread squared. For independent random numbers, variances add when the numbers add. So a score that adds d products of variance 1 has variance d, and a spread of √d. The 2017 paper makes this argument in a footnote.

Why the scores are scaledTransformers

verifiable reward

A reward computed by a program that checks the answer: a string match, a unit test, a proof checker. Reinforcement learning on these is often called RLVR, reinforcement learning with verifiable rewards.

Rewarding checkable answersTraining and Tuning · Pro

verification gate

A check in code that must pass before a run may end as a success. It reads the real world (test results, files, database rows), not the model's description of it.

Knowing when to stopAgents · Pro

virtual environment

A folder, usually .venv, with its own Python and its own installed packages, for one project. Activating it puts it first on PATH. It's rebuilt from a list, never committed.

Setting up a Python projectEngineering Toolkit · Pro

vocabulary

A token is one of the pieces a tokenizer cuts text into. The vocabulary is the fixed list of tokens it knows. A token's place on that list is its token ID, the number the model receives.

Text as bytes, bytes as tokensTokens and Embeddings

vocabulary mismatch

When a question and the passage that answers it use different words for the same thing. To keyword search the passage has no matching words, so it scores 0 however well it answers.

Keyword search with TF-IDF and BM25Search and Retrieval

W4A16

Shorthand for a quantized setup: W for the bits per weight, A for the bits per activation. W8A8 stores weights and runs the maths in 8 bits. W4A16 stores weights in 4 bits but does the maths in 16, which cuts memory and reading time without needing 4-bit arithmetic.

Number formatsInference and Serving · Pro

W8A8

Shorthand for a quantized setup: W for the bits per weight, A for the bits per activation. W8A8 stores weights and runs the maths in 8 bits. W4A16 stores weights in 4 bits but does the maths in 16, which cuts memory and reading time without needing 4-bit arithmetic.

Number formatsInference and Serving · Pro

warm-up

Requests you send and then throw away before measuring, so one-off start-up costs don't land in your numbers. Send enough to cover the prompt lengths and batch sizes you'll test. Measure cold start separately, if it matters to you, and label it.

Designing a fair benchmarkInference and Serving · Pro

warmup

Warmup raises the rate from 0 to its peak over the first steps. Cosine decay then lowers it along half a cosine wave to a floor, as progress runs from 0 to 1. The cosine shape comes from Loshchilov and Hutter's SGDR paper (2016).

Momentum, Adam and learning-rate schedulesNeural Networks · Pro

weights

A weight sets how much one input counts, and in which direction. The bias is added at the end, so the neuron can lean one way even when every input is 0. Training is the search for good values of both.

One neuronNeural Networks

wildcard

A * (any characters, or none) or ? (exactly one character) in a file name. The shell replaces the pattern with every name that matches, in alphabetical order, before the command runs.

Files and folders in the shellEngineering Toolkit

window function

A function such as SUM, ROW_NUMBER, RANK or LAG followed by OVER (...). It computes across a group of related rows and returns a value for every row, without merging them.

Window functions, indexes and safe queriesEngineering Toolkit · Pro

winner's curse

The best of many measured results tends to overstate its true value, because it was picked partly for its luck. The more results you pick from, the bigger the overstatement.

Multiple testing in experimentsEvaluation · Pro

When you pick the best of many noisy scores, the winner's score is usually better than its true value, because it was partly picked for its luck. The more things you try, the bigger the gap.

An agent that runs experimentsAgents · Pro

word analogy

A puzzle of the form "a is to b as c is to ?", answered by b − a + c and a nearest-neighbour search. It's the classic test of whether directions in an embedding space mean something.

A tour of trained embedding spacesTokens and Embeddings · Pro

word sense

One meaning of a word: bank as a place for money, bank as a river's edge. A static embedding has one row per word, so it holds a blend of the word's senses, weighted by how often each one appears.

Context changes meaningTransformers

workflow

A workflow strings model calls and tools along a path written in your code. An agent lets the model choose each next step in a loop. Anthropic's "Building effective agents" (2024) calls both agentic systems.

Fixed workflow or open loopAgents

working directory

The working directory is the folder the shell is in now, which pwd prints. A path names a file or folder by its route. It's absolute if it starts with /, and relative to the working directory if not. .. means one level up, and ~ your home folder.

Files and folders in the shellEngineering Toolkit

working memory

The history in the context window is often called working memory: fast, visible to the model, small. A store that lasts across runs and is searched on demand is long-term memory.

What an agent remembersAgents · Pro

yes or no check

A rubric part asked as one question with a yes or no answer, such as "Does the reply ask for a password?". It gives graders one border to agree on, where a 1 to 5 scale gives four. Also called a binary or pass/fail criterion.

RubricsEvaluation

ZeRO

ZeRO (Rajbhandari and others, Microsoft, 2019) shards training state across data-parallel GPUs in three stages: Adam's state, then gradients, then weights. PyTorch's FSDP, fully sharded data parallel, is built on the same idea.

Training across many GPUsTraining and Tuning · Pro

zero point

The zero point is the integer that stands for real 0. Storing a scale and a zero point maps the real minimum and maximum onto the two ends of the integer range, so no codes go to waste. That's asymmetric quantization. Real 0 still lands exactly on an integer, so zeros come back exact.

Quantizing weightsInference and Serving · Pro

Quant engineering

adverse selection

Adverse selection is when the people who choose to trade with you are, on average, the ones who know better. The term comes from insurance. The Glosten-Milgrom model sets the ask to what you'd believe after a buy and the bid to what you'd believe after a sell. Lawrence Glosten and Paul Milgrom published it in 1985, and its spread pays for adverse selection and nothing else.

Informed tradersMarkets · Pro

alignment

Matching rows and columns by label before doing the maths is alignment. NaN, short for not a number, marks a missing value. Most pandas maths skips it or passes it through.

Tables of pricesPython for Market Data

alpha

Regress a stock's return on the market's: stock = α + β × market + e. Beta, β, is the slope: how far the stock moves on average for each 1% the market moves. Alpha, α, is the intercept: the return left once the market's part is taken out. e is the stock's own move. ρ, read "rho", is the correlation.

Beta and factor exposureStatistics and Regression · Pro

The line of expected return against beta is the security market line. A return's distance above it, what's left after paying for market risk, is its alpha. Measured over a few years, alpha is mostly noise, so it needs a standard error next to it.

CAPM and betaPortfolio and Risk · Pro

Amdahl's law

Profiling is measuring where a program spends its time. Amdahl's law puts a number on what you saw: if a step takes a share s of the run, making it infinitely fast saves at most s. A step that's 5% of the run can save you 5%, never more.

Making it fastPython for Market Data · Pro

amend

Changing an order that's already in the book. Some exchanges call it a modify, or a cancel/replace. The usual rule: cut the size and keep your place; change the price or add size and go to the back.

Order types, cancels and amendsMarkets · Pro

AR(1)

An autoregressive model of order 1: xₜ = c + φxₜ₋₁ + εₜ, read "today is a constant, plus phi times yesterday, plus a fresh shock". With |φ| below 1 it's stationary, with average μ = c / (1 − φ).

Autoregressive modelsTime Series · Pro

array

An array is numpy's block of numbers, all of one type, packed side by side. p[1:] is a slice: a stretch of the array, picked by position. Code that works on a whole array in one call is vectorised. The loop still runs, inside numpy's compiled code.

Arrays, not loopsPython for Market Data

as-of join

A join that matches each row to the most recent row at or before it in time, instead of to an equal key. pandas calls it merge_asof.

Point-in-time joinsPython for Market Data · Pro

ask

Every waiting order, sorted by price, is the order book. Waiting buy orders are bids and waiting sell orders are asks. The highest bid is the best bid and the lowest ask is the best ask.

What an exchange isMarkets

autocorrelation

The autocorrelation is the correlation of a series with itself some days earlier. The gap is the lag. ρ̂(k), read "rho hat of k", is the autocorrelation at lag k measured from data. The hat marks it as an estimate.

AutocorrelationTime Series

Avellaneda-Stoikov model

Quoting around a reservation price, with a spread made of a risk part and a fill part. Marco Avellaneda and Sasha Stoikov published it in 2008, and it's the usual starting point for quoting that accounts for inventory.

InventoryMarkets · Pro

axis

An array's shape counts its elements in each direction: (4, 3) is 4 rows and 3 columns. The axis argument says which direction a sum, mean or standard deviation runs along. That direction disappears from the shape.

Arrays, not loopsPython for Market Data

backward induction

To value a game with choices, start at the last choice, where carrying on has a known value, and work back. At each choice, take the larger of what you hold and what carrying on is worth, written max.

Expected valueProbability · Pro

base rate

How common something is before you see any evidence is its base rate, also called the prior: here 1%. The chance after the evidence is the posterior: here about 9%. Answering 90% leaves the base rate out, a mistake called base rate neglect.

Bayes' ruleProbability · Pro

basis point

The Sharpe ratio is the average daily return over its standard deviation, times √252 to make it yearly: return per unit of risk. A basis point (bp) is a hundredth of a percent, so 5 bps on each unit traded is 0.05%.

A backtest in twenty linesPython for Market Data · Pro

Bayes' rule

To turn P(B | A) into P(A | B), multiply by the prior P(A) and divide by P(B), the overall chance of the evidence. Find P(B) by splitting into cases: A happens, or it doesn't.

Bayes' ruleProbability · Pro

Updating a belief after seeing evidence: count how often the evidence turns up in each possible world, then keep only the worlds where it did. Named after Thomas Bayes, from the 1700s.

Informed tradersMarkets · Pro

beta

Regress a stock's return on the market's: stock = α + β × market + e. Beta, β, is the slope: how far the stock moves on average for each 1% the market moves. Alpha, α, is the intercept: the return left once the market's part is taken out. e is the stock's own move. ρ, read "rho", is the correlation.

Beta and factor exposureStatistics and Regression · Pro

bias-variance trade-off

Bias is how far a model's average fit sits from the truth, and variance is how much its fit moves between samples. More flexibility lowers bias and raises variance. The noise is a floor no model gets below on average.

OverfittingStatistics and Regression · Pro

bid

Every waiting order, sorted by price, is the order book. Waiting buy orders are bids and waiting sell orders are asks. The highest bid is the best bid and the lowest ask is the best ask.

What an exchange isMarkets

binomial distribution

The number of successes in n independent tries, each a success with chance p, has a binomial distribution. Its mean is n × p. Each try is a 1-or-0 score with variance p × (1 − p), and variances add, so the variance is n × p × (1 − p).

Distributions you meet dailyProbability · Pro

birthday problem

The birthday problem asks how many people make a shared birthday more likely than not. With d equally likely values, n draws are all different with the chance below, and a match passes 50% at about 1.2 × √d draws: 23 people for 365 days.

Interview puzzles, workedProbability · Pro

block bootstrap

Resampling runs of consecutive points, such as blocks of 20 days, instead of single points, so the links between neighbours survive. Use it for anything in time order: returns, signals and numbers measured over overlapping windows.

The bootstrapStatistics and Regression · Pro

Bonferroni correction

Testing each of m results at α / m, so that the chance of even one false positive stays at α or below, is the Bonferroni correction.

Multiple testingStatistics and Regression · Pro

bootstrap

Estimating how much a number would vary by recomputing it on many resamples: datasets the same size as yours, drawn from it with replacement, so each pick goes back before the next. The spread of the results is the bootstrap standard error.

The bootstrapStatistics and Regression · Pro

broadcasting

Stretching a single number across a whole array is broadcasting. The array of True and False from a comparison is a mask. r[mask] keeps the elements where the mask is True, and mask.mean() is the share that are True.

Arrays, not loopsPython for Market Data

cache miss

A cache miss is a read the cache can't serve, so the processor waits on main memory. Pointer chasing is following a chain of addresses, where each read must finish before the next can start.

Fast data structuresMarkets · Pro

call auction

A call auction collects orders for a while, then matches them all at one price, the clearing price. While orders are being collected, the book can be crossed. That's the one time a crossed book is normal.

The opening auctionMarkets · Pro

capital allocation line

The mix of risky assets with the highest Sharpe ratio sits where a line from cash just touches the curve of mixes, so it's called the tangency portfolio. The line itself, that mix blended with cash or with borrowing, is the capital allocation line.

Mean-variancePortfolio and Risk

CAPM

This is the capital asset pricing model, or CAPM. The market's expected return above cash, E[Rm] − r, is the market risk premium. In CAPM, beta is the only thing that earns a premium.

CAPM and betaPortfolio and Risk · Pro

central limit theorem

The central limit theorem says the sum or the average of many independent draws, from almost any distribution, is close to normal. The average has mean μ and standard deviation σ / √n, so z-scores and "68, 95, 99.7" apply to it.

Large numbers and the CLTProbability · Pro

clearing price

A call auction collects orders for a while, then matches them all at one price, the clearing price. While orders are being collected, the book can be crossed. That's the one time a crossed book is normal.

The opening auctionMarkets · Pro

cointegration

Two series are cointegrated when each has a unit root but some combination A − βB is stationary. β is the hedge ratio, and A − βB is the spread. Correlation is about whether daily moves line up. Cointegration is about whether the levels stay tied.

Cointegration and pairsTime Series · Pro

colocation

Tick-to-trade is the time from a market data message arriving to your order leaving in response. Colocation is renting space for your servers inside the exchange's data centre, metres from its matching engine. Kernel bypass lets your program read and write the network card directly, skipping the operating system.

Latency and speed racesMarkets · Pro

combination

A permutation is an arrangement, where order matters. A combination is a group, where it doesn't. To count combinations, count the permutations, then divide by the number of orders of one group.

Counting outcomesProbability

complement

The complement of an event is everything else: "no six" is the complement of "at least one six". P(not A), read "the chance A doesn't happen", is one minus the chance it does:

Probability is countingProbability

compounding

1 + r is the growth factor, the number the price gets multiplied by. Chaining returns by multiplying their growth factors is compounding:

Prices and returnsTime Series

conditional probability

P(A | B), read "the probability of A given B", is the chance of A once you know B happened. Count A inside B. With chances instead of counts, divide. For the dice, (2/36) / (11/36) = 2/11.

Conditional probabilityProbability

confidence interval

A confidence interval is a range built from a sample by a recipe that catches the true value a set share of the time. That share is the confidence level. For an average, at 95%:

Confidence intervalsStatistics and Regression

confidence level

The share of samples for which the interval recipe catches the truth. It describes the recipe, not any one interval. "This recipe works 95% of the time" is right. "There's a 95% chance the truth is in this range" is the common misreading.

Confidence intervalsStatistics and Regression

confounder

A confounder drives both who gets the treatment and the outcome, like order size here. Leaving one out shifts the slope by its effect on the outcome times how much it moves with the treatment: omitted-variable bias.

Cause and effectStatistics and Regression · Pro

copy

A view is a new array that shares the original's memory. A copy owns memory of its own. Slices give views; lists of positions and masks give copies.

Making it fastPython for Market Data · Pro

correlation

The correlation coefficient r, also called Pearson's r, runs from −1 to +1. +1 means the points sit exactly on a rising line, −1 exactly on a falling one, and 0 means no straight-line relation. Σ means "add up":

CorrelationStatistics and Regression · Pro

correlation matrix

A table of every pair's correlation is a correlation matrix, and its entries have to fit together. If corr(X, Y) = ρ₁ and corr(Y, Z) = ρ₂, read "rho one" and "rho two", then corr(X, Z) lies within:

CorrelationStatistics and Regression · Pro

correlogram

A correlogram is a bar chart of the autocorrelation at lags 1, 2, 3 and on. Desks draw one for returns, for their sizes, and for whatever a model leaves unexplained.

AutocorrelationTime Series

covariance

Spreading money across assets that don't move in lockstep, so that part of their swings cancel, is diversification. In the cross term, ρσAσB is the covariance of A and B, with ρ, read "rho", the correlation. A table of every pair's covariance is the covariance matrix. With a share w in A:

DiversificationPortfolio and Risk

cross-section

All the stocks on one date. A cross-sectional rank orders them against each other on that date: rank(axis=1) on a wide table, or a groupby("date") and rank() on a long one.

Ranks across stocksPython for Market Data · Pro

cross-validation

Splitting the data into k folds, fitting on k − 1 of them and testing on the one left out, then rotating so each fold is tested once. The model with the lowest average error wins. With data in time order, each test fold must come after the data it was fitted on.

OverfittingStatistics and Regression · Pro

crossing the spread

A buy priced at or above the best ask, or a sell at or below the best bid, crosses the spread and trades on arrival. An order that doesn't cross rests in the book.

Matching a tradeMarkets

data snooping

Trying many ideas on the same data and reporting the best is data snooping, also called p-hacking. The winner's own p-value comes out too small. The chance that the best of m useless tests reaches p or lower is:

Multiple testingStatistics and Regression · Pro

DataFrame

A DataFrame is pandas' table: a numpy array with labels on both edges. Its row labels are the index, here dates. One column on its own, or one row, is a Series: values with labels.

Tables of pricesPython for Market Data

demean

To demean is to subtract the cross-section's average, so each day's values add up to zero. A z-score also divides by that day's standard deviation: (x − mean) / std, read "how many standard deviations from the day's average".

Ranks across stocksPython for Market Data · Pro

depth

Depth is how many shares wait at and near the best prices. Slippage is how much worse your average price was than the best price when you started.

What an exchange isMarkets

differencing

A series with φ = 1 has a unit root. Taking day-to-day changes, Δxₜ = xₜ − xₜ₋₁, is differencing. A series that becomes stationary after differencing once is integrated of order 1, or I(1). Log prices usually behave like I(1) series.

StationarityTime Series · Pro

diversification

Spreading money across assets that don't move in lockstep, so that part of their swings cancel, is diversification. In the cross term, ρσAσB is the covariance of A and B, with ρ, read "rho", the correlation. A table of every pair's covariance is the covariance matrix. With a share w in A:

DiversificationPortfolio and Risk

drawdown

The fall from the highest value so far to the current value is the drawdown. The largest over a period is the maximum drawdown, and the time spent below an old peak is the drawdown's duration.

Measuring riskPortfolio and Risk · Pro

edge

A fair game has an expected profit of zero for both sides. Your edge is your expected profit for each 1 you stake. For a bet that pays b to 1 and wins with chance p:

Betting gamesProbability · Pro

efficient frontier

The upper edge, the most return for each level of risk, is the efficient frontier. Its left tip, the lowest-risk mix of all, is the minimum-variance portfolio. Add cash, and the steepest line from Mean-variance touches the frontier at one point: the tangency portfolio.

The efficient frontierPortfolio and Risk · Pro

eigenvalue

Multiply the covariance matrix C by a component's weights v and you get the same weights back, scaled: Cv = λv, read "C times v equals lambda times v". The weights are an eigenvector, and the scale λ is its eigenvalue, the variance along that component. Each row of the three-stock matrix adds to 0.08, so equal weights come back times 0.08.

Principal componentsStatistics and Regression · Pro

eigenvector

Multiply the covariance matrix C by a component's weights v and you get the same weights back, scaled: Cv = λv, read "C times v equals lambda times v". The weights are an eigenvector, and the scale λ is its eigenvalue, the variance along that component. Each row of the three-stock matrix adds to 0.08, so equal weights come back times 0.08.

Principal componentsStatistics and Regression · Pro

equally likely

Outcomes are equally likely when none is favoured over another, like the 36 squares of two fair dice. Only then is a chance a count over a count. Otherwise, add up the chance of each outcome in the event:

Probability is countingProbability

estimate

A number computed from a sample to stand in for a hidden one is an estimate. The sample average x̄ estimates the true average μ ("mu"), and the sample standard deviation s estimates the true one, σ ("sigma"). Σ means "add up":

Samples and estimatesStatistics and Regression

estimation error

The gap between an estimate and the truth is estimation error. Pulling noisy estimates towards a common value, such as their average, is shrinkage. It adds a little bias and removes a lot of noise.

The efficient frontierPortfolio and Risk · Pro

event

The sample space is every outcome that can happen: the 36 squares. An event is a set of outcomes you care about, such as "the total is 7". If every outcome is equally likely, P(A), read "the probability of A", is A's share of them:

Probability is countingProbability

EWMA volatility

An exponentially weighted moving average of squared returns: σ²ₜ = λσ²ₜ₋₁ + (1 − λ)r²ₜ₋₁, read "today's variance is lambda times yesterday's variance, plus one minus lambda times yesterday's squared return". The day k back gets weight (1 − λ)λᵏ⁻¹.

Volatility modelsTime Series · Pro

excess return

Return above the cash rate is excess return. Excess return divided by volatility is the Sharpe ratio, the return per unit of risk. With r the cash rate:

Risk and returnPortfolio and Risk

expected shortfall

The loss that only 1% of days go past is the 99% one-day value at risk, or VaR. The average loss on those worst 1% of days is the 99% expected shortfall, or ES. VaR is a quantile; expected shortfall is the average beyond it.

Measuring riskPortfolio and Risk · Pro

expected value

The expected value of a random amount X, written E[X], is each value times its chance, added up. Σ, read "sum", means add this up over every value. For the die, E[X] = 21/6 = 3.5. A bet's fair price is its expected value: pay that, and neither side has an edge.

Expected valueProbability · Pro

factor model

A regression of returns on several factors, each a column of returns such as the market, or cheap stocks minus expensive ones. Each slope is an exposure, also called a loading. Beta is the exposure to one factor, the market.

Beta and factor exposureStatistics and Regression · Pro

A factor model explains a return as the sum of its exposures to a few common drivers, plus a part of its own: R − r = α + β₁F₁ + β₂F₂ + … + ε. Each F is a factor's return, each β is the loading on that factor, and ε, read "epsilon", is the part left over.

Factor modelsPortfolio and Risk · Pro

factorial

n!, read "n factorial", is n × (n − 1) × … × 1, so 3! = 6 and 5! = 120. The number of groups of k things from n is C(n, k), read "n choose k":

Counting outcomesProbability

fair game

A fair game has an expected profit of zero for both sides. Your edge is your expected profit for each 1 you stake. For a bet that pays b to 1 and wins with chance p:

Betting gamesProbability · Pro

fair value

Your best estimate of what something is worth: its average outcome, given what you know. A market maker centres the quote on it. For two dice it's 7.

Make a market on a numberMarkets · Pro

false discovery rate

The expected share of false finds among the results you keep is the false discovery rate. The rule above, from Yoav Benjamini and Yosef Hochberg (1995), holds it at q: sort the m p-values, find the largest k whose p is under its bar, and keep the first k.

Multiple testingStatistics and Regression · Pro

family-wise error rate

Running many tests and paying attention to the ones that pass is multiple testing. The chance of at least one false positive across the whole family of m tests is the family-wise error rate. At level α, read "alpha", for independent tests:

Multiple testingStatistics and Regression · Pro

fill

The matching engine is the exchange's program that takes orders one at a time, matches each against the book by its priority rule, and rests what's left. Each match between the arriving order and one waiting order is a fill, with its own size and price.

Matching a tradeMarkets

first-step analysis

In first-step analysis, you condition on what the first move does, write one equation for each state you can be in, and solve them together. It answers "how long until" and "which comes first" questions, and it values games with a stopping rule.

Interview puzzles, workedProbability · Pro

forward fill

ffill() copies the last known value forward into the gaps. Give it a limit, such as ffill(limit=3), so a stock that stopped trading doesn't keep its last price for ever.

Dates and alignmentPython for Market Data

fractional Kelly

Running at a set fraction of the Kelly size, such as half, is fractional Kelly. It gives up a little growth for a large cut in drawdowns, and in the damage done by overestimating your edge.

Sizing betsPortfolio and Risk · Pro

frequent batch auction

Running a call auction every fraction of a second instead of matching continuously. Inside one batch, orders compete on price, not arrival time.

Latency and speed racesMarkets · Pro

gambler's fallacy

Believing that after a run of one outcome, the other is "due". With independent trials it never is: the chance of the next outcome is the same whatever came before.

IndependenceProbability · Pro

gambler's ruin

A walk that starts at k and stops at 0 or N is the gambler's ruin problem. With a fair coin, the chance of reaching N first is k / N, and the chance of ruin is 1 − k / N.

Random walksProbability · Pro

GARCH(1,1)

σ²ₜ = ω + αr²ₜ₋₁ + βσ²ₜ₋₁, read "today's variance is a constant, plus alpha times yesterday's squared return, plus beta times yesterday's variance". With α + β below 1, variance is pulled back to a long-run level V = ω / (1 − α − β). α + β is the persistence. EWMA is the special case ω = 0, α = 1 − λ, β = λ, with persistence exactly 1.

Volatility modelsTime Series · Pro

geometric mean

The geometric mean is the steady rate that compounds to the same end: the n-th root of the total growth factor, minus 1. Its gap below the plain average is volatility drag. Roughly, with σ the spread of the returns:

Prices and returnsTime Series

Glosten-Milgrom model

Adverse selection is when the people who choose to trade with you are, on average, the ones who know better. The term comes from insurance. The Glosten-Milgrom model sets the ask to what you'd believe after a buy and the bid to what you'd believe after a sell. Lawrence Glosten and Paul Milgrom published it in 1985, and its spread pays for adverse selection and nothing else.

Informed tradersMarkets · Pro

growth factor

1 + r is the growth factor, the number the price gets multiplied by. Chaining returns by multiplying their growth factors is compounding:

Prices and returnsTime Series

growth rate

Your growth rate is what a typical bet multiplies your money by: each result's multiplier, raised to its chance, multiplied together. Above 1, a typical player gets richer. Below 1, poorer. Staking half on the 60% coin, 10 typical flips multiply your money by 0.71, which is about 0.967 a flip. For a share f of your money on an even-money bet that wins with chance p:

Betting gamesProbability · Pro

half-life

A series pulled back toward a long-run average is mean-reverting. Its half-life is the number of days it takes, on average, to close half of any gap from that average.

Mean reversionTime Series · Pro

half-spread

A market maker keeps a bid and an ask up at the same time, so anyone can trade with them in either direction. The pair is a quote. The distance from your guess to either side (0.10 at the start) is the half-spread.

You are the market makerMarkets · Pro

hedge ratio

Two series are cointegrated when each has a unit root but some combination A − βB is stationary. β is the hedge ratio, and A − βB is the spread. Correlation is about whether daily moves line up. Cointegration is about whether the levels stay tied.

Cointegration and pairsTime Series · Pro

hitting time

The number of steps a walk takes to first reach a level is its hitting time. A fair walk that starts at k and stops at 0 or N takes this many steps on average. From the middle, d from each wall, that's d².

Random walksProbability · Pro

hot path

The hot path is the code that runs on every message. An object pool is memory set aside at start-up and handed out and taken back by your own code, so the hot path never allocates.

Fast data structuresMarkets · Pro

I(1)

A series with φ = 1 has a unit root. Taking day-to-day changes, Δxₜ = xₜ − xₜ₋₁, is differencing. A series that becomes stationary after differencing once is integrated of order 1, or I(1). Log prices usually behave like I(1) series.

StationarityTime Series · Pro

idiosyncratic risk

The shared part that diversification can't remove is systematic risk, or market risk. Each stock's own part, which cancels across many stocks, is idiosyncratic risk, or specific risk. For N stocks with equal money:

DiversificationPortfolio and Risk

.iloc

.loc picks rows and columns by label, and a label slice keeps both ends. .iloc picks by position, counting from 0, and a position slice leaves out its end, like a list.

Tables of pricesPython for Market Data

in-sample

Data used to fit a model is in-sample. Data the model never saw is out-of-sample. Walk-forward testing refits on a moving window of the past and forecasts the next stretch, again and again, so every forecast is out of sample, as it would have been in real time.

Forecasting honestlyTime Series · Pro

independent errors

Misses that say nothing about each other. The standard error assumes them. Copied rows break the assumption completely, and rows that share data break it in part. Either way the slope stays put and its standard error comes out too small.

What regression assumesStatistics and Regression · Pro

independent events

A and B are independent when knowing one happened doesn't change the chance of the other: P(B | A) = P(B). Then the multiplication rule for chances loses its condition. For the dice, 1/2 × 1/6 = 1/12, and 3 of the 36 squares are both.

IndependenceProbability · Pro

independent trials

Repeats that don't affect each other, such as rolls of a die or flips of a coin, are independent trials. If each succeeds with chance p, the chance of at least one success in n trials is one minus the chance of none:

IndependenceProbability · Pro

index

A DataFrame is pandas' table: a numpy array with labels on both edges. Its row labels are the index, here dates. One column on its own, or one row, is a Series: values with labels.

Tables of pricesPython for Market Data

indicator

A score that is 1 when something happens and 0 when it doesn't is an indicator. Its average is the chance that the thing happens. So the average number of things that happen is the sum of their chances:

Interview puzzles, workedProbability · Pro

informed traders

Traders who know something about value that you don't know yet are informed. The rest are uninformed, sometimes called noise traders. An order doesn't say which kind sent it.

You are the market makerMarkets · Pro

inner join

An outer join keeps every date from either side and fills the gaps with NaN. An inner join keeps only the dates both sides have. pd.concat([kite, wren], axis=1, join="inner") does the inner join in one step.

Dates and alignmentPython for Market Data

intensity

The plain matrix you blend towards is the shrinkage target: here, the sample's own variances with every correlation set to their average. The target's share of the blend, δ ("delta") from 0 to 1, is the shrinkage intensity.

Estimating covariancePortfolio and Risk · Pro

inventory

Your inventory is the shares you hold right now: positive when long, negative when short. Inventory risk is the chance of losing money on them while value moves. It grows with how much you hold and how far value can move.

InventoryMarkets · Pro

inventory risk

Your inventory is the shares you hold right now: positive when long, negative when short. Inventory risk is the chance of losing money on them while value moves. It grows with how much you hold and how far value can move.

InventoryMarkets · Pro

Kelly criterion

The Kelly criterion stakes the share of your money with the highest growth rate. That share is your edge divided by the payout. For a bet that pays b to 1 and wins with chance p, the best share f* (read "f star") is:

Betting gamesProbability · Pro

The size that makes wealth grow fastest over the long run is the Kelly size. For a strategy with roughly normal returns it's μ / σ², excess return over variance. For a single bet it's the share of your money to stake. Here it means $5 of positions for every $1 you own.

Sizing betsPortfolio and Risk · Pro

kernel bypass

Tick-to-trade is the time from a market data message arriving to your order leaving in response. Colocation is renting space for your servers inside the exchange's data centre, metres from its matching engine. Kernel bypass lets your program read and write the network card directly, skipping the operating system.

Latency and speed racesMarkets · Pro

kill switch

One action that cancels every order and blocks new ones. A loss limit can pull it, a health check can pull it, and so can a person. Firms test theirs, because the day they need it is a bad day to find a bug.

Risk limits and the kill switchMarkets · Pro

lasso

Regression with the penalty λΣ|b|. With uncorrelated, standardised signals it takes λ / 2 off each |Σxy|, keeps the sign and stops at zero, so a signal weaker than that drops out. It chooses signals as well as sizing them.

RegularisationStatistics and Regression · Pro

law of large numbers

The law of large numbers says the average of many independent draws settles on the expected value. The typical distance of an average of n draws from that value is its standard error, σ / √n, read "sigma over root n".

Large numbers and the CLTProbability · Pro

law of total probability

Split on what you don't know, into cases that can't overlap and that together cover everything. The chance of A is its chance in each case, weighted by how likely that case is:

Conditional probabilityProbability

least squares

A point's residual is its actual y minus the line's y: how far it sits above or below the line. For a line a + bx, least squares picks the a and b with the smallest sum of squared residuals. Fitting a line this way is linear regression, often called OLS, for ordinary least squares.

Linear regressionStatistics and Regression · Pro

least-squares line

The slope b is the covariance of x and y divided by the variance of x, and the intercept a puts the line through the point of averages. In finance, the slope of a stock's returns on the market's is the stock's beta.

Linear regressionStatistics and Regression · Pro

likelihood

How likely the evidence is under each explanation is its likelihood: 1 for the two-headed coin, 1/8 for the fair one. Odds compare two chances. In odds, Bayes' rule needs no bottom: multiply the odds by the likelihood ratio, one likelihood over the other.

Bayes' ruleProbability · Pro

limit price

The price on an order is its limit price: the worst price it will trade at. An order that trades only some of its shares gets a partial fill, and the rest waits in the book at its limit.

Matching a tradeMarkets

linearity of expectation

The expected value of a sum is the sum of the expected values, whether or not the parts are independent.

Expected valueProbability · Pro

.loc

.loc picks rows and columns by label, and a label slice keeps both ends. .iloc picks by position, counting from 0, and a position slice leaves out its end, like a list.

Tables of pricesPython for Market Data

log return

The log return is ℓ = ln(P₁ / P₀), read "the natural log of the new price over the old". Over several days, log returns add up to the log return of the whole stretch. The plain kind, P₁ / P₀ − 1, is the simple return.

Prices and returnsTime Series

log returns

A simple return is p_t / p_{t−1} − 1, read "today's price over yesterday's, minus 1". A log return is log(p_t / p_{t−1}). Log returns add up over time; simple returns add up across the stocks in a portfolio. For small daily moves the two are almost equal.

Returns and rolling windowsPython for Market Data · Pro

long

A long table has one row per observation: date, ticker, value. A wide table has one row per date and one column per ticker. pivot goes from long to wide, and melt goes back.

Tables of pricesPython for Market Data

look-ahead bias

Look-ahead bias is a test using information before it was available. A point-in-time table stores each value with the date it became known, so a join can ask: what did we know on this day?

Point-in-time joinsPython for Market Data · Pro

maker

The waiting order made the price, so its owner is the maker. The order that arrived and traded took it, so its owner is the taker.

Matching a tradeMarkets

maker-taker fees

A fee schedule that charges whoever takes liquidity and pays a rebate to whoever posted it. The rebate is the exchange paying people to keep quotes in its book.

Queue position and feesMarkets · Pro

margin of error

Two standard errors either side of an average is its margin of error: about 95% of the time, the average lands within it of the true mean. To see a gap d against a spread σ, you need the margin below d.

Large numbers and the CLTProbability · Pro

Half the width of a confidence interval is its margin of error. At 95% it's 1.96 standard errors, so it shrinks with √n: a third of the width takes nine times the data.

Confidence intervalsStatistics and Regression

mark to market

Valuing what you hold at today's value: P&L = cash + shares × value. Trading desks mark to market all day, not only when a position is closed.

Make a market on a numberMarkets · Pro

market by order

A market by price feed (often called L2) gives the total at each price. A market by order feed (often called L3) gives every order. Top of book alone is L1. Vendors use these nicknames loosely, so check what a feed contains.

Data feeds and rebuilding the bookMarkets · Pro

market by price

A market by price feed (often called L2) gives the total at each price. A market by order feed (often called L3) gives every order. Top of book alone is L1. Vendors use these nicknames loosely, so check what a feed contains.

Data feeds and rebuilding the bookMarkets · Pro

market data feed

The market data feed is the stream of messages an exchange sends for every change to its book. Each message carries a sequence number, one higher than the last. A skip means you missed something. A repeat means a copy.

Data feeds and rebuilding the bookMarkets · Pro

market maker

A market maker keeps a bid and an ask up at the same time, so anyone can trade with them in either direction. The pair is a quote. The distance from your guess to either side (0.10 at the start) is the half-spread.

You are the market makerMarkets · Pro

market risk

Market risk, also called systematic risk, is the part of a stock's variance that comes with the market: β² × σ²(market). Specific risk, or idiosyncratic risk, is the rest, σ²(e), from the stock's own moves. A market hedge removes the first and leaves the second.

Beta and factor exposureStatistics and Regression · Pro

market risk premium

This is the capital asset pricing model, or CAPM. The market's expected return above cash, E[Rm] − r, is the market risk premium. In CAPM, beta is the only thing that earns a premium.

CAPM and betaPortfolio and Risk · Pro

markout

Your queue position is how much size sits ahead of your order at its price. A markout scores a fill against value a short time later: for a buy, value later minus your price. Positive markouts mean you earned the spread. Negative ones mean someone knew more.

Queue position and feesMarkets · Pro

mask

Stretching a single number across a whole array is broadcasting. The array of True and False from a comparison is a mask. r[mask] keeps the elements where the mask is True, and mask.mean() is the share that are True.

Arrays, not loopsPython for Market Data

matching engine

The matching engine is the exchange's program that takes orders one at a time, matches each against the book by its priority rule, and rests what's left. Each match between the arriving order and one waiting order is a fill, with its own size and price.

Matching a tradeMarkets

maximum drawdown

The biggest fall from a running peak to a later low, as a share of the peak. Risk reports quote it next to volatility: it's the loss of someone who bought at the worst moment.

Arrays, not loopsPython for Market Data

mean reversion

A series pulled back toward a long-run average is mean-reverting. Its half-life is the number of days it takes, on average, to close half of any gap from that average.

Mean reversionTime Series · Pro

mean-variance weights

Choosing a portfolio by its expected return and variance alone is mean-variance optimisation. For uncorrelated assets, the best weights are in proportion to excess return over variance. With correlations, the same recipe uses the covariance matrix Σ: weights in proportion to Σ⁻¹(μ − r), read "the inverse of the covariance matrix times the excess returns".

Mean-variancePortfolio and Risk

mid

The spread is the best ask minus the best bid. The mid is halfway between them. The mid is a fair middle for valuing what you hold, but trading straight away happens at the bid or the ask.

What an exchange isMarkets

minimum-variance portfolio

The upper edge, the most return for each level of risk, is the efficient frontier. Its left tip, the lowest-risk mix of all, is the minimum-variance portfolio. Add cash, and the steepest line from Mean-variance touches the frontier at one point: the tangency portfolio.

The efficient frontierPortfolio and Risk · Pro

momentum

Momentum, or trend, is when past returns over some horizon predict future returns of the same sign. Reversal is when they predict the opposite sign. Trading in the direction of momentum is trend following.

Momentum and trendTime Series · Pro

Monty Hall problem

The Monty Hall problem is the usual name for the three doors puzzle. Its method reaches far past game shows: before you update on news, ask how the news was chosen. The same open door means different things under different rules.

Interview puzzles, workedProbability · Pro

multicollinearity

Multicollinearity means some inputs are close to a mix of the others. An input's variance inflation factor, VIF, is how many times its coefficient's variance grows compared with unrelated inputs. Its R² comes from regressing that input on the others.

Principal componentsStatistics and Regression · Pro

multiplication rule

When a choice happens in stages, and each stage has the same number of options whatever came before, the number of outcomes is the product of the options at each stage.

Counting outcomesProbability

multiplication rule for chances

The chance of both is the chance of the first, times the chance of the second given the first. It's the formula for P(B | A), turned around:

Conditional probabilityProbability

n choose k

n!, read "n factorial", is n × (n − 1) × … × 1, so 3! = 6 and 5! = 120. The number of groups of k things from n is C(n, k), read "n choose k":

Counting outcomesProbability

NaN

Matching rows and columns by label before doing the maths is alignment. NaN, short for not a number, marks a missing value. Most pandas maths skips it or passes it through.

Tables of pricesPython for Market Data

no-memory band

With n days of a series that has no memory, the autocorrelation at any lag lands inside this band 95% of the time. A bar outside it is evidence of memory.

AutocorrelationTime Series

non-synchronous returns

Two returns in one row that cover different stretches of time are non-synchronous. They make related stocks look less related. Join the prices by date, drop the days either market was shut, and only then take returns.

Dates and alignmentPython for Market Data

normal distribution

The normal distribution is the bell curve, fixed by its mean μ and standard deviation σ. The z-score of a value x counts how many standard deviations it sits from the mean. "68, 95, 99.7" covers most quick estimates.

Distributions you meet dailyProbability · Pro

null hypothesis

The dull explanation you test against is the null hypothesis: here, "the coin is fair". The p-value is the chance, if the null hypothesis were true, of a result at least as extreme as yours. A small p means surprising data.

Tests and p-valuesStatistics and Regression

object pool

The hot path is the code that runs on every message. An object pool is memory set aside at start-up and handed out and taken back by your own code, so the hot path never allocates.

Fast data structuresMarkets · Pro

odds

How likely the evidence is under each explanation is its likelihood: 1 for the two-headed coin, 1/8 for the fair one. Odds compare two chances. In odds, Bayes' rule needs no bottom: multiply the odds by the likelihood ratio, one likelihood over the other.

Bayes' ruleProbability · Pro

OHLCV bar

One row that sums up a stretch of trading: its first price (open), highest (high), lowest (low), last (close), and the total traded (volume).

ResamplingPython for Market Data · Pro

omitted-variable bias

A confounder drives both who gets the treatment and the outcome, like order size here. Leaving one out shifts the slope by its effect on the outcome times how much it moves with the treatment: omitted-variable bias.

Cause and effectStatistics and Regression · Pro

order book

Every waiting order, sorted by price, is the order book. Waiting buy orders are bids and waiting sell orders are asks. The highest bid is the best bid and the lowest ask is the best ask.

What an exchange isMarkets

order book imbalance

Bid size ÷ (bid size + ask size), at the best prices. Above 0.5 the book leans up, below 0.5 it leans down. 900 ÷ 1,000 = 0.90 leans hard up.

Reading the bookMarkets · Pro

order types

Market, limit, IOC, FOK and post-only are order types. IOC and FOK are also called time-in-force instructions, because they say how long an order may wait. Each one is a check before the matching loop or a rule after it. The loop itself doesn't change.

Order types, cancels and amendsMarkets · Pro

order-to-trade ratio

Orders sent divided by trades made. Regulators and exchanges watch it, because a flood of orders that never trade costs everyone bandwidth.

Order types, cancels and amendsMarkets · Pro

out-of-sample

Data used to fit a model is in-sample. Data the model never saw is out-of-sample. Walk-forward testing refits on a moving window of the past and forecasts the next stretch, again and again, so every forecast is out of sample, as it would have been in real time.

Forecasting honestlyTime Series · Pro

outer

An outer join keeps every date from either side and fills the gaps with NaN. An inner join keeps only the dates both sides have. pd.concat([kite, wren], axis=1, join="inner") does the inner join in one step.

Dates and alignmentPython for Market Data

outlier

A point far from the rest is an outlier. In r, a point counts by the product of its distances from the averages, so a point twice as far out on both counts four times as much. Before you trust an r, look at the scatter and ask which points are doing the work.

CorrelationStatistics and Regression · Pro

overfitting

Training error is measured on the rows a model was fitted to, and test error on rows held back. A model much better on its training rows than on test rows is overfitting: it has learned the noise. A model too simple to follow the real shape is underfitting.

OverfittingStatistics and Regression · Pro

p-value

The dull explanation you test against is the null hypothesis: here, "the coin is fair". The p-value is the chance, if the null hypothesis were true, of a result at least as extreme as yours. A small p means surprising data.

Tests and p-valuesStatistics and Regression

partial autocorrelation

The partial autocorrelation at lag k is the last coefficient, φₖ, when you fit an AR(k). It measures what k days ago adds once the days in between are known. For an AR(p) it drops to zero after lag p.

Autoregressive modelsTime Series · Pro

partial fill

The price on an order is its limit price: the worst price it will trade at. An order that trades only some of its shares gets a partial fill, and the rest waits in the book at its limit.

Matching a tradeMarkets

percentile

p99, the 99th percentile, is the time that 99% of trips beat. The slow end of the spread is the tail. Trading teams watch p99 and p99.9 at least as closely as the median, because bursts are when the market is busiest.

Latency and speed racesMarkets · Pro

percentile bootstrap interval

The middle 95% of a number's values across many resamples: sort them and set aside 2.5% at each end. It needs no formula, and it can be lopsided where the number's spread is.

The bootstrapStatistics and Regression · Pro

permutation

A permutation is an arrangement, where order matters. A combination is a group, where it doesn't. To count combinations, count the permutations, then divide by the number of orders of one group.

Counting outcomesProbability

persistence

σ²ₜ = ω + αr²ₜ₋₁ + βσ²ₜ₋₁, read "today's variance is a constant, plus alpha times yesterday's squared return, plus beta times yesterday's variance". With α + β below 1, variance is pulled back to a long-run level V = ω / (1 − α − β). α + β is the persistence. EWMA is the special case ω = 0, α = 1 − λ, β = λ, with persistence exactly 1.

Volatility modelsTime Series · Pro

point in time

Look-ahead bias is a test using information before it was available. A point-in-time table stores each value with the date it became known, so a join can ask: what did we know on this day?

Point-in-time joinsPython for Market Data · Pro

pointer chasing

A cache miss is a read the cache can't serve, so the processor waits on main memory. Pointer chasing is following a chain of addresses, where each read must finish before the next can start.

Fast data structuresMarkets · Pro

Poisson distribution

A count of independent events that arrive at a steady average rate λ has a Poisson distribution. k! is k × (k − 1) × … × 1, and 0! = 1. Its mean is λ, and so is its variance, so σ = √λ.

Distributions you meet dailyProbability · Pro

position

The signal is the rule's number at each close. The position is what you hold over the next day. In a daily backtest, today's position is yesterday's signal: pos = signal.shift(1).

A backtest in twenty linesPython for Market Data · Pro

posterior

How common something is before you see any evidence is its base rate, also called the prior: here 1%. The chance after the evidence is the posterior: here about 9%. Answering 90% leaves the base rate out, a mistake called base rate neglect.

Bayes' ruleProbability · Pro

pre-trade risk checks

Checks every order must pass before it's sent: size, price, rate and position. They stay simple and separate from the strategy, so a bug in the strategy can't switch them off. The price check is often called a price collar.

Risk limits and the kill switchMarkets · Pro

price-time priority

Best price first. At the same price, the order that arrived first trades first. The line at each price is first in, first out, or FIFO.

Price-time priorityMarkets

principal components

The first principal component is the direction, a set of weights whose squares add to 1, along which the data spreads most. Each next one spreads most at right angles to those before, one per series. Its share of the total variance is the variance it explains. Finding them is principal component analysis, PCA.

Principal componentsStatistics and Regression · Pro

prior

How common something is before you see any evidence is its base rate, also called the prior: here 1%. The chance after the evidence is the posterior: here about 9%. Answering 90% leaves the base rate out, a mistake called base rate neglect.

Bayes' ruleProbability · Pro

pro-rata

Splitting a trade among the orders at the best price in proportion to their size.

Price-time priorityMarkets

profiling

Profiling is measuring where a program spends its time. Amdahl's law puts a number on what you saw: if a step takes a share s of the run, making it infinitely fast saves at most s. A step that's 5% of the run can save you 5%, never more.

Making it fastPython for Market Data · Pro

queue position

Your queue position is how many shares wait ahead of you at your price. A trade reaches you only after it has filled all of them.

Price-time priorityMarkets

Your queue position is how much size sits ahead of your order at its price. A markout scores a fill against value a short time later: for a buy, value later minus your price. Positive markouts mean you earned the spread. Negative ones mean someone knew more.

Queue position and feesMarkets · Pro

quote

A market maker keeps a bid and an ask up at the same time, so anyone can trade with them in either direction. The pair is a quote. The distance from your guess to either side (0.10 at the start) is the half-spread.

You are the market makerMarkets · Pro

R²

R², read "R squared", is the share of y's variance the line explains: 1 minus the squared residuals over the squared distances from ȳ. It runs from 0 to 1, and with a single x it's exactly r².

Linear regressionStatistics and Regression · Pro

random walk

A random walk is a path built by adding up independent random steps. After n steps of +1 or −1 on a fair coin, its position has mean 0 and standard deviation √n.

Random walksProbability · Pro

A series where each step can't be predicted from the steps before: price today = price yesterday + a move nobody could forecast. Its returns have no memory. Asking "is this price a random walk?" asks whether past returns help predict future ones.

Random walk or notTime Series · Pro

randomised experiment

The thing whose effect you measure is the treatment, and the cases without it the control group. Handing out the treatment by chance makes a randomised experiment, an A/B test on websites and in apps. It removes selection bias on average and leaves luck.

Cause and effectStatistics and Regression · Pro

rebalancing

Trading a portfolio back to its target weights is rebalancing. For each holding, the trade is its target share of the new total minus what it holds now. A positive number means buy, and a negative one means sell.

DiversificationPortfolio and Risk

regression assumptions

The slope's standard error assumes the average of y is a straight line in x, the misses are independent of each other, and they have the same spread everywhere. A fan breaks the last one, which is called heteroscedasticity. With few rows, the misses should also be roughly normal.

What regression assumesStatistics and Regression · Pro

regression to the mean

When r is below 1, the line predicts y closer to its average, in standard deviations, than x is to its own. Francis Galton described this in 1886, in the heights of parents and their children, and the name regression comes from it.

Linear regressionStatistics and Regression · Pro

regularisation

Regularisation adds a penalty for complexity to the error a model minimises. Ridge regression penalises the sum of squared coefficients. At λ = 0 it's least squares, and as λ grows every coefficient shrinks towards zero. ŷ, read "y hat", is the model's prediction.

RegularisationStatistics and Regression · Pro

replay

A snapshot is the whole book as of a known sequence number. Replay is applying the held messages that come after it. Together they're how a book builder recovers from a big gap or a late start.

Data feeds and rebuilding the bookMarkets · Pro

resample

resample("W-FRI") groups rows into weeks ending on Friday and labels each week with that Friday. "ME" groups by calendar month and labels each with the month's last day; pandas before version 2.2 spells it "M". Then you say how to squash each group: last(), first(), mean(), max() or sum().

ResamplingPython for Market Data · Pro

reservation price

The price at which you'd be equally happy to buy one more share or sell one. Written r = s − q × γ × σ² × (T − t): the mid s, minus shares held q, times γ, times the variance still to come. With no inventory it's the mid. You centre your quote on it.

InventoryMarkets · Pro

residual

A point's residual is its actual y minus the line's y: how far it sits above or below the line. For a line a + bx, least squares picks the a and b with the smallest sum of squared residuals. Fitting a line this way is linear regression, often called OLS, for ordinary least squares.

Linear regressionStatistics and Regression · Pro

return

A return is a price change as a share of the starting price. With P₀ the starting price and P₁ the new one, r = P₁ / P₀ − 1, read "the new price over the old, minus one".

Prices and returnsTime Series

A return is the gain over a period as a share of what you started with: $100 growing to $106 is 6%. The average return is the mean of many periods' returns. Volatility is their standard deviation, the typical size of a swing around the average. Both are usually quoted per year.

Risk and returnPortfolio and Risk

reversal

Momentum, or trend, is when past returns over some horizon predict future returns of the same sign. Reversal is when they predict the opposite sign. Trading in the direction of momentum is trend following.

Momentum and trendTime Series · Pro

reverse stress test

Starting from an unacceptable loss and working back to the scenarios that would cause it is a reverse stress test.

Stress testsPortfolio and Risk · Pro

ridge

Regularisation adds a penalty for complexity to the error a model minimises. Ridge regression penalises the sum of squared coefficients. At λ = 0 it's least squares, and as λ grows every coefficient shrinks towards zero. ŷ, read "y hat", is the model's prediction.

RegularisationStatistics and Regression · Pro

risk aversion

Risk aversion, γ, is how much variance costs you. The best share in the risky mix is excess return over γ times variance. Everyone holds the same tangency mix, and only the amount differs, with the rest in cash or borrowed. That's two-fund separation: the two funds are the tangency portfolio and cash.

Mean-variancePortfolio and Risk

risk contribution

An asset's risk contribution is how much of the portfolio's variance it brings, counting how it moves with everything else. The contributions add up to the whole. Weighting assets so their contributions are equal is risk parity.

Risk parityPortfolio and Risk · Pro

risk parity

An asset's risk contribution is how much of the portfolio's variance it brings, counting how it moves with everything else. The contributions add up to the whole. Weighting assets so their contributions are equal is risk parity.

Risk parityPortfolio and Risk · Pro

rolling volatility

Rolling volatility is volatility measured over the last w days and recomputed every day as the window moves forward. w is the window's length.

Volatility clustersTime Series

rolling window

rolling(20) takes each row together with the 19 rows before it, and applies a function such as mean() or std() to those 20 values. By default it needs all 20, so the first rows are NaN. center=True moves the window so each row sits in its middle, which reads rows that come after it.

Returns and rolling windowsPython for Market Data · Pro

sample space

The sample space is every outcome that can happen: the 36 squares. An event is a set of outcomes you care about, such as "the total is 7". If every outcome is equally likely, P(A), read "the probability of A", is A's share of them:

Probability is countingProbability

scenario

A stress test asks what a portfolio would lose in a specific bad situation, a scenario, rather than on a typical bad day. A historical scenario replays the moves of a past crisis on today's positions. A hypothetical scenario is designed, such as "stocks −20%, bonds −6%".

Stress testsPortfolio and Risk · Pro

security market line

The line of expected return against beta is the security market line. A return's distance above it, what's left after paying for market risk, is its alpha. Measured over a few years, alpha is mostly noise, so it needs a standard error next to it.

CAPM and betaPortfolio and Risk · Pro

selection bias

When the cases that got a treatment differ from the rest in ways that change the outcome, the plain difference mixes the treatment's effect with that difference. The mixed-in part is selection bias. The unseen outcome, what would have happened otherwise, is the counterfactual.

Cause and effectStatistics and Regression · Pro

sequence number

The market data feed is the stream of messages an exchange sends for every change to its book. Each message carries a sequence number, one higher than the last. A skip means you missed something. A repeat means a copy.

Data feeds and rebuilding the bookMarkets · Pro

Series

A DataFrame is pandas' table: a numpy array with labels on both edges. Its row labels are the index, here dates. One column on its own, or one row, is a Series: values with labels.

Tables of pricesPython for Market Data

shape

An array's shape counts its elements in each direction: (4, 3) is 4 rows and 3 columns. The axis argument says which direction a sum, mean or standard deviation runs along. That direction disappears from the shape.

Arrays, not loopsPython for Market Data

Sharpe ratio

The Sharpe ratio is the average daily return over its standard deviation, times √252 to make it yearly: return per unit of risk. A basis point (bp) is a hundredth of a percent, so 5 bps on each unit traded is 0.05%.

A backtest in twenty linesPython for Market Data · Pro

Return above the cash rate is excess return. Excess return divided by volatility is the Sharpe ratio, the return per unit of risk. With r the cash rate:

Risk and returnPortfolio and Risk

shrinkage

Pulling noisy estimates towards zero, or another simple value, on purpose. It adds a little bias and removes more variance. The best factor is β² / (β² + SE²), where β is the true value: near 1 for a strong, well-measured effect, and small for a weak, noisy one.

RegularisationStatistics and Regression · Pro

The gap between an estimate and the truth is estimation error. Pulling noisy estimates towards a common value, such as their average, is shrinkage. It adds a little bias and removes a lot of noise.

The efficient frontierPortfolio and Risk · Pro

shrinkage target

The plain matrix you blend towards is the shrinkage target: here, the sample's own variances with every correlation set to their average. The target's share of the blend, δ ("delta") from 0 to 1, is the shrinkage intensity.

Estimating covariancePortfolio and Risk · Pro

signal

The signal is the rule's number at each close. The position is what you hold over the next day. In a daily backtest, today's position is yesterday's signal: pos = signal.shift(1).

A backtest in twenty linesPython for Market Data · Pro

significance level

The line you agree on in advance, often 5%, is the significance level. Below it, you reject the null hypothesis and call the result statistically significant. Rejecting a null hypothesis that's true is a false positive (a type I error). Missing a real effect is a false negative (a type II error).

Tests and p-valuesStatistics and Regression

simple

A simple return is p_t / p_{t−1} − 1, read "today's price over yesterday's, minus 1". A log return is log(p_t / p_{t−1}). Log returns add up over time; simple returns add up across the stocks in a portfolio. For small daily moves the two are almost equal.

Returns and rolling windowsPython for Market Data · Pro

skew

Moving both of your prices by an amount that depends on your inventory: down when you're long, up when you're short. Only the middle of the quote moves, not its width. The lab's lean per share is a skew.

InventoryMarkets · Pro

skill score

Skill = 1 − MSE(model) / MSE(baseline), read "one minus the model's mean squared error over the baseline's". Baseline error 4.0, model 3.8: skill = 1 − 0.95 = 5%. Zero means no better than the baseline, and below zero means worse. Measured out of sample against the historical average, it's called the out-of-sample R².

Forecasting honestlyTime Series · Pro

slice

An array is numpy's block of numbers, all of one type, packed side by side. p[1:] is a slice: a stretch of the array, picked by position. Code that works on a whole array in one call is vectorised. The loop still runs, inside numpy's compiled code.

Arrays, not loopsPython for Market Data

slippage

Depth is how many shares wait at and near the best prices. Slippage is how much worse your average price was than the best price when you started.

What an exchange isMarkets

snapshot

A snapshot is the whole book as of a known sequence number. Replay is applying the held messages that come after it. Together they're how a book builder recovers from a big gap or a late start.

Data feeds and rebuilding the bookMarkets · Pro

sniping

A stale quote is a resting price the news has made wrong. Sniping, or latency arbitrage, is racing to trade against stale quotes before their owners can cancel them.

Latency and speed racesMarkets · Pro

specific risk

Market risk, also called systematic risk, is the part of a stock's variance that comes with the market: β² × σ²(market). Specific risk, or idiosyncratic risk, is the rest, σ²(e), from the stock's own moves. A market hedge removes the first and leaves the second.

Beta and factor exposureStatistics and Regression · Pro

spread

Two series are cointegrated when each has a unit root but some combination A − βB is stationary. β is the hedge ratio, and A − βB is the spread. Correlation is about whether daily moves line up. Cointegration is about whether the levels stay tied.

Cointegration and pairsTime Series · Pro

The spread is the best ask minus the best bid. The mid is halfway between them. The mid is a fair middle for valuing what you hold, but trading straight away happens at the bid or the ask.

What an exchange isMarkets

square root rule

Over n independent rounds, each with mean μ and standard deviation σ, the total has mean n × μ and standard deviation √n × σ. The mean grows with n and the spread only with √n, so a real edge pulls clear of the noise in the end.

Variance and riskProbability · Pro

square-root rule

A standard error falls with the square root of the sample size. To make it k times smaller, you need k² times the data.

Samples and estimatesStatistics and Regression

square-root-of-time rule

If days are independent, the volatility over T days is the daily volatility times √T. Turned into a yearly figure this way, a volatility is annualised.

Volatility clustersTime Series

If periods are independent, the volatility over T periods is the volatility of one period times √T. A year holds about 252 trading days, so daily volatility times √252, about 15.9, gives yearly volatility. The average scales by T itself.

Risk and returnPortfolio and Risk

stale quote

A stale quote is a resting price the news has made wrong. Sniping, or latency arbitrage, is racing to trade against stale quotes before their owners can cancel them.

Latency and speed racesMarkets · Pro

standard deviation

The variance of a random amount X is the average squared gap from its mean μ (read "mu"). Its square root is the standard deviation, σ (read "sigma"), in the same units as X. Bet A has variance 2.25 and σ = 1.5.

Variance and riskProbability · Pro

standard error

The law of large numbers says the average of many independent draws settles on the expected value. The typical distance of an average of n draws from that value is its standard error, σ / √n, read "sigma over root n".

Large numbers and the CLTProbability · Pro

How far an estimate typically lands from the truth, measured as a standard deviation, is its standard error, SE for short. For an average of n independent days, each with spread σ:

Samples and estimatesStatistics and Regression

standard error of the slope

How far a fitted slope would move if you drew the data again: the leftover spread around the line, divided by the spread of x. The slope's t-statistic is b over it, read against the t number for n − 2: 3.18 for five points, close to 1.96 for a few hundred.

What regression assumesStatistics and Regression · Pro

stationary

A series is stationary when its average, its spread and its autocorrelations stay the same whichever stretch you look at. Formally, for weak stationarity: E[xₜ] = μ and Var(xₜ) = σ² for every t, and Cov(xₜ, xₜ₋ₖ) depends only on the lag k.

StationarityTime Series · Pro

stock split

When a company splits its shares, say 4 for 1, every share becomes four and the price per share drops to a quarter. Nothing of value changed. Data vendors provide split-adjusted prices that scale the history to match; research uses those, or the returns show a crash that never happened.

Plotting to thinkPython for Market Data · Pro

stress test

A stress test asks what a portfolio would lose in a specific bad situation, a scenario, rather than on a typical bad day. A historical scenario replays the moves of a past crisis on today's positions. A hypothetical scenario is designed, such as "stocks −20%, bonds −6%".

Stress testsPortfolio and Risk · Pro

subadditive

A risk measure is subadditive if the risk of two books together is never more than the sum of their separate risks. Expected shortfall always is. VaR can fail it, as here.

Measuring riskPortfolio and Risk · Pro

systematic

The shared part that diversification can't remove is systematic risk, or market risk. Each stock's own part, which cancels across many stocks, is idiosyncratic risk, or specific risk. For N stocks with equal money:

DiversificationPortfolio and Risk

t-statistic

An estimate divided by its standard error is its t-statistic. For a strategy's average return, with S the annual Sharpe ratio and T the years of daily data:

Tests and p-valuesStatistics and Regression

tail latency

p99, the 99th percentile, is the time that 99% of trips beat. The slow end of the spread is the tail. Trading teams watch p99 and p99.9 at least as closely as the median, because bursts are when the market is busiest.

Latency and speed racesMarkets · Pro

taker

The waiting order made the price, so its owner is the maker. The order that arrived and traded took it, so its owner is the taker.

Matching a tradeMarkets

tangency portfolio

The mix of risky assets with the highest Sharpe ratio sits where a line from cash just touches the curve of mixes, so it's called the tangency portfolio. The line itself, that mix blended with cash or with borrowing, is the capital allocation line.

Mean-variancePortfolio and Risk

test error

Training error is measured on the rows a model was fitted to, and test error on rows held back. A model much better on its training rows than on test rows is overfitting: it has learned the noise. A model too simple to follow the real shape is underfitting.

OverfittingStatistics and Regression · Pro

tick size

The smallest step a price can move, set by the exchange. Traders also say "tick" for one move of the price, or for a single trade. Context keeps them apart.

Fast data structuresMarkets · Pro

tick-to-trade

Tick-to-trade is the time from a market data message arriving to your order leaving in response. Colocation is renting space for your servers inside the exchange's data centre, metres from its matching engine. Kernel bypass lets your program read and write the network card directly, skipping the operating system.

Latency and speed racesMarkets · Pro

trading calendar

The days a market is open. Weekends are out everywhere, but holidays differ: New York shut on 7 September 2026 for Labor Day, and London on 31 August for its summer bank holiday. In real code, load each exchange's published calendar instead of typing holidays by hand.

Dates and alignmentPython for Market Data

training error

Training error is measured on the rows a model was fitted to, and test error on rows held back. A model much better on its training rows than on test rows is overfitting: it has learned the noise. A model too simple to follow the real shape is underfitting.

OverfittingStatistics and Regression · Pro

two-fund separation

Risk aversion, γ, is how much variance costs you. The best share in the risky mix is excess return over γ times variance. Everyone holds the same tangency mix, and only the amount differs, with the rest in cash or borrowed. That's two-fund separation: the two funds are the tangency portfolio and cash.

Mean-variancePortfolio and Risk

uncorrelated

Two variables with r = 0 are uncorrelated. Independent variables, where knowing one tells you nothing about the other, are always uncorrelated. Uncorrelated ones can still depend on each other, as long as the link isn't a straight line.

CorrelationStatistics and Regression · Pro

uninformed traders

Traders who know something about value that you don't know yet are informed. The rest are uninformed, sometimes called noise traders. An order doesn't say which kind sent it.

You are the market makerMarkets · Pro

unit root

A series with φ = 1 has a unit root. Taking day-to-day changes, Δxₜ = xₜ − xₜ₋₁, is differencing. A series that becomes stationary after differencing once is integrated of order 1, or I(1). Log prices usually behave like I(1) series.

StationarityTime Series · Pro

value at risk

The loss that only 1% of days go past is the 99% one-day value at risk, or VaR. The average loss on those worst 1% of days is the 99% expected shortfall, or ES. VaR is a quantile; expected shortfall is the average beyond it.

Measuring riskPortfolio and Risk · Pro

variance

The variance of a random amount X is the average squared gap from its mean μ (read "mu"). Its square root is the standard deviation, σ (read "sigma"), in the same units as X. Bet A has variance 2.25 and σ = 1.5.

Variance and riskProbability · Pro

variance ratio

VR(q) = Var(q-day return) / (q × Var(1-day return)), read "the variance over q days, divided by q times the daily variance". For a random walk it's 1. Above 1 suggests trending, below 1 suggests mean reversion.

Random walk or notTime Series · Pro

variance shortcut

The variance equals the average of the squares minus the square of the average. It gives the same answer as the gaps, often with less work. It also shows that E[X²] is never smaller than (E[X])², since a variance can't be negative.

Variance and riskProbability · Pro

vectorised

An array is numpy's block of numbers, all of one type, packed side by side. p[1:] is a slice: a stretch of the array, picked by position. Code that works on a whole array in one call is vectorised. The loop still runs, inside numpy's compiled code.

Arrays, not loopsPython for Market Data

view

A view is a new array that shares the original's memory. A copy owns memory of its own. Slices give views; lists of positions and masks give copies.

Making it fastPython for Market Data · Pro

VIF

Multicollinearity means some inputs are close to a mix of the others. An input's variance inflation factor, VIF, is how many times its coefficient's variance grows compared with unrelated inputs. Its R² comes from regressing that input on the others.

Principal componentsStatistics and Regression · Pro

volatility

Volatility is the standard deviation of returns: how far a return typically lands from the average. It's written σ, "sigma". Read the formula as "the square root of the squared distances from the average, added up and divided by n − 1".

Volatility clustersTime Series

A return is the gain over a period as a share of what you started with: $100 growing to $106 is 6%. The average return is the mean of many periods' returns. Volatility is their standard deviation, the typical size of a swing around the average. Both are usually quoted per year.

Risk and returnPortfolio and Risk

volatility clustering

Big moves tend to follow big moves, of either sign, and small moves tend to follow small ones. The direction of tomorrow's move stays hard to guess. Its size doesn't.

Volatility clustersTime Series

volatility drag

The geometric mean is the steady rate that compounds to the same end: the n-th root of the total growth factor, minus 1. Its gap below the plain average is volatility drag. Roughly, with σ the spread of the returns:

Prices and returnsTime Series

The rate at which the typical investor's money grows is the compound growth rate. Its gap below the average return, about half the variance, is volatility drag. For yearly returns with average μ and volatility σ, as a rule of thumb:

Risk and returnPortfolio and Risk

volatility targeting

Setting the size to a target volatility divided by a forecast volatility is volatility targeting. Forecasts often use an exponentially weighted average of past squared returns, which counts recent days most.

Sizing betsPortfolio and Risk · Pro

walk-forward

Data used to fit a model is in-sample. Data the model never saw is out-of-sample. Walk-forward testing refits on a moving window of the past and forecasts the next stretch, again and again, so every forecast is out of sample, as it would have been in real time.

Forecasting honestlyTime Series · Pro

weighted mid

The mid with each best price weighted by the size on the opposite side. Some desks call it the microprice. When the two sides are lopsided, it's a better guess of fair value than the plain mid.

Reading the bookMarkets · Pro

wide

A long table has one row per observation: date, ticker, value. A wide table has one row per date and one column per ticker. pivot goes from long to wide, and melt goes back.

Tables of pricesPython for Market Data

z-score

The normal distribution is the bell curve, fixed by its mean μ and standard deviation σ. The z-score of a value x counts how many standard deviations it sits from the mean. "68, 95, 99.7" covers most quick estimates.

Distributions you meet dailyProbability · Pro

How far a result sits from what the null hypothesis expects, measured in standard errors, is its z-score. Beyond ±1.96, p is below 0.05. Beyond ±2.576, it's below 0.01.

Tests and p-valuesStatistics and Regression

z = (spread − average) / standard deviation, read "how many standard deviations the spread sits from its average". Spread 3.1, average 2.5, standard deviation 0.3: z = 0.6 / 0.3 = 2.0.

Cointegration and pairsTime Series · Pro

To demean is to subtract the cross-section's average, so each day's values add up to zero. A z-score also divides by that day's standard deviation: (x − mean) / std, read "how many standard deviations from the day's average".

Ranks across stocksPython for Market Data · Pro