Home › Machine learning

Machine learning

Model building blocks, data, classical ML, reinforcement learning and evaluation.

Foundations

The pieces every model is made of.

Modern layers

What sits inside today's networks.

Data

Turning raw data into training batches.

Byte-pair encoding (BPE) tokenization

low

Learn a subword vocabulary by repeatedly merging the most frequent adjacent pair; byte-level BPE encodes any input losslessly with 32k-200k tokens.

training O(merges × corpus) naive, O(corpus · log) with incremental pair counts and a heap; encoding O(n log n) per pre-token chunk with a heap, O(n²) naive

Data loading pipelines

medium

Turn files on disk into shuffled, sharded, resumable GPU batches fast enough that the accelerator never waits.

Near-duplicate detection with MinHash LSH

medium

Estimate set Jaccard similarity from k min-hashes and find similar pairs with banded LSH buckets; the standard dedup for web crawls, training corpora and sequence collections.

O(n·L·k) to sign n docs of L shingles with k hashes; O(n·b) bucket inserts; candidate pairs ≈ true near-duplicates, not n²

Data augmentation

low

Generate label-preserving variants of each training example on the fly to enlarge the effective dataset and bake in invariances.

O(input size) per sample per transform; no extra labels needed

symmetry data augmentation

Planned.

active learning

Planned.

Negative sampling

low

Train by contrasting each observed positive with a few sampled negatives instead of normalising over every candidate; the choice of sampler decides bias and quality.

O(k·d) per positive instead of O(V·d); O(1) per negative draw with an alias table

Feature store

medium

One definition per feature feeds a history store for training and a latest-value store for serving, so training and inference see the same values as of the same moment.

PIT lookup O(log h) per label row for h versions of an entity; online read O(1) hash lookup plus one network round trip; materialization O(entities)

Classical ML

Often the right tool, and much cheaper.

Linear and logistic regression

low

Fit a weighted sum of features to a number (least squares) or a probability (logistic); the baseline every model must beat.

normal equations O(n·d² + d³); Newton/IRLS O(n·d² + d³) per iteration, about 5-20 iterations; SGD O(n·d) per epoch

Gradient-boosted decision trees (GBDT)

medium

Add small regression trees one at a time, each fitted to the loss gradient; histogram splits over 256 bins make it the strongest tabular default.

per tree O(n·f) to build histograms + O(leaves·f·bins) to find splits; prediction O(trees·depth)

k-means clustering

low

Partition points into k clusters by alternating nearest-centroid assignment and centroid averaging; k-means++ seeding makes it dependable.

O(n·k·d) per Lloyd iteration (a matrix multiply); k-means++ seeding O(n·k·d); usually 10-100 iterations

PCA and SVD

low

Find orthogonal directions of maximum variance by an SVD of the centred data; randomized SVD gets the top k components in a few passes.

full SVD O(n·d·min(n,d)); randomized top-k O(n·d·(k+p)·(q+1)) with oversampling p and q power iterations

Naive Bayes classifier

low

Count how often each feature occurs per class and score a new item by summed log-likelihoods; trains in one pass, updates and merges by adding counts.

train O(tokens); predict O(tokens x classes); memory O(vocabulary x classes)

Isolation forest

low

Score each record by how few random axis-aligned splits it takes to isolate it in a small forest of random trees; anomalies are few and different, so they isolate fast.

train O(t·ψ·log ψ), independent of n; score O(t·log ψ) per point; memory O(t·ψ)

Density-based clustering (DBSCAN)

medium

Group points that are packed densely, label the rest as noise: no k, arbitrary shapes, two parameters (eps, minPts), cost set by the neighbour index.

n region queries; O(n log n) typical with a spatial index and small eps, O(n²) brute force or worst case

gaussian processes

Planned.

Generalized linear models (GLMs)

medium

Linear model for counts, rates, positive amounts and proportions: a linear score pushed through a link, fitted by iteratively reweighted least squares.

per IRLS iteration O(n·p²) to form XᵀWX plus O(p³) to solve; typically a handful of iterations

quantile regression

Planned.

ftrl online learning

Planned.

Feature hashing (the hashing trick)

low

Hash each feature name to an index in a fixed-size vector, with a second hash for the sign, so no vocabulary is needed and memory is fixed.

O(k) time for k features; O(2^b) memory regardless of vocabulary size; collisions about n/(2m) of tokens when n much less than m

weight of evidence binning

Planned.

belief propagation

Planned.

Reinforcement learning

Learning from reward instead of labels.

Evaluation

Knowing whether a model is actually better.

Recommendation & ranking

Retrieving and ranking items for users, and modelling what they will remember.

Two-tower retrieval

medium

Two separate encoders map users/queries and items into one vector space; item vectors are precomputed and searched by nearest neighbour, so recall over millions costs one small forward pass.

serve O(user tower + ANN search over N items, sublinear); train O(B²·d) logits per batch of B pairs

Learning to rank

medium

Train a scorer on query-grouped data so that the order it induces maximizes NDCG; LambdaMART (boosted trees with NDCG-weighted pair gradients) is the production default.

