The open notebook / 97 notes

Everything is connected.

Machine learning, from first principles to production. Browse the index or follow a thread through the atlas.

All notes · Recent first 97
01 · Core Concepts

Loss Functions

where $d$ = distance between an embedding pair, $y=1$ if dissimilar, $m$ = margin.

  • Training
  • Optimization
  • Deep Learning
  • Evaluation
  • Linear Models
01 · Core Concepts

NDCG

NDCG measures ranking quality by checking whether highly relevant items appear near the top of a ranked list. It is computed in three steps: DCG → IDCG → normalize.

  • Optimization
  • Training
  • Evaluation
01 · Core Concepts

Activation Functions and Optimizers

Without activation functions, a neural network — no matter how deep — collapses into a single linear transformation. Stacking linear layers gives you another linear function:

  • Optimization
  • Training
  • Deep Learning
  • Evaluation
  • Supervised Learning
02 · Recommendation Systems

Multi-Label vs Multi-Task vs Multi-Task Multi-Label

Most confusion comes from treating these as three points on one line. They are not. There are two independent questions:

  • Ranking
  • Recommendation
  • Training
  • Vision
  • Serving
01 · Core Concepts

Calibration

A model is calibrated if, among all cases where it says "70%", roughly 70% are actually positive. Many classifiers violate this:

  • Optimization
  • Training
  • Evaluation
  • Graphs
  • Linear Models
04 · Deep Learning

Neural Networks

A neural network is a parameterized function $f\theta: \mathbb{R}^d \rightarrow \mathbb{R}^k$ that maps inputs to outputs by composing many simple nonlinear transformations. The…

  • Deep Learning
  • Training
  • Optimization
  • Clustering
  • Evaluation
05 · Graph Learning

Graph Fundamentals and Representations

A graph $G = (V, E)$ is a set of nodes $V$ ($|V| = n$) and edges $E \subseteq V \times V$ ($|E| = m$). It is the natural data structure when the signal lives in the relationship…

  • Embeddings
  • Graphs
  • Evaluation
  • Clustering
  • Inference
05 · Graph Learning

GraphSAGE

For node $v$ at layer $l$:

  • Graphs
  • Embeddings
  • Training
  • Clustering
  • Inference
05 · Graph Learning

Graph Tasks - Node, Link, Edge, Graph

Predict $yv$ for each node. Example: flag fraudulent accounts in a payments graph; classify papers in Cora.

  • Graphs
  • Embeddings
  • Evaluation
  • Probability
  • Supervised Learning
05 · Graph Learning

Message Passing Framework

Per layer $l$, for every node $v$ with neighbors $\mathcal{N}(v)$:

  • Graphs
  • Embeddings
  • Transformers
  • Deep Learning
  • Evaluation
05 · Graph Learning

Training GNNs - Pitfalls and Scale

Stacking L layers gives every node an L-hop receptive field — and that's exactly the problem. Each message-passing layer is (approximately) a step of feature averaging over neig…

  • Graphs
  • Embeddings
  • Training
  • Deep Learning
  • Clustering
05 · Graph Learning

Graph Attention Networks (GAT)

Motivation in one sentence: GCN and mean-aggregating GraphSAGE weight all neighbors by structure alone (degree normalization or uniform), but not all neighbors are equally infor…

  • Graphs
  • Embeddings
  • Transformers
  • Deep Learning
  • LLMs
05 · Graph Learning

Graph Convolutional Networks (GCN)

The GCN (Kipf & Welling, 2017) is the "linear regression of GNNs": the simplest, most-cited instance of the Message Passing Framework, and the default baseline you must be able…

  • Graphs
  • Embeddings
  • Evaluation
  • Linear Models
  • Supervised Learning
05 · Graph Learning

Graph Transformers

Core idea: drop the edge-masked aggregation of the Message Passing Framework and let every node attend to every node — full self-attention over the node set, with graph structur…

  • Graphs
  • Embeddings
  • Transformers
  • Training
  • Inference
05 · Graph Learning

Classical Graph Algorithms

