Tutorials

About Publications Projects
Math Foundations Classical Machine Learning Deep Learning Fundamentals Self-Supervised Learning Reinforcement Learning Transformers LLMs Model Efficiency Audio & Signals Multitask Learning

Short, hands-on tutorials on the ideas I keep coming back to. Each one starts with intuition, walks through the math in plain words, and each has something you can play with. The code behind them lives in my model-optimization repo.

Vectors and Matrices

Length, the dot product and the cosine, projection, matrices as layers that move the plane, the determinant, inverse and rank, and the shape rules for reading attention code.

Probability and Bayes Rule

A language model's next-token bars, the chain rule that scores a reply, and Bayes rule on a keyword spotter.

Common Probability Distributions

Bernoulli, softmax's categorical, the uniform, the Gaussian and its tilted cloud, the loss each minus log gives, and how to draw samples.

Eigenvalues, Eigenvectors and SVD

The directions a matrix only stretches: eigenvectors of a face-pixel covariance, the SVD as turn, stretch, turn, and keeping the top few for PCA, collapse checks and LoRA.

Linear Regression

Fitting a line by walking downhill. Gradient descent versus the closed-form answer (the exact formula that jumps straight to the best line), and what learning rate (the size of each step the walk takes) does to the walk.

Logistic Regression

A line that says yes or no. The sigmoid, an S-shaped curve that squeezes any score into the range from 0 to 1, turns a score into a probability, and 0.5 draws the boundary.

Multilayer Perceptrons (MLP)

When a line is not enough. Its layers each mix the numbers they receive with learned weights and bend the mix, so stacked layers can bend the boundary too. One dial grows the model from a straight boundary to a smooth curve to a crazy overfit, where the model learns the training examples so closely that it does worse on new ones.

Decision Trees, Random Forests, and Boosting

Twenty questions, then a forest. One tree memorizes, many vote, and boosting fits the last round's mistakes.

Support Vector Machines (SVM)

Maximum margin (the widest empty gap you can leave between the boundary and the nearest points on each side). Hinge loss (the penalty for points on the wrong side of the margin), support vectors (the borderline points that hold the margin up), and the C knob that trades margin width against violations.

k-Nearest Neighbors (k-NN)

Ask the neighbors. No training, just voting, and one slider that shows bias (oversmoothing the pattern away) versus variance (twitching at every noisy neighbor) live.

Naive Bayes

Classifying by counting. Each word moves the class bars, and smoothing (adding a small count to everything) stops zero counts from zeroing everything.

k-Means Clustering

Find the clumps with no labels. Two steps repeated: points pick the nearest center, centers jump to the middle.

Maximum Likelihood and EM

How do you set a model’s numbers from data?

Gaussian Mixture Models (GMM)

k-means gives every point one cluster and every cluster a circle.

Hidden Markov Models (HMM)

A Markov chain is a state that hops by fixed odds.

Principal Component Analysis (PCA)

Faces from parts. The notebook's eigenfaces, the ghostly basic face patterns that get mixed in different amounts to build a face, rebuilt in your browser: one slider from ghost to person.

Independent Component Analysis (ICA)

Two voices, two microphones. How ICA unmixes recordings into independent sources: whitening (the PCA step), the non-Gaussian objective, FastICA one update at a time, and why a real room's echoes break it.

Non-negative Matrix Factorization (NMF)

A spectrogram rebuilt as sound templates times when each one plays. Why non-negative parts add up, the two costs, the multiplicative updates, choosing the rank, and how a convolutive version pulls room echo out of a recording.

t-SNE

The name expands to t-distributed Stochastic Neighbor Embedding. PCA's nonlinear follow-up. Neighbor probabilities, the heavy-tailed t (which lets far pairs stay vaguely far, so clusters get room to separate), and the perplexity knob (how many effective neighbors each point gets) that remakes the map.

Recommender Systems

People who liked this. Taste as geometry: same-taste users versus same-content movies, side by side.

CNN Basics: Convolution, Stride and Pooling

How a convolution layer slides one small kernel (a little grid of learned weights) over an image, how kernel size, stride (the step between positions) and padding set the output size, what pooling (keeping one value per small patch) keeps, and a small digit classifier traced layer by layer.

Receptive Fields, Dilation and Causal Convolutions