training O(pairs per query) = O(m²) per query of m documents (less with truncation); scoring O(candidates × model cost); one sort per query

Matrix factorization for collaborative filtering

medium

Learn a short latent vector per row and per column from the observed cells only; a missing cell is predicted by the dot product of its two vectors.

SGD epoch O(nnz·k); ALS iteration O(nnz·k² + (rows+cols)·k³); score one pair O(k), all N items O(N·k)

Deep ranking models for recommendation

medium

Embedding tables plus a feature-interaction net predict several feedback signals per candidate; a weighted sum of them is the ranking score.

O(candidates × (sparse lookups × d + MLP + history length)) per request; memory-bound on embedding lookups

Click-probability prediction (CTR models)

medium

Learn p(action | user, item, context) from hashed categorical features with interaction terms (FM, Wide & Deep, DCN, DLRM), then keep it calibrated, since downstream multiplies it.

FM score O(k·n) for n active features and k factors (not O(k·n²)); DLRM O(n² d) for dot interactions; serving is bound by embedding lookups, one DRAM miss per feature

knowledge tracing

Planned.

spaced repetition

Planned.

Vision models

Detecting, segmenting, tracking and recognizing things in images and point clouds.

Document understanding

Getting text and structure out of scans, PDFs and web pages.

Optical character recognition (text recognition)

medium

Find text lines in an image, read each crop with a CTC or attention model, then correct with a lexicon and score confidence for review routing.

detection O(pixels) per page; recognition O(width x model) per line crop; greedy CTC decode O(T x V) per line; naive lexicon correction O(words x lexicon x len^2)

layout analysis

Planned.

table structure recognition

Planned.

Document image preprocessing

low

Turn a scan or phone photo into an upright, evenly lit, binarised or normalised grey page so layout analysis and OCR read it reliably.

O(pixels) per stage; Sauvola with integral images is O(1) per pixel for any window; deskew O(angles x pixels)

PDF text extraction

low

Rebuild words, lines, columns and reading order from the glyph positions a born-digital PDF stores, and route pages without usable text to OCR.

O(n log n) in glyphs per page (sorts); content-stream decoding O(bytes); no model call

HTML main-text extraction

medium

Decode bytes, tolerate broken markup, drop non-content nodes and score text blocks by length and link density to keep the main run, with headings, metadata and offsets for citation.

O(n) in page bytes: one tokenizer pass plus a scoring pass over blocks; a headless browser adds about a whole page load

Text chunking

low

Cut documents into token-bounded pieces along structure boundaries, keeping offsets and section paths, so each piece embeds well and can be cited.

O(n) over the text for splitting; embedding cost O(tokens × size/(size − overlap)); index size = chunks × dims × bytes

Language processing

Classic NLP components: tagging, linking, classification, normalization, dialogue.

Named entity recognition

medium

Find the character spans of entities in text and give each a type, by labelling every token and decoding a valid label sequence.

per sentence O(tokens x features x tags) for emissions plus O(tokens x tags^2) Viterbi; transformer encoder O(tokens x layers), attention quadratic in tokens

Entity linking

medium

Map each mention to a knowledge-base id, or to NIL, by generating candidates from an alias table, scoring them on prior and context, and thresholding.

candidate generation O(trigrams x posting length) or one ANN query; scoring O(candidates x context); a cross-encoder rerank costs one transformer pass per candidate

relation extraction

Planned.

Text classification

medium

Assign one or more labels to a text; climb a ladder from regexes to linear models on n-grams, embeddings, fine-tuned encoders and LLM prompts, only as far as the data and budget demand.

linear model predict O(nonzero features x classes) per document; encoder forward O(tokens x layers), quadratic in tokens through attention

Language identification

low

Score a text's character n-grams against per-language statistics, after a cheap script check, and return an ISO 639 code with a confidence or "und".

O(n · L) for n characters and L languages with naive Bayes; O(n · d) with a fastText-style linear model of dimension d

Text normalization

low

Rewrite messy text into one canonical form for matchers and models, or into spoken words for speech output (and back), keeping a map to the original offsets.

O(n) rule pass with an offset map; spelling lookup is a few hash probes per token (deletes of the token)

ngram language model

Planned.

back translation

Planned.

Template-based text generation

low

Realise facts as sentences by filling slots in alternative templates, with agreement, referring expressions and seeded variation; every word traces to data or a template.

O(output length) per report; no model, no search

Intent classification and slot filling

medium

Turn one utterance into an intent label and typed slot values with a joint model: a sentence-level classifier plus a token-level BIO tagger on a shared encoder.

per utterance O(tokens x features x (intents + tags)) for the linear model; encoder forward O(tokens x layers), attention quadratic in tokens

Dialogue state tracking

medium

Keep a structured belief of the user's goal (slot → value, plus requests) and update it every turn from NLU output, the old state and the last system action.

O(hypotheses per turn) for a frame tracker; neural trackers O(dialogue tokens) per turn, O(1) with the previous state as input

Speech

Recognizing, segmenting and synthesizing speech.