Dijkstra: non-negative weights, greedy with a priority queue, $O(m \log n)$ — that one-liner suffices. Add Bellman-Ford ("handles negative weights, $O(nm)$") and A ("Dijkstra +…

  • Graphs
  • Embeddings
  • Clustering
  • Inference
  • LLMs
06 · Vision

CLIP and Multimodal Models

Train on ~400M (image, caption) pairs from the web with a symmetric InfoNCE loss over the batch: each image must pick out its own caption among all captions in the batch (and vi…

  • Vision
  • Embeddings
  • Retrieval
  • LLMs
  • Training
05 · Fraud and Abuse

Anatomy of a Fraud Detection System

The generic trust-&-safety architecture. Account matching is a specialization of this; payment fraud, spam, bot detection are siblings.

  • Fraud
  • Ranking
  • Graphs
  • Serving
  • Evaluation
04 · Graph Neural Networks

Heterogeneous Graphs and R-GCN

Real industrial graphs have multiple node types and edge types. The account-matching identity graph:

  • Graphs
  • Transformers
  • Embeddings
  • Serving
  • Training
04 · Graph Neural Networks

Graphs and Message Passing from Scratch

Some data's most important information is relational: who connects to whom. LinkedIn's member graph, Roblox's friend/trade graph, the account–device–IP identity graph, transacti…

  • Graphs
  • Transformers
  • Fraud
  • Embeddings
  • Training
03 · Search and LLMs

RAG System Design (Databricks favorite)

Retrieval-Augmented Generation: ground an LLM's answers in retrieved enterprise documents. The interview is 20% LLM, 80% retrieval + evaluation + ops.

  • Retrieval
  • LLMs
  • Embeddings
  • Evaluation
  • Ranking
03 · Search and LLMs

BM25, Dense Retrieval, and Hybrid Search

BM25 scores a document for a query by summing, over query terms, a TF-IDF-like quantity:

  • Retrieval
  • LLMs
  • Embeddings
  • Transformers
  • Training
02 · Recommendation Systems

Two-Tower Retrieval Networks (Dual Encoders)

The workhorse of Stage-1 retrieval everywhere (and the template for account-matching candidate generation).

  • Recommendation
  • Ranking
  • Embeddings
  • Retrieval
  • LLMs
02 · Recommendation Systems

The Two-Stage (really Multi-Stage) RecSys Funnel

Every industrial recommender — LinkedIn feed, YouTube, Roblox discovery, ads — has the same skeleton, because of one arithmetic fact: you cannot run an expensive model on 10⁸ it…

  • Recommendation
  • Ranking
  • Embeddings
  • Retrieval
  • LLMs
02 · Recommendation Systems

Multi-Task Learning — Shared Bottom, MMoE, PLE

Real rankers predict many outcomes at once: pClick, pLike, pComment, pShare, pDwell>30s, pHide, pReport. Why multi-task instead of seven separate models?

  • Ranking
  • Recommendation
  • Training
  • Serving
  • Fraud
01 · Foundations

Transformers from Scratch

The Transformer is the encoder you'll propose for any sequence: words, user click histories (Sequence Recommenders - DIN, SASRec, BERT4Rec), account event streams (AM-05 The Sia…

  • Training
  • Embeddings
  • Transformers
  • Retrieval
  • Recommendation
01 · Foundations

Softmax, Sampled Softmax, and the logQ Correction

This note explains, from scratch, the three terms that appear constantly in retrieval papers: softmax over a huge catalog, sampled softmax / in-batch negatives, and the logQ cor…

  • Embeddings
  • Training
  • Retrieval
  • Recommendation
  • Serving
01 · Foundations

Negative Sampling and Hard Negatives

In retrieval, metric learning, and link prediction you almost never have explicit negatives — you have positives (clicks, matched pairs, edges) and an ocean of "everything else.…

  • Training
  • Embeddings
  • Retrieval
  • Graphs
  • Evaluation
01 · Foundations

Contrastive Learning — InfoNCE, Triplet, Siamese

Goal: learn an encoder $f(\cdot)$ that maps raw objects (images, sentences, user behavior histories, accounts) to vectors such that semantically same things land close together…

  • Embeddings
  • Training
  • Retrieval
  • Transformers
  • Vision
01 · Foundations

Approximate Nearest Neighbor (ANN) Search

The serving primitive of embedding systems. Once everything is an embedding, every retrieval problem reduces to: given query vector q, find the K vectors nearest to q among N =…

  • Embeddings
  • Training
  • Retrieval
  • Graphs
  • Serving
01 · Foundations

Embeddings from First Principles

Neural networks consume vectors of real numbers. But most industrial data is categorical: user IDs, item IDs, words, device models, country codes. How do you feed "user84629173"…

  • Embeddings
  • Training
  • Retrieval
  • Recommendation
  • Transformers
01 · Foundations

Loss Functions Field Guide

Every architecture in this vault is "encoder + loss." Interviewers care that you pick the loss that matches the decision the system makes. This note covers each loss, its formul…

  • Training
  • Embeddings
  • Fraud
  • Evaluation
  • Retrieval
02 · Recommendation Systems

Sequence Recommenders — DIN, SASRec, BERT4Rec

A user is not a bag of features; a user is a sequence of actions. Order and recency carry intent: someone who viewed {crib, stroller, bottle} yesterday is in a different state t…

  • Recommendation
  • Ranking
  • Transformers
  • Retrieval
  • Embeddings
02 · Recommendation Systems

Position Bias and Counterfactual Learning

Training data for rankers comes from logged impressions of the previous ranker. Click probability factors (to first order) as:

  • Ranking
  • Recommendation
  • Vision
  • Training
  • LLMs
02 · Recommendation Systems

Cold Start and Exploration

Every recsys interview ends with "what about new users/items?" Have a layered answer.

  • Recommendation
  • Ranking
  • LLMs
  • Embeddings
  • Retrieval
03 · Search and LLMs

Fine-Tuning — LoRA and Friends

Updating all weights of a 70B model needs the weights + gradients + optimizer states ≈ 16 bytes/param with Adam (fp16 weight 2 + grad 2 + fp32 master 4 + two moments 8) ≈ over a…

  • LLMs
  • Retrieval
  • Training
  • Ranking
  • Transformers
03 · Search and LLMs

Bi-Encoder vs Cross-Encoder

The single most reusable architectural dichotomy in this vault. It is the same tradeoff as retrieval-vs-ranking in recsys, and Layer-1-vs-Layer-2 in account matching.

  • Retrieval
  • LLMs
  • Embeddings
  • Ranking
  • Recommendation
04 · Graph Neural Networks

Scaling GNNs — PinSage and Sampling

Full-graph GNN training needs the whole adjacency + all activations in memory — impossible at 10⁹ nodes / 10¹⁰ edges. Know four scaling strategies plus the PinSage case study.

  • Graphs
  • Training
  • Serving
  • Embeddings
  • Retrieval
04 · Graph Neural Networks

Link Prediction

Task: given a graph, predict missing/future edges. Two flagship applications in your interviews: PYMK ("People You May Know" — predict future friendships, LinkedIn Prep) and sam…

  • Graphs
  • Embeddings
  • Training
  • Evaluation
  • Retrieval
04 · Graph Neural Networks

GCN, GraphSAGE, GAT

The three names you must distinguish crisply. All are instances of message passing; they differ in how they aggregate and whether they generalize to unseen nodes.

  • Graphs
  • Training
  • Embeddings
  • Transformers
  • Fraud
05 · Fraud and Abuse

Anomaly Detection Methods

When labels are scarce or the attack is novel, you detect deviation from normal instead of similarity to known-bad. Taxonomy by how much supervision you have:

  • Fraud
  • Embeddings
  • Vision
  • Training
  • Retrieval
06 · Vision

Vision Transformers (ViT)

Cut the image into 16×16 patches; linearly project each patch to a vector ("patch embedding"); add position embeddings; prepend a learnable [CLS] token; run a standard Transform…

  • Vision
  • Transformers
  • Embeddings
  • Training
  • LLMs
06 · Vision

Object Detection — R-CNN to DETR

Task: localize (boxes) + classify every object. Know the two-stage/one-stage/set-prediction trichotomy and the shared vocabulary: IoU (intersection-over-union of boxes), NMS (no…

  • Vision
  • Transformers
  • Training
  • Evaluation
  • Serving
06 · Vision

CNNs and ResNet

A convolutional layer slides a small learned filter (e.g., 3×3×C) across the image, computing a dot product at each location → a feature map. Three built-in assumptions (inducti…

  • Vision
  • Training
  • Transformers
  • LLMs
  • Graphs
06 · Vision

Motion Prediction — VectorNet and Beyond (Waymo core)

Task: given each agent's past track + the HD map + traffic context, predict each agent's next ~8 seconds. Sits between perception and planning; Waymo wrote the canonical papers,…

  • Vision
  • Embeddings
  • Transformers
  • Graphs
  • Training
06 · Vision

Lidar Networks — PointNet to CenterPoint

Lidar returns a point cloud: ~100–300k points per sweep, each (x, y, z, intensity). Two properties break standard nets: it's an unordered set (any permutation is the same scene…

  • Vision
  • Evaluation
  • Transformers
06 · Vision

BEV Representations and Sensor Fusion

A camera image is a perspective projection — depth is lost. To place camera evidence in the bird's-eye-view plane you must reason about depth. Two canonical mechanisms:

  • Vision
  • Transformers
  • Evaluation
06 · Language Models

Positional Encodings

Self-attention treats its input as a set, not a sequence — by itself it cannot tell "dog bites man" from "man bites dog." Positional encodings fix this by adding or modifying to…

  • Transformers
  • LLMs
  • Embeddings
  • Training
  • Evaluation
06 · Language Models

LLM Architecture

A modern LLM (GPT, Llama, Claude-style) is a decoder-only transformer: tokens are embedded, position information is added, and the sequence passes through $N$ identical decoder…

  • LLMs
  • Transformers
  • Embeddings
  • Evaluation
  • Graphs
06 · Language Models

Attention Variants and Efficiency

Standard multi-head attention (MHA) costs $O(n^2 d)$ compute and, at inference, a KV cache that grows with the number of heads. Multi-Query Attention (MQA) lets all query heads…

  • Transformers
  • LLMs
  • Inference
  • Optimization
  • Training
06 · Language Models

Normalization and Activations in LLMs

Modern LLMs stabilize training by normalizing activations inside the residual branch (pre-norm) and almost always use RMSNorm — a cheaper LayerNorm variant that drops mean-cente…

  • LLMs
  • Transformers
  • Optimization
  • Training
  • Deep Learning
06 · Language Models

Tokenization

A transformer never sees characters or words — it sees a sequence of integer token IDs, each of which indexes a row in the embedding table. Tokenization is the algorithm that sp…

  • LLMs
  • Transformers
  • Deep Learning
  • Embeddings
  • Probability
06 · Language Models

Mixture of Experts

Mixture of Experts (MoE) swaps the dense feed-forward network (FFN) in a transformer block for $N$ parallel expert FFNs plus a lightweight router (gating network) that, per toke…

  • LLMs
  • Transformers
  • Inference
  • Training
  • Optimization
06 · Language Models

Supervised Fine-Tuning

Supervised Fine-Tuning (SFT), also called instruction tuning, takes a pretrained base model — which only predicts likely next tokens — and trains it on human-written or curated…

  • LLMs
  • Transformers
  • Supervised Learning
  • Training
  • Optimization
06 · Language Models

Scaling Laws

Scaling laws say that an LLM's test loss decreases predictably — as a power law — as you grow the number of parameters $N$, training tokens $D$, and compute $C$. Kaplan et al. (…

  • LLMs
  • Transformers
  • Probability
  • Training
  • Deep Learning
06 · Language Models

RLHF and Preference Optimization

RLHF (Reinforcement Learning from Human Feedback) is the alignment step that turns a capable-but-raw fine-tuned model into a helpful, harmless assistant. The classic InstructGPT…

  • LLMs
  • Transformers
  • Optimization
  • Probability
  • Supervised Learning
06 · Language Models

Pretraining and Language Modeling

Pretraining trains a model on a single, brutally simple objective: given the tokens seen so far, predict the next one. The loss is per-token cross-entropy (negative log-likeliho…

  • LLMs
  • Transformers
  • Training
  • Probability
  • Supervised Learning
06 · Language Models

Parameter-Efficient Fine-Tuning

Parameter-Efficient Fine-Tuning (PEFT) freezes the pretrained model and trains only a small set of extra or selected parameters, getting most of the quality of full fine-tuning…

  • LLMs
  • Transformers
  • Training
  • Evaluation
  • Inference
06 · Language Models

Decoding Strategies

An autoregressive LLM only gives you a probability distribution over the next token; a decoding strategy decides which token to actually emit. Greedy picks the argmax (determini…

  • LLMs
  • Transformers
  • Inference
  • Optimization
  • Probability
06 · Language Models

KV Cache and Inference Optimization

When an LLM generates text one token at a time, each new token must attend to every previous token. Naively you would re-run the whole prompt through attention at every step, wa…

  • LLMs
  • Transformers
  • Inference
  • Optimization
  • Training
06 · Language Models

Quantization for LLMs

Quantization maps high-precision floating-point numbers (FP16/BF16) to low-bit integers (INT8/INT4) or compact floats (FP8/NF4) using a learned scale and zero-point, shrinking a…

  • LLMs
  • Transformers
  • Evaluation
  • Inference
  • Optimization
06 · Language Models

Speculative Decoding and Distillation

Speculative decoding runs a small, fast draft model to guess the next $k$ tokens, then has the big target model verify all $k$ in a single parallel forward pass; you accept the…

  • LLMs
  • Transformers
  • Inference
  • Optimization
  • Probability
06 · Language Models

Long Context

A model's context window is the maximum number of tokens it can process in one forward pass. It grew from ~2k (GPT-3) to 128k–1M+ in modern models. Long context is hard because…

  • LLMs
  • Transformers
  • Inference
  • Optimization
  • Retrieval
06 · Language Models

Prompt Engineering

Prompt engineering is the practice of designing the input text so a pretrained LLM performs a task well. Because large models exhibit in-context learning (ICL) — learning a task…

  • LLMs
  • Transformers
  • Inference
  • Retrieval
  • Supervised Learning
06 · Language Models

Tool Use and Agents

An LLM by itself is a frozen text predictor: it cannot do exact arithmetic, look up live or private data, or take actions in the world. Tool use (a.k.a. function calling) fixes…

  • LLMs
  • Transformers
  • Inference
  • Probability
  • Retrieval
06 · Language Models

Reasoning and Test-Time Compute

Test-time (inference-time) compute is the idea that you can trade extra computation at query time for higher accuracy, instead of only making the model bigger at training time.…

  • LLMs
  • Transformers
  • Inference
  • Optimization
  • Retrieval
06 · Language Models

LLM Evaluation

Evaluating an LLM is hard because most useful outputs are open-ended — there is no single correct string to match. So we triangulate: intrinsic measures like perplexity (how wel…

  • LLMs
  • Transformers
  • Evaluation
  • Optimization
  • Retrieval
06 · Language Models

Hallucination and Safety

LLMs are trained to produce likely, fluent continuations — not true ones — so they confidently invent facts, citations, and APIs that don't exist; this is hallucination. The mai…

  • LLMs
  • Transformers
  • Evaluation
  • Optimization
  • Retrieval
06 · Language Models

Retrieval-Augmented Generation

RAG = retrieval + generation. Offline, you chunk a document corpus, embed each chunk with a bi-encoder text-embedding model, and store the vectors in a vector database. Online,…

  • LLMs
  • Transformers
  • Retrieval
  • Embeddings
  • Evaluation
04 · Deep Learning

Transformers

RNNs were the standard for sequences but had fundamental problems:

  • Deep Learning
  • Training
  • Transformers
  • Inference
  • LLMs
04 · Deep Learning

Recurrent Neural Networks

MLPs and CNNs assume fixed-size inputs with no inherent ordering. But many problems involve variable-length sequences where order matters:

  • Deep Learning
  • Training
  • Transformers
  • Graphs
  • Inference
04 · Deep Learning

Convolutional Neural Networks

Consider a 224×224 RGB image fed into an MLP with 1000 hidden units:

  • Deep Learning
  • Training
  • Transformers
  • Clustering
  • Evaluation
04 · Deep Learning

Attention

Recall the seq2seq encoder-decoder for translation:

  • Deep Learning
  • Training
  • Transformers
  • Evaluation
  • Graphs
03 · Unsupervised Learning

k-Means Clustering

Before diving into K-Means, understand the paradigm shift:

  • Clustering
  • Unsupervised Learning
  • Evaluation
  • Linear Models
  • Supervised Learning
02 · Supervised Learning

Random Forests

Random Forest is an ensemble learning algorithm that combines many decision trees into a single, more robust model. Each tree is trained on a different random subset of the data…

  • Supervised Learning
  • Trees
  • Training
  • Evaluation
  • Probability
02 · Supervised Learning

Naive Bayes

Naive Bayes is a family of probabilistic classifiers based on Bayes' Theorem with a "naive" assumption: all features are conditionally independent given the class.

  • Supervised Learning
  • Probability
  • Evaluation
  • Inference
  • Graphs
02 · Supervised Learning

Logistic Regression

Logistic regression is a supervised learning algorithm used for binary classification (and extendable to multi-class). It predicts the probability that an input belongs to a par…

  • Supervised Learning
  • Linear Models
  • Probability
  • Deep Learning
  • Evaluation
02 · Supervised Learning

Linear Regression

Linear regression is a supervised learning algorithm used for regression problems (predicting continuous values). It models the relationship between a dependent variable y and o…

  • Supervised Learning
  • Linear Models
  • Probability
  • Training
  • Evaluation
02 · Supervised Learning

kNN

K-Nearest Neighbors is a non-parametric, instance-based supervised learning algorithm used for both classification and regression. It makes predictions based on the K closest tr…

  • Supervised Learning
  • Embeddings
  • Evaluation
  • Retrieval
  • Training
02 · Supervised Learning

Decision Trees

A Decision Tree is a supervised learning algorithm used for both classification and regression. It splits data into subsets based on feature values, forming a tree-like structur…

  • Supervised Learning
  • Trees
  • Deep Learning
  • Linear Models
  • Clustering
01 · Core Concepts

Metrics

Three layers of metrics — a strong answer touches all three:

  • Training
  • Optimization
  • Evaluation
  • Inference
  • Supervised Learning
01 · Core Concepts

Back Propagation

Backprop is just the chain rule applied systematically over a Computational Graph. Everything below builds from one neuron up to the vectorized, minibatched form.

  • Optimization
  • Training
  • Deep Learning
  • Graphs
  • Probability
02 · Supervised Learning

Support Vector Machines

A supervised algorithm for classification (and, via SVR, regression). Among all hyperplanes that separate two classes, the SVM picks the one that maximizes the margin — the dist…

  • Supervised Learning
  • Linear Models
  • Evaluation
  • Optimization
  • Training
02 · Supervised Learning

Gradient Boosted Trees

An ensemble method that combines many weak learners (shallow decision trees) into a strong one. Unlike Random Forests which builds trees independently and in parallel (bagging),…

  • Supervised Learning
  • Trees
  • Optimization
  • Training
  • Deep Learning
03 · Unsupervised Learning

DBScan

A cluster is a region of high point density. DBSCAN grows clusters from dense "core" points and leaves low-density points as noise. It finds arbitrarily shaped clusters and is r…

  • Clustering
  • Unsupervised Learning
  • Retrieval
  • Evaluation
01 · Core Concepts

Softmax

For logits $\mathbf{z} = (z1, \dots, zK)$:

  • Training
  • Optimization
  • Linear Models
  • Probability
  • Supervised Learning
01 · Core Concepts

Cross-Entropy Loss

Cross-entropy $H(p, q) = -\sumi pi \log qi$ is the expected number of bits to encode events from the true distribution $p$ using a code optimized for the predicted $q$. Minimizi…

  • Training
  • Optimization
  • Probability
  • Linear Models
  • Supervised Learning
01 · Core Concepts

Gradient Descent

Plain SGD struggles with ravines and saddle points. Improvements:

  • Optimization
  • Training
  • Deep Learning
  • Linear Models
  • Supervised Learning
01 · Core Concepts

Batch Normalization

For a mini-batch $\mathcal{B} = \{x1, \dots, xm\}$ at some layer:

  • Optimization
  • Training
  • Inference
  • Deep Learning
  • Transformers
01 · Core Concepts

Vanishing and Exploding Gradients

The gradient at layer $\ell$ is a product of terms across all later layers:

  • Optimization
  • Training
  • Deep Learning
  • Transformers