How much of the input one output can see (its receptive field), why stacked 3×3 kernels beat one large kernel, and how dilation (spacing a kernel's taps apart) widens that view with the same weights. Causal convolutions look only at the past, and stacks of them called TCNs (temporal convolutional networks) handle live time series.

Classic CNN Architectures: AlexNet to ResNet

The networks that set the design rules for image models, each remembered for one block it repeats. AlexNet brought ReLU, VGG tested depth, Inception added the 1×1 convolution (a layer that mixes channels only), batch normalization (rescaling each layer's outputs) steadied training, and ResNet's shortcut connections made very deep networks train.

Efficient CNNs: MobileNet and EfficientNet

How to keep accuracy with far fewer weights. Depthwise separable convolutions split filtering from channel mixing, MobileNetV2's inverted residual widens only inside the block, squeeze-and-excitation reweights channels by importance, and EfficientNet grows depth, width and image size together.

RNN Basics: Recurrence and Backpropagation Through Time

One cell reused at every time step, and how backpropagation through time (unrolling the loop and passing gradients back through every step) trains it. Why its gradients (the signals that tell each weight which way to move) vanish or explode, and what clipping and truncated backpropagation do about it.

Gated RNNs: GRU and LSTM

Gates (small learned switches between 0 and 1) decide what memory to keep and what to forget. The GRU (gated recurrent unit) uses an update and a reset gate, the LSTM (long short-term memory) guards a separate cell state with three gates, and both hold a signal that a plain RNN loses.

Cross-Entropy Loss

How a model scores one prediction. BCE (binary cross entropy, how you score a coin flip prediction, where the model states a probability and the loss measures how wrong that probability was), cross entropy, and why confident-and-wrong is ruinous.

KL Divergence

Why cross-entropy is the target's own spread plus KL, why KL is not symmetric, and how distillation, RLHF and t-SNE pick a direction.

Gradient Descent

The loss (a score of how wrong the model's predictions are) over all the weights is a landscape. Walk it downhill, then race three optimizers (the methods that decide how the weights actually move downhill at each step) on one steep valley.

Backpropagation and Gradient Checking

How one backward pass finds every weight's slope by the chain rule, why long chains make gradients vanish or explode, and how to check backprop against a nudge, all on the small network of the MLP page.

CTC Loss

What if you don't know which frame said what? Blank tokens (a no-label token that soaks up extra frames), dynamic programming (summing all the possible alignments by reusing partial sums), and beam search (keeping only the best few candidate outputs at each step), so the alignments get searched without trying every one.

Understanding Model Errors

Bias (the error from a fit that is too simple and oversmooths the pattern away), variance (the error from a fit that twitches at noise and changes with the sample), and the errors you cannot train away. Know your floor before you blame your model.

Regularization and Data Augmentation

Your model memorized the training set. Dropout (randomly switching neurons off during training), weight penalties (a cost on large weights), and fake data that actually works.

SGD, Momentum and Nesterov

Why plain SGD swings across a steep valley, and how remembering the last step speeds it up and calms it down.

Adaptive Optimizers: AdaGrad, RMSProp and Adam

Give every weight its own step size: how Adam's two running averages, its betas and its zero-start fix make each step about the same length.

Optimizers in Practice: AdamW, SAM, Schedules and Clipping

A real training loop adds four controls around the optimizer. AdamW applies weight decay (shrinking weights toward zero) outside Adam's scaling, SAM (sharpness-aware minimization) takes a second gradient to prefer flat minima, a schedule changes the learning rate over training, and gradient clipping caps rare huge gradients. Each is shown where it acts in the training step, with the failure it prevents.

Normalization Layers

BatchNorm, LayerNorm, InstanceNorm, GroupNorm and RMSNorm as one recipe on different slices of a tensor, how BatchNorm changes between training and inference, and where each is used.

Scaling Laws

How much loss (how wrong the model is, as one score) does a dollar buy? The brutal exchange rate between compute and loss, and how to split a fixed budget.

Self-Supervised Learning

Labels are expensive, structure is free: how a model learns from unlabeled data by answering questions the data poses itself, and how we check what it learned.

Contrastive Learning

Pull two edited copies of one image together and push other images away: SimCLR (negatives from the batch) and MoCo (a queue of past embeddings that stands in for a huge batch).

Image-Text Contrastive Learning (CLIP)

In Contrastive Learning, each view picks its positive, the other view of the same image, out of a batch with InfoNCE.

Non-Contrastive Self-Supervised Learning

Learning with no other images to push away, and why the model does not collapse to one output: BYOL (a slow copy as target), SimSiam (a gradient stop) and DINO (a student matching a teacher).

Masked Image Modeling

Hide 75% of an image's patches and rebuild them: why hiding most of the picture forces a model to understand the scene.

Self-Supervised Learning Failure Modes and Checks

Shortcuts through overlapping receptive fields (the input region one output sees), collapse, BatchNorm leaks, misleading probe scores, and what to watch during training.

RL Basics

Learning from rewards: the agent acts, the world answers with a score. Bananas included.

Value-Based RL

Learn a score for every move and play the best one: where value-based methods sit among the RL families, then Q-learning, SARSA and DQN with its Double and Dueling fixes.

Policy Gradients: REINFORCE, Actor-Critic and PPO

Learn the move itself with REINFORCE and a baseline, judge it with a critic in actor-critic and A2C, and keep each update small with PPO clipping.

Continuous-Action Actor-Critic: TD3 and SAC

Choose real-number actions by trusting the lower of two critics with TD3, and pay for keeping options open with SAC.

Model-Based RL: Dyna, AlphaZero and MuZero

Learn how the world responds and plan or practise inside it with Dyna, AlphaZero, MuZero, World Models and Dreamer, then choose a method.

Deep Q-Networks (DQN)

Teach an agent the Q value of every move (Q for quality, how good that move is), then it just picks the best one. Watch it stop eating blue bananas.

Deep Deterministic Policy Gradient (DDPG): Actor and Critic

When actions are real numbers, like joint torques, there is no list to take the best of. An actor network outputs the action directly, a critic network scores it against slow target copies (lagging versions of each network), and the actor climbs the critic's gradient.

Training DDPG: Target Networks, Replay and Noise

Why DDPG needs three stabilizers to train. Slow target copies stop the critic chasing its own guesses, a replay buffer (a memory of past steps sampled at random) breaks the link between neighboring steps, and smooth exploration noise makes a fixed actor try new moves. Then one full update, my Reacher arm run, the failure modes, and TD3 and SAC.

Multi-Agent Reinforcement Learning

Two rackets, both learning at once. Your opponent never sits still.

Aligning Language Models with RL

RLHF (reinforcement learning from human feedback): people rank answers, a reward model learns their taste, and RL pushes the language model toward it, until pushing too hard backfires.

Attention

Attention is weighted averaging with learned weights: each token scores every other token, turns the scores into weights, and blends what they carry. Several heads do it in parallel.

Positional Encoding and Masking

Attention sees a bag of tokens with no order. Positions tell it where each token sits (sines, RoPE, ALiBi), and masks tell it what each token may look at.

The Transformer Block

Attention mixes, a small feed-forward network refines, residuals carry everything up. Stack the block and you get BERT, the translation model, or GPT.

Cross-Attention

Queries from one stream, keys and values from another: a translation reading its source sentence, or a fixed set of learned queries reading an input of any size.

Transformer Cost and Efficiency

Why long inputs cost the square of their length, and the tricks that follow: the KV cache, shared key and value heads, FlashAttention and streaming.

Adapters

Fine-tune a giant model while training almost nothing. Rank, the size of the tiny trainable update, is a dial, not a magic number.

The Conformer Block

How a speech encoder adds a convolution module between two half feed-forwards so one block hears both short sounds and the whole sentence, what the paper's ablation shows, and how Branchformer and Squeezeformer rewired it.

Conformer in PyTorch: Training and Streaming

The Conformer block written as PyTorch classes, trained with CTC and a warm-up schedule, then run on live audio with a chunked attention mask at a chosen latency.

Tokenizers

How text becomes token ids: word, character and byte vocabularies, the vocabulary size trade-off, which tokenizer GPT, Llama, Gemma and BERT use, and its side effects on numbers, languages and spaces.

How Subword Tokenizers Are Built: BPE, WordPiece and Unigram

How BPE, byte-level BPE, WordPiece and Unigram build a vocabulary from a corpus, with a step-through of BPE merges, Unigram sampling and SentencePiece training.

Softmax, Temperature and Decoding

How a model picks each next word: softmax turns scores into probabilities, temperature sharpens or flattens them, and greedy, beam search, top-k and top-p choose the word.

Mixture of Experts (MoE)

How an MoE layer routes each token to a few expert FFNs: router scores, top-k, the balance loss, capacity and the z-loss, with a small PyTorch layer.

Mixture of Experts Designs

How real MoE models are built and run: bias balancing without a loss, Switch to DeepSeek-V3 designs, experts across GPUs, serving memory and fine-tuning.

Activation Probes

Tiny classifiers that read a model's internal activations (the lists of numbers inside the model that describe what it has understood so far) to flag harmful prompts, before it answers.

From BLIP to the Q-Former

One text model trained three ways learns to match, compare and caption images. Then 32 learned queries let a frozen language model read a frozen image model (BLIP-2).

Quantization Basics

How a float tensor becomes 8-bit or 4-bit integers: scale, zero point, and where to cut the range so outliers and rounding cost the least.

Post-Training Quantization and Quantization-Aware Training

Dynamic and static quantization in PyTorch with calibration and observers, then quantization-aware training with fake quantization and the straight-through estimator.

Normalization and Quantization

How BatchNorm folds into the conv, why LayerNorm and RMSNorm cannot, and how SmoothQuant tames the outlier activations around them before 8-bit inference.

Debugging a Quantized Model

The model quantized and the accuracy fell off a cliff. What to check first, then print, plot, and disable layers until the bad one shows itself.

Neural Architecture Search Basics

Search spaces, random search, evolution and reinforcement-learning controllers, how such a search is run, and how an RL search found EfficientNet.

One-Shot NAS: Weight Sharing and DARTS

One supernet shares its weights across every candidate, DARTS blends the candidate ops by a learned vote trained by gradient descent, and skip connections can take over.

Knowledge Distillation

Shrink a giant model into a small one without much performance loss. The teacher's soft labels, its full probability distribution over the classes rather than one hard answer, do the teaching.

Pruning

Cut the weights that do not matter and keep the accuracy. Sparsity, the fraction of weights cut away, is free compression if you do it right.

Audio & Signals Basics

A signal’s path, and two ways to see it.

ADC Fundamentals

If analog input is a ramp, ADC is a staircase. Bits, noise, and the 6 dB rule, each extra bit buys about 6 dB of signal-to-noise ratio, made playable.

Aliasing and Anti-Aliasing Filters

Why fast things look slow once sampled, and the filter that stops it.

LTI Systems and Convolution

What a filter or a room does to a sound.

Fourier Transform and the FFT

Time and frequency, and what the basis looks like.

How FIR and IIR Filters Shape Magnitude and Phase

Keeping some frequencies, dropping others, and what that does to timing.

The STFT and Spectrograms

A spectrum for every moment, and the trade-off between time and frequency detail.

Power Spectral Density

How a signal’s power spreads over frequency, and how to measure it.

Spectral Subtraction for Denoising

Estimate the noise, take it away frame by frame, and see what is left.

The Wiener Filter

One gain per bin, set by how much of that bin is speech.

Reverberation and Dereverberation

What a room does to sound, how to measure it, and how to remove its late tail.

MFCC and Other Audio Features

From a spectrogram to the few numbers per frame that models learn from.

Introduction to Multitask Learning

The three ways training one model on many tasks fails, the geometry behind them, and which page fixes each one.

The Multitask Field Guide

Diagnose which failure you have, avoid the five mistakes, batch jointly, and admit only the losses that must shape the shared layers.

MGDA (Multiple Gradient Descent Algorithm)

Blend the task gradients into their shortest mix, every weight zero or more and all adding to one, and step against it.

GradNorm (Gradient Normalization)

Learn one loss weight per task (the number its loss is multiplied by) so every task trains at the same pace.

Uncertainty Weighting

Set each task's loss weight from the data's noise.

PCGrad (Projecting Conflicting Gradients)

When gradients fight, cut only the part that fights back.

GradVac (Gradient Vaccine)

Nudge each pair of task gradients back to how much that pair usually agrees, instead of cutting every conflict until the pair neither agrees nor fights.

CAGrad (Conflict-Averse Gradient Descent)

Help the worst-off task without losing sight of the average.

Gradient Balancing Inside the Training Loop

What the loss, the optimizer (the rule that turns gradients into weight updates), clipping (capping a gradient's length) and logging do to the balanced gradient once a balancing method hands it on.