ML / DL exam field guide
Lessons · 0 of 9
Shared master’s course · complete review

Reason it out. Then calculate it.

A source-bounded machine-learning guide built around the professor’s recurring exam move: give a small artifact, change one condition, and ask you to justify what follows.

Open visual cheat sheet Three-board whole-course recall map
Boundary: lecture weeks 1–10, both supplied notebooks, and the transferable question style of four older CS exams. Old Naive Bayes and modified-ID3 specifics are not treated as current syllabus facts.
Start closed-book

Find the weak link first

Each item tests a decision or calculation, not a definition. Your result points to the lesson to study first.

Question 1 of 10Evaluation

Read once · refer back often

The notation bridge

You do not need a mathematics degree. You do need to know what each symbol is doing.

Example and features

x is one input vector; xj is feature j. X stacks examples as rows. y is the true target; y^ is the prediction.

Parameters and hyperparameters

θ means parameters learned from training data, such as weights and biases. Hyperparameters—depth, k, C, or γ—are selected with validation data.

Loss and gradient

L(θ) scores error. Lw asks: “if weight w increases slightly, which way and how much does loss move?”

Shape

Wm×n means an m×n matrix. Multiplication works when the inner dimensions match.

Recurring operators

Σ means “add the indexed terms”; wT is a transpose; w·x is a dot product; w is vector length.

Tensor

A tensor is a multidimensional array. An image batch often has shape B×H×W×C: batch, height, width, channels.

scalars=3 vectorv=[31] matrixM=[3124]
01
Weeks 1–2

ML reasoning & evaluation

Choose the task, protect the test set, match the metric to the cost, and diagnose generalization from train/validation behavior.

1 · DefineName the concept and its job.
2 · MechanismShow the formula, flow, or calculation.
3 · PerturbState what changes when one condition moves.
4 · ConcludeChoose for the scenario and name the trade-off.
When ML is appropriate

Use ML when the mapping is too complex to hand-code, data provides a usable learning signal and evaluation criterion, and future cases resemble what can be learned. Prefer rules when requirements are exact, stable, and fully specified.

Representation

Representation means the numbers shown to the model. A house may become [size,rooms]; a CNN instead learns useful features from pixels.

Inductive bias (built-in preference)

Every learner prefers some solutions: KNN assumes nearby points behave alike; trees prefer axis-aligned rules; CNNs assume local patterns recur across position.

Best-possible boundary

The Bayes rule chooses the most probable class. Even the best possible rule must err when classes overlap or labels are noisy.

y^Bayes(x)=argmaxcP(Y=c|X=x)
Fitdata → features → training → learned model
Predictnew input → same feature transform → model → prediction
Learning setupSignal availableTypical taskRecognition cue
SupervisedDesired outputsRegression or classificationExamples include target values or labels.
UnsupervisedNo desired outputClustering or associationDiscover structure or co-occurrence.
ReinforcementReward from actionsSequential decision policyActions change later states and rewards.
Self-supervisedTargets constructed from raw dataRepresentation pretrainingMask, predict, or contrast parts of the input.

The lecture frames AI problem solving as a choice among exact algorithms, fast approximate solutions, hand-written if–then knowledge, and patterns learned from data. Use ML when the last option matches the evidence and cost—not merely because data exists.

Split by purpose, not habit

Training setFit weights and transformations.
Validation setChoose depth, threshold, epoch, and other hyperparameters.
Freeze choicesNo more tuning after this point.
Test setEstimate final performance once.
DeploymentMonitor shift and real costs.
Notebook trap: the Week 3 notebook selects tree depth using X_test; Week 6 early-stops and compares models on X_test. In both cases, that set has become validation data. A new untouched test set is required for an honest final estimate.

Threshold laboratory

Thirty fixed cases: 5 positive, 25 negative. Predict positive when score ≥ threshold. Your operational target is at least 90% recall.

Calculate + justify
Actual ↓
Pred +
Pred −
Positive
TP 4
FN 1
Negative
FP 4
TN 21
Accuracy83.3%
Precision50.0%
Recall80.0%
F161.5%

The same 30 cases, seen as curves

A single threshold gives one confusion matrix. Sweeping every threshold traces a curve, and the slider below marks where you are standing on it. ROC plots TPRvsFPR; the PR curve plots precision against recall and is the more honest view when positives are rare.

curve over all thresholds your current threshold random-guess baseline
TPR (= recall)
FPR (= 1 − specificity)
ROC AUC
Positive prevalence5 / 30 ≈ 16.7%

Read the axes before the shape. ROC AUC is threshold-free and ignores prevalence, so a rare-positive model can look excellent on ROC and poor on PR. The PR baseline is not the diagonal — it is the flat line at prevalence, here 5300.167. Moving the threshold slides you along a curve; retraining is what moves the curve itself.
Formula sheet and zero-denominator rule
N=TP+TN+FP+FNAccuracy=TP+TNN Precision=TPTP+FPRecall=TPTP+FNSpecificity=TNTN+FP F1=2PRP+R

If a denominator is zero, report the metric as undefined (), not as a confident zero. Trees and KNN may emit a label directly; logistic regression, SVMs, and neural classifiers often emit a score whose threshold determines the confusion matrix.

Multiclass: reduce to one-vs-rest

For each class, treat that class as positive and every other class as negative. Then aggregate.

AverageCalculationWhat it answersExam use
MacroMean of class metricsAre all classes treated equally?Prefer when rare classes matter.
WeightedMean weighted by class supportHow is performance across actual prevalence?Can hide weak rare-class performance.
MicroPool all TP/FP/FN firstHow are individual decisions doing overall?Dominated by common classes.
Worked 3-class matrix: one-vs-rest, macro, weighted, and micro

Rows are actual classes and columns are predictions:

C=[410131015]

For class A: TP=4,FP=1,FN=1, so precision = recall = F1 = 0.80. The class F1 scores are A = 0.80, B = 0.60, C ≈ 0.833.

F1,macro=0.80+0.60+0.83330.744 F1,weighted=5(0.80)+5(0.60)+6(0.833)160.750

Why: macro gives every class equal weight; weighted follows class support. In ordinary single-label multiclass classification, micro-F1 equals accuracy: here 1216=0.75.

Curve clinic

Predict the diagnosis before moving the capacity marker.

Read curves, not labels
Biasmedium
Variance riskmedium
Diagnosisbalanced region

Schematic seven-point example for reading curves; the exact shape is not a universal law. Choose capacity using the validation minimum, not the lowest training error.

𝔼𝒟,ε[(Yf^𝒟(x))2]=σε2+(𝔼𝒟[f^𝒟(x)]f(x))2+Var𝒟[f^𝒟(x)]

This decomposition is for expected squared-error regression. Use “bias/variance” qualitatively for classification unless the question specifies such a loss.

The four train/validation cases
  1. High train, high validation error: underfitting / high bias.
  2. Low train, much higher validation error: overfitting / high variance.
  3. High train, much higher validation error: high bias and high variance; improve representation/capacity and reduce overfitting.
  4. Low train, low validation error: useful low-bias, low-variance fit.

Separate deployment warning: if development scores are strong but deployment is poor, suspect leakage or distribution shift.

Feature engineering and feature selection — compact exam recap

Preprocessing changes existing feature values by a defined transformation: thresholding, binning, scaling, or one-hot encoding. Extraction creates new features from raw or multiple inputs. Selection keeps a subset. A threshold learned using labels is supervised; one chosen from feature distribution alone is unsupervised.

With n features there are 2n subsets. Exhaustive search becomes expensive. Forward selection adds the best next feature; backward elimination removes the least useful; wrappers score subsets with a model; filters score features without repeatedly fitting the final model.

Interaction trap: a univariate filter can discard features that are weak alone but decisive together. In XOR, neither x1 nor x2 predicts the class by itself, while the pair predicts it perfectly. Multivariate selection evaluates the joint subset.

Fold strip

Twelve development examples plus a sealed test set. Watch which rows train and which row validates, fold by fold.

Where does each example go?
trains the model validates this fold sealed test set — untouched
Model fits per setting4
Validation cases per fold3
Reported scoremean of 4 folds

The step students lose marks on: every preprocessing step that learns something — a scaler’s mean and standard deviation, an imputer’s median, a feature selector’s ranking — must be re-fitted inside each fold’s training portion only. Fitting it once on all development data leaks validation information into training and inflates every fold.
Holdout, k-fold, and leave-one-out
StrategyFitsStrengthCost / risk
Holdout1 per settingFast; simple on large dataEstimate depends on one split.
k-fold CVk per settingEvery example validates once; average the foldsMore compute; keep preprocessing inside each training fold.
LOOCVn per settingUses n−1 training cases per foldVery expensive; each validation fold has one case.

Cross-validation helps select hyperparameters. It does not license repeated inspection of the final test set.

Exit ticket: choose the metric

A cancer screener must catch at least 95% of true cases, while a human reviews flagged cases. Which constraint comes first, and how do you tune it?

Model answer: recall is the primary constraint because false negatives are costly. Lower the threshold until validation recall reaches at least 95%, then compare precision/workload among qualifying settings. Keep the test set untouched until the rule is frozen.

02
Week 3

Features & decision trees

Compute a weighted split, explain why the best feature wins, and trace how depth and pruning change bias and variance.

Entropy

Impurity is zero in a pure node and largest at a balanced binary node.

H(S)=c=1Cpclog2pc

Use the convention 0log20:=0.

Information gain

ID3 greedily chooses the split with maximum information gain: parent impurity minus size-weighted child impurity.

IG(S,A)=H(S)vValues(A)|Sv||S|H(Sv)
Stopping

Stop at purity, no useful features, minimum samples, or maximum depth. Pruning removes weak branches after growth.

The impurity curve

Every entropy number in this lesson is one point on this curve. Drag the mix and watch impurity rise toward the balanced middle and collapse at the pure ends.

Why balanced = 1 bit
Entropy H(p)1.000
Gini 2p(1p)0.500
Majority-class error0.500

Three facts the curve gives you for free. Entropy is 0 only at a pure node; it is maximal at the balanced node and equals exactly 1 bit for two classes; and it is concave, which is precisely why any split into children can never increase the size-weighted average impurity — information gain is never negative.

Weighted split laboratory

Play-Tennis target: 9 Yes, 5 No. The parent entropy is calculated below; then every candidate is compared with the same parent.

ID3 arithmetic
H(parent)=914log2914514log25140.9403
Weighted entropy = …
Weighted child entropy
Information gain
Best root among fourOutlook

Grow the tree one level at a time

The same 14 Play-Tennis examples. Each level is ID3 re-running the gain calculation inside every impure child.

Depth → error → variance
Leaves5
Training errors0 / 14
Training accuracy100%
Bias / variance pressurelow bias

The trap in “depth 2 is best”. Training error reaching zero is not evidence of a good tree — it is exactly what an unrestricted tree is guaranteed to do on clean, non-contradictory data. Depth must be chosen on validation data. Pre-pruning stops growth early (maximum depth, minimum samples, minimum gain); post-pruning grows fully and then removes branches that do not pay for themselves on held-out data.

From tree to rules

Each root-to-leaf path becomes an AND rule; alternative leaves become OR rules.

IF Outlook=Overcast → Play=Yes

Trees are interpretable because the prediction follows explicit feature tests, but small data changes can produce a different tree.

Perturbation checklist

  • Increase maximum depth → training error cannot increase; variance usually rises.
  • Increase minimum leaf size → simpler tree; bias usually rises, variance falls.
  • Add a noisy feature → a greedy split may overfit unless regularized/pruned.
  • Duplicate a case → counts and weighted gains change; recompute.
Do not skip the weights. A small perfectly pure child can still be less useful than a feature that improves many examples. Information gain weights each child by its fraction of the parent.
Continuous feature: how to find the split threshold on paper

Sort the distinct values, test midpoints between adjacent values, compute the weighted entropy for each threshold, then choose the largest gain.

Example: values 2, 4, 7, 9 create candidate thresholds 3, 5.5, and 8. A rule such as x5.5 makes left/right children; their class counts—not the numeric distance—determine entropy.

Exit ticket: why is “purest child wins” wrong?

Because a split creates several children and affects different numbers of examples. ID3 minimizes the weighted average child entropy, then subtracts it from parent entropy. One tiny pure child does not determine the whole split.

03
Weeks 3–4

KNN & SVM

Reason geometrically: who is a neighbor, which points define the margin, and what changes when one point or hyperparameter moves.

KNN: lazy local voting

Store training examples; at prediction time, measure distance, select k, and vote. Small k gives flexible boundaries; large k smooths them.

d2(x,z)=j=1d(xjzj)2
SVM: widest-gap separator

In 2D, SVM chooses a line with the widest gap between classes. The closest points are support vectors; distant points do not affect the line unless they become support vectors.

y^(x)=sign(wTx+b) one-sided margin=1wfull width=2w

These margin distances use the canonical scaling yi(wTxi+b)1.

KNN board

Move the query. The plot and distance calculation use the same selected coordinate space. The default case deliberately flips after standardization.

Distance → neighbors → vote
Click or drag anywhere on the board to move the query.
Predicted class
Vote
Other coordinate space

    x~j=xjμjσj

    For these ten training points, using population SD (divide by N): Feature 1 μ50.30,σ19.99; Feature 2 μ5.71,σ2.154. Both statistics come from training examples only.

    KNN exam facts
    • Scale features before distance if units differ; fit the scaler on training data only.
    • Choose k using validation or cross-validation. LOOCV holds out each training point once.
    • Euclidean uses straight-line distance; Manhattan sums absolute differences; Chebyshev uses the largest coordinate difference; cosine compares direction. Choose a metric whose geometry matches the features.
    • For weighted voting, a common rule is weight 1/d. If an exact zero-distance match exists, predict from zero-distance matches instead of dividing by zero.
    • A naive query compares all N cases. A kd-tree partitions by median coordinates and backtracks when another branch can beat the current neighbor radius; it helps mainly in lower dimensions.
    • Condensation tries to retain boundary cases and remove redundant interior points.
    • With standard assumptions, asymptotic 1-NN error is bounded by about twice Bayes error. Zero training error additionally assumes each point can vote for itself and there are no conflicting duplicates.

    Weighted-vote example: two A neighbors at distances 1 and 2 give wA=11+12=1.5. One B neighbor at distance 1.5 gives wB=11.50.667, so weighted KNN predicts A.

    Margin laboratory

    A real soft-margin SVM is solved on these points every time you move one. Drag a point and watch what the separator does — or refuses to do.

    Drag it. Prove it to yourself.
    class +1 class −1 decision boundary wTx+b=0 margins =±1 support vector
    Drag any point. Support vectors are ringed; try dragging one, then try dragging a far point.
    Margin width 2w
    w
    Support vectors
    Total slack ξi

    Three things to verify by hand before the exam. (1) Drag a point that sits far inside its own side — the boundary does not move, because its dual weight is α=0. (2) Drag a ringed support vector — the boundary moves immediately. (3) Push C toward zero with the outlier preset — the separator stops contorting to rescue that one point and the margin widens, which is exactly what “low C is more regularized” means geometrically.

    Perturbation table

    The same three cases stated as exam-ready sentences. Use the laboratory above to confirm each row, then learn the wording here.

    Which points define the boundary?
    Moved caseDual/slack stateBoundary consequenceReason
    Distant non-support pointαi=0Normally unchangedIt contributes nothing to w=iαiyiφ(xi).
    Support vectorαi>0Can moveThe point directly helps define the optimum separator.
    Overlapping outlierξi>0 if it violates the marginDepends strongly on CLow C accepts more slack; high C penalizes the violation more.

    minw,b,ξ12w2+Ci=1nξisubject toyi(wTxi+b)1ξi,ξi0
    C and kernels without slogans

    High C penalizes violations more, so the fit tends to contort more around training cases and may sacrifice margin. Low C tolerates more slack for a wider, more regularized separator. These are tendencies, not guarantees of perfect classification.

    A kernel replaces an explicit dot product with similarity in an implicit feature space. Polynomial: K(x,z)=(x·z+c)d. RBF: K(x,z)=exp(γxz2). High γ is more local; low γ is smoother. Scaling changes margins, dot products, and RBF distances, so fit scaling on training data and tune C,γ on validation data.

    Multiclass SVM counts

    A binary SVM needs a decomposition for K classes. One-vs-rest trains K classifiers. One-vs-one trains (K(K1)2). For 5 classes, that is 5 versus 10 classifiers.

    Exit ticket: add a point far from the SVM margin

    If it remains correctly classified and non-supporting, its dual weight is zero and the optimum boundary does not change. Moving a support vector can change the margin because support vectors define w.

    04
    Week 5

    Neural networks by hand

    Carry one example through affine layers, activations, loss, the chain rule, and a parameter update—without hiding behind a framework.

    Inputx=[1,2]
    Weighted sum + bias (affine)zh=Whx+bh
    ReLUh=max(0,zh)
    Outputzo=vh+bo,y^=σ(zo)
    Lossbinary cross-entropy against y

    One complete numeric update

    Fixed example and weights keep the arithmetic inspectable. Change only the learning rate and target.

    Forward → loss → backward → update
    x=[12],Wh=[0.50,0.25],bh=0,v=0.80,bo=0.30

    Forward pass

    Backward pass and new weights

    Prediction y^
    BCE loss
    Lzo

    The same update as a graph

    Backpropagation is not a separate algorithm to memorize — it is the chain rule walked backwards along this graph. Step through it: the forward sweep fills the green values, then each backward step multiplies the incoming gradient by one local derivative.

    Every backward arrow carries one multiplication. Sigmoid + binary cross-entropy is the special case where the two derivatives collapse into y^y — that cancellation is why this pair is always chosen together, and it is a frequent “explain why” question.

    Activation and its derivative

    The derivative is the multiplier backpropagation uses at this unit. Where the derivative is near zero, learning through this unit stops.

    Saturation, seen directly
    activation g(z) derivative g(z) your z
    g(z)
    g(z)
    Signal after 10 such layers
    Status

    Connect the two facts. Sigmoid’s derivative peaks at 14 and decays toward zero in both tails. Stack ten sigmoid layers and the best possible product of derivatives is (14)109.5×107 — that is the vanishing-gradient problem, and it is the reason ReLU (derivative exactly 1 on the positive side) became the default.
    Binary cross-entropy

    One sigmoid output for a binary target.

    LBCE=[ylny^+(1y)ln(1y^)]
    Categorical cross-entropy

    Softmax probabilities across mutually exclusive classes.

    pi=ezij=1Cezj LCE=i=1Cyilnpi
    Decision: binary target → one sigmoid output + BCE. One-of-C mutually exclusive classes → C softmax outputs + categorical cross-entropy.

    Softmax bench

    Three logits in, three probabilities out. The loss shown is the categorical cross-entropy paid for the true class you select.

    Logits → probabilities → loss
    Probabilities
    Sum1.000
    Loss lnptrue
    Gradient Lz=py

    Shift invariance is the exam question. Press “add +5” and watch every probability stay identical. Adding a constant c to every logit multiplies numerator and denominator by ec, so it cancels: softmax depends only on logit differences. This is also why implementations subtract max(z) before exponentiating — identical result, no numeric overflow.
    Activation choice and saturation

    Sigmoid is useful for a binary probability but saturates near 0 and 1, where its derivative becomes small. Tanh is zero-centered but also saturates. ReLU has derivative 1 for positive inputs and 0 for negative inputs; persistent negative pre-activations can create “dead” units.

    Exit ticket: why does backprop run backward?

    The loss depends on the output, which depends on hidden activations, which depend on earlier weights. The chain rule therefore starts with the loss derivative and multiplies local derivatives backward through that dependency graph.

    05
    Weeks 5–6

    Optimization & regularization

    Separate “can we minimize training loss?” from “will the learned solution generalize?” and diagnose the correct intervention.

    SGD

    Estimate the gradient from one example or a small batch. Each update is cheaper but noisier than using the full dataset.

    Momentum

    Accumulates a velocity so consistent directions accelerate and alternating directions cancel.

    gt=θL(θt) vt=βvt1+gtθt+1=θtηvt

    gt = current gradient, vt = velocity, β = momentum memory, η = learning rate.

    Adaptive scaling

    Adam-like methods use moment estimates to scale coordinates. Convenient, but learning rate and validation behavior still matter.

    Optimizer diagnosis: oscillation → reduce learning rate or use momentum. Training loss down while validation rises → restore the best checkpoint and regularize. Plateau → inspect learning rate, gradients, and capacity before choosing an intervention.

    Descent playground

    A genuine gradient descent run on an elongated quadratic bowl — the classic hard case. Every dot is one update; the contours are level sets of the loss.

    Learning rate, seen
    Loss after shown steps
    Distance to optimum
    Stability limit 2λmax
    Behaviour

    The one inequality worth memorizing. For a quadratic loss with largest curvature λmax, plain gradient descent converges only while η<2λmax. Below it you converge; above it you diverge; near it you oscillate across the valley. The curvature ratio is the second story: a long thin valley forces a small step in the steep direction, so progress along the flat direction crawls — and that is exactly the gap momentum closes.
    Batch, mini-batch, and stochastic — the same picture with noise

    Batch gradient descent uses all n examples per update: the smoothest path, the most expensive step. Stochastic uses one example: very cheap, very noisy, and the trajectory rattles around the optimum rather than settling. Mini-batch (typically 32–512) is the practical middle and is what “SGD” means in almost every framework.

    The noise is not purely a cost. It lets the iterate escape shallow local structure and acts as a mild regularizer, which is why the noisy path often generalizes at least as well as the exact one.

    Early-stopping clinic

    The validation minimum chooses the checkpoint. The test curve is deliberately absent.

    Choose without test leakage
    Best validation epoch5
    Current decision

    If you inspect a “test” curve to choose the checkpoint, that split has become validation data. Final testing happens once after the checkpoint rule and all other choices are frozen.

    MethodMechanismLikely effectImportant nuance
    L2 / weight decayPenalize squared weightsSmoothly shrink weightsUsually not exact zeros.
    L1Penalize absolute weightsCan create sparse weightsThe corner at zero helps produce exact zeros.
    Elastic netCombine L1 and L2L1 sparsity plus L2 shrinkageTwo strengths to tune.
    DropoutRandomly mask units during trainingDiscourage co-adaptationDisabled at inference; all units active under the framework’s scaling convention.
    Early stoppingKeep best validation checkpointLimits over-trainingValidation is not the final test.
    More data / augmentationIncrease useful variationOften lowers varianceAugmentations must preserve the label.
    Batch normalizationNormalize intermediate mini-batch statistics, then learn scale/shiftCan stabilize optimizationTraining and inference statistics differ.
    Regularization equations
    L2=L+λ2iwi2L1=L+λ1i|wi| Lelastic=L+λ1i|wi|+λ2iwi2

    Why L1 produces exact zeros and L2 does not

    Two weights, one loss. The shaded region is the budget the penalty allows; the ellipses are loss contours. The solution sits where the smallest reachable contour first touches the budget.

    Geometry, not slogan
    L1 solution L2 solution loss contours unpenalized optimum
    L1 solution
    L2 solution
    Exact zeros under L1
    Exact zeros under L20

    Say it with the corner. The L1 budget |w1|+|w2|t is a diamond whose corners lie on the axes, and a corner is where a contour is most likely to make first contact — contact on an axis means a coordinate is exactly zero. The L2 budget w12+w22t is a smooth circle with no corners, so contact almost never lands exactly on an axis: weights shrink toward zero without reaching it. Equivalently, L1 has a non-differentiable kink at zero whose subgradient can hold a weight pinned there; L2’s gradient 2λw vanishes as w0 and stops pushing.
    Learning-rate schedules and warmup

    A fixed rate is simplest. Step or exponential decay reduces it over time; cosine decay lowers it smoothly; a plateau scheduler reacts when validation improvement stalls. Warmup begins with small updates and raises the rate over early steps, which can stabilize large or sensitive models. The schedule changes step size, not the gradient direction itself.

    Neural hyperparameter checklist

    Architecture depth/width, activation, initialization, optimizer, learning rate and schedule, batch size, number of epochs, weight decay, dropout, normalization, augmentation, and checkpoint rule. Tune on validation evidence; do not list knobs without linking each to an observed failure.

    Exit ticket: train loss falls, validation loss rises after epoch 5

    The model is fitting training-specific variation after epoch 5. Restore the epoch-5 checkpoint and consider stronger regularization, augmentation, less capacity, or more data. Do not choose the epoch using the test set.

    06
    Week 7

    CNN: pixels to tensor shapes

    Perform one convolution, compute each output shape and parameter count, and explain why weight sharing matters.

    Local connectivity

    A kernel is a small learned weight grid; its receptive field is the input patch currently read.

    Weight sharing

    The same kernel slides across positions, reducing parameters and detecting a pattern wherever it occurs.

    Channels

    Each filter spans all input channels and produces one output channel.

    Convolution under the microscope

    Slide a 3×3 edge kernel across a 5×5 input. The selected nine products sum to one feature-map cell.

    Multiply → sum → move
    K=[101101101] Yr,c=i=02j=02Xr+i,c+jKi,j
    Selected output value
    Feature-map shape3 × 3
    Top-left 2×2 max pool

    Max pooling returns the largest value in each window and has no learned weights.

    Bright cells in the feature map are strong vertical edges; this kernel answers “is the left side brighter than the right?”.

    Single-layer shape ledger

    N,K,S,Cin,Cout must be positive integers; padding P must be a nonnegative integer.

    Most common calculation
    Nout=N+2PKS+1 Pconv=(KhKwCin+1)Cout

    The +1 assumes one enabled bias per output filter.

    Output tensor32 × 32 × 16
    Parameters448
    Layer validityvalid

    Three cases to recognize instantly. “Same” padding with stride 1 needs P=K12, which is why odd kernels (3, 5, 7) are the convention. “Valid” padding is P=0 and shrinks the map by K1 each layer. Stride s divides the size by roughly s, and the floor silently discards any incomplete final window — set N=7,K=2,S=2,P=0 above to see one input column go unused.

    Multi-layer ledger

    LayerInputOutputParametersReason
    Conv 3×3, same, 1632×32×332×32×16(32·3+1)·16=448Padding 1 preserves spatial size.
    MaxPool 2×2, stride 232×32×1616×16×160Halves height and width.
    Conv 3×3, same, 3216×16×1616×16×32(32·16+1)·32=4,640One bias per output filter.
    Flatten16×16×328,1920Reshape only.
    Dense 108,192108,192·10+10=81,930Dense layers often dominate parameters.
    Exit ticket: double the number of filters

    The output channel count doubles. Parameters in this layer double because each additional filter has its own K×K×Cin weights and bias. The next convolution’s parameter count can also rise because its Cin has doubled.

    07
    Week 7

    RNN & LSTM

    Trace information through time, explain vanishing gradients, and inspect how LSTM gates preserve or replace memory.

    Tokenrepresented numerically; an embedding is a learned dense vector
    Recurrent updateht=tanh(Wxxt+Whht1+b)
    Per-token outputslot or tag at time t
    Shared weightssame update at every position
    BPTTunroll and propagate loss through time
    Why gradients vanish: backpropagation through time repeatedly multiplies derivatives through time. Values mostly below 1 shrink distant influence; values above 1 can make it explode.

    A sigmoid gate acts like a valve: 0 blocks, 1 passes, and values in between pass a fraction.

    Gradient decay through time

    Backpropagation through time multiplies one factor per step. This plots how much of the gradient at step T still reaches step Tk.

    Why long dependencies die
    your factor reference: 0.5, 0.9, 1.0, 1.1 numerical floor
    Survives 10 steps
    Survives 50 steps
    Steps until 1% remains
    Regime
    hTht=k=t+1TWhTdiag(g)γTt

    Two different diseases, two different cures. γ<1 gives vanishing gradients: distant steps contribute nothing, training silently fails to learn long dependencies, and no amount of extra epochs fixes it — the architecture must change (gating, skip connections, attention). γ>1 gives exploding gradients: loud, visible NaNs, and it is cheaply fixed by gradient clipping. Notice the asymmetry — the quiet failure is the dangerous one.

    LSTM state inspector

    Use scalar gates to see the exact roles. Real LSTMs apply the same equations elementwise to vectors.

    Keep + write + reveal
    Retained ft·ct1
    Written it·gt
    New cell ct
    Hidden ht

    Read the cell state as a conveyor belt. ct=ftct1+itgt is additive, so the gradient along the belt is multiplied by ft rather than by a weight matrix and a squashing derivative. When the network learns ft1 the factor is ≈ 1 and gradients survive hundreds of steps. That single design choice — replacing a multiply-and-squash with an additive gated highway — is the whole answer to “how does LSTM address vanishing gradients?”.
    MechanismInformation pathStrengthBottleneck
    RNNCompress past into ht, step by stepNatural online processingLong gradient path; sequential computation
    LSTMGated cell state plus hidden stateBetter controlled long memoryStill sequential and compressed
    Self-attentionDirect weighted links between positionsShort dependency path; parallel over a known sequenceNeeds position information; full attention cost grows quadratically with length (standard clarification)
    GRU, bidirectional RNN, and seq2seq
    • GRU: a lighter recurrent unit with an update gate that mixes old/new state and a reset gate that controls how much past state helps form the candidate; fewer gates/parameters than LSTM, but still sequential.
    • Bidirectional RNN/LSTM: combines left-to-right and right-to-left states. Useful when the full input sequence is known; invalid for a strict online prediction that cannot see the future.
    • Sequence-to-sequence: the encoder hands a representation of the input to a decoder that emits an output sequence. Attention removes the fixed-vector bottleneck by letting each decoder step consult all encoder states.
    Exit ticket: set f=1 and i=0

    The cell state is copied exactly: ct=ct1. The output gate can still hide part of it from ht. This near-linear memory path helps preserve gradients across time.

    08
    Week 8

    Transformers, exactly

    Calculate scaled dot-product attention, place the causal mask correctly, and distinguish encoder, decoder, and cross-attention information flow.

    Query

    What the current position is looking for.

    Key

    What each candidate position offers for matching.

    Value

    The content blended after match weights are normalized.

    Queries, keys, and values are learned projections of token vectors. dk is the key-vector length; division by dk keeps large dot products from making softmax excessively sharp.

    S=QKTdk+M,A=softmaxrow(S),O=AV

    Mi,j=0 when allowed; Mi,j=−∞ when forbidden.

    Exact attention stepper

    Three fixed tokens and 2D vectors. Every displayed weight is calculated, not illustrative.

    Scores → mask → softmax → values
    Q=K=[100111],V=[1000101010],dk=2
    Key tokenq·k÷ √2After maskSoftmax weightWeighted V
    Attention output
    Weights sum

    The attention matrix

    Six tokens, real fixed embeddings, two real head projections. Every cell is Ai,j: how much row i attends to column j.

    Rows are queries
    weight ≈ 0 medium weight ≈ 1 masked, exactly 0

    Every row sums to exactly 1 — always check this first. Softmax is applied along each row, so a row is a probability distribution over the positions that query is allowed to see. Switch on the causal mask and the matrix becomes lower-triangular: the mask deletes the upper triangle before softmax, so the remaining entries in each row renormalize to 1 rather than simply being zeroed afterwards. Zeroing after softmax would leave rows summing to less than 1 and is a classic wrong answer.
    Why the matrix is why attention costs O(n2)

    The matrix has one cell per (query, key) pair, so a sequence of n tokens builds an n×n object: doubling the context quadruples the attention compute and memory. Against that cost you buy a constant path length — position 1 reaches position 1000 in one hop, where an RNN needs 999 sequential multiplications — and full parallelism over positions during training, since no cell depends on another cell.

    That trade is the entire RNN-versus-Transformer comparison in one sentence: quadratic cost bought a constant-length gradient path and parallel training.

    Architecture anatomy

    Encoder block
    1. Multi-head self-attention
    2. Residual Add & Norm
    3. Position-wise feed-forward network
    4. Residual Add & Norm
    Decoder block
    1. Masked self-attention
    2. Residual Add & Norm
    3. Cross-attention: decoder queries, encoder keys/values
    4. Residual Add & Norm
    5. Feed-forward, then Add & Norm
    Mask placement: add −∞ to forbidden logits before softmax. Their probability becomes zero. Teacher forcing trace: decoder input [BOS, A, B] targets [A, B, C]; the causal mask prevents each position from seeing later target tokens.

    Inside each block: residual paths preserve the block input; normalization controls scale; the feed-forward network applies the same small network independently to each token.

    Positional encoding
    PE(pos,2i)=sin(pos100002idmodel) PE(pos,2i+1)=cos(pos100002idmodel)

    0i<dmodel2.

    Self-attention alone has no inherent sensitivity to token order. Positional information is added or learned so permutations are distinguishable.

    Positional encoding, drawn

    Rows are positions, columns are embedding dimensions. Low dimensions oscillate fast; high dimensions oscillate slowly — together they give every position a unique fingerprint.

    Order, injected
    Fastest wavelength (dim 0)≈ 6.3 positions
    Slowest wavelength
    Similarity to position 0
    Vector norm

    The property the sinusoids were chosen for. Because sin(pos+k) and cos(pos+k) are fixed linear combinations of sin(pos) and cos(pos), the encoding of a position k steps ahead is a fixed rotation of the current one — the same rotation regardless of where you are in the sequence. A linear projection can therefore learn to read relative offsets, and the scheme extends to positions longer than any seen in training. Learned positional embeddings are simpler but have neither property.
    What multi-head adds

    Each head learns separate Q/K/V projections, performs attention in its own subspace, then the head outputs are concatenated and projected. This gives the block multiple similarity patterns at once; it does not guarantee that any head has a human-named linguistic role.

    BERT and self-supervised contextual learning

    Tokenization produces discrete IDs; initial embeddings plus position information enter a bidirectional encoder. Masked-language modeling predicts hidden tokens from surrounding context, creating contextual representations. The lecture also presents the original next-sentence objective. Fine-tuning adds a task head and updates some or all parameters.

    Exit ticket: remove positional information

    The model can still compare token content, but identical token multisets in different orders become difficult or impossible to distinguish from attention alone. It is more precise to say “no inherent order sensitivity” than “the Transformer is an unordered set model.”

    09
    Weeks 9–10

    LLMs in practice

    Select prompting, retrieval, or parameter adaptation from constraints; locate RAG failures; and choose a verification method.

    Chunk

    A passage cut from a source document.

    Embedding

    A vector used to compare semantic similarity.

    Index

    A searchable store of chunks and their vectors.

    Rerank

    Rescore a retrieved shortlist more precisely.

    Offlinedocuments → chunks
    Offlinechunks → embeddings → index
    Onlinequery → embedding → retrieve
    Onlineoptional rerank → selected evidence
    Onlineprompt + evidence → answer + citation
    Standard inference-time RAG changes the model’s context, not its weights. A retriever or generator can be trained separately, but retrieval at answer time is not itself fine-tuning.

    Adaptation decision lab

    Choose a scenario, commit to one or more methods, then check the rationale.

    Constraint → intervention
    Your method(s)

    Parameter-efficient adaptation

    MethodWhat changesBest fitKey limit
    PromptingNo weights; instructions/examples in contextFast behavior steeringContext cost and sensitivity; no new durable knowledge guarantee
    RAGContext receives retrieved evidenceFresh/private facts and citationsRetrieval and evidence-use failures
    Prompt tuningLearn continuous embeddings added at the model inputVery small task-specific stateMay be weaker for large behavior shifts
    Prefix tuningLearn K/V prefix vectors at every Transformer layerDeeper parameter-efficient steeringConsumes attention context at each layer
    AdaptersInsert small trainable modulesModular task/domain adaptationAdds modules at inference
    LoRALearn a low-rank update ΔW=BAStrong PEFT with limited memoryRank and target modules matter
    Partial fine-tuningUpdate selected pretrained layersMiddle groundMore memory and drift than PEFT
    Full fine-tuningUpdate all pretrained weightsLarge stable dataset + compute + deep changeCost, forgetting, version proliferation
    ΔW=BA,Ar×din,Bdout×r,rmin(din,dout)

    PEFT is motivated not only by memory and time, but also by the economic and environmental cost of repeatedly adapting very large models.

    LoRA: count the parameters yourself

    One frozen weight matrix, one low-rank detour. The bars are drawn to scale, so the saving is visible rather than asserted.

    The most calculable PEFT question
    Full ΔW per matrix
    LoRA B+A per matrix
    Trainable, whole model
    Fraction of full tuning

    Say why it works, not just what it does. The claim is that the update needed to adapt a pretrained matrix has low intrinsic rank, even though the pretrained matrix itself does not. So freeze W0 and learn only ΔW=BA with rd. Two consequences worth a mark each: B is initialized to zero so the adapted model starts exactly equal to the base model, and at deployment W0+BA can be merged into one matrix, so unlike adapters or prefix tuning LoRA adds zero inference latency.

    Six fact-checking strategies

    Rule-based

    Deterministic checks for format, ranges, or known constraints. Precise but narrow.

    Retrieval-based

    Compare claims with trusted external evidence. Good for factual grounding; retrieval quality is the gate.

    LLM as judge

    A second evaluation prompt scores support or consistency. Flexible but can share model biases.

    Self-reflection

    The model critiques and revises its answer. Cheap, but cannot invent missing evidence reliably.

    Self-consistency

    Sample multiple reasoning paths and aggregate. Helps when independent paths converge; costs more.

    Multi-agent verification

    Separate roles propose, retrieve, challenge, and adjudicate. More checks, more orchestration and correlated-failure risk.

    Agreement is not truth. Rules and retrieval can compare a claim with external evidence. Self-reflection, self-consistency, and extra agents test internal agreement unless they also consult trusted evidence.

    Domain-adversarial training

    Inputsource + target examples
    Feature extractorshared representation, then branch
    Label branch

    Feature → label predictor. Minimize source-label loss so features remain task-predictive.

    Domain branch

    Feature → gradient reversal (λ) → domain classifier. The classifier learns source vs target while the extractor receives the reversed domain gradient.

    The feature extractor helps the label task while confusing the domain classifier. Example: source = labeled hospital A; target = unlabeled hospital B. Preserve disease evidence while suppressing hospital/scanner cues. This assumes both domains share a useful labeling structure.

    θfLdλθfLd

    Locate the RAG failure

    A wrong answer is not “RAG failed”. Six different things can break, each with a different symptom, a different test, and a different fix. Pick the symptom you observe.

    Symptom → stage → fix
    The diagnostic move the professor is testing. Before proposing a fix, name the test that isolates the stage. Put the gold passage into the prompt by hand: if the answer becomes correct, retrieval is at fault; if it stays wrong, generation/grounding is at fault. That single experiment splits the pipeline in two and is worth stating explicitly in an answer.
    RAG failure diagnosis
    1. Evidence absent from the corpus: acquisition/coverage failure.
    2. Evidence exists but is split badly: chunking/indexing failure.
    3. Relevant chunk not retrieved: embedding/query/recall failure.
    4. Retrieved but ranked too low: ranking failure; consider a cross-encoder reranker.
    5. Evidence reaches prompt but answer contradicts it: generation/grounding failure.
    6. Answer is supported but citation is wrong: attribution failure.
    Chunking, bi-encoder retrieval, and cross-encoder reranking

    Fixed-size chunking is simple but may split a semantic unit. Semantic chunking follows topic or sentence boundaries, improving coherence at extra preprocessing cost. A bi-encoder embeds query and chunks separately for fast large-scale retrieval; a cross-encoder jointly reads each query–chunk pair for slower but more precise reranking of a small candidate set.

    Exit ticket: changing facts, strict citations, no training budget

    Use RAG: update the external index without retraining, retrieve trusted chunks, and require evidence-linked output. Prompting alone cannot supply unavailable private facts; fine-tuning is costly and a poor mechanism for weekly factual updates.

    Active recall · answer, then read the reason

    Drill bank

    Forty-eight one-move questions. Each is the smallest decision an exam question can hinge on, and each answer explains not only why the right option is right but why the tempting one is wrong.

    Drill 1

    0 correct · 0 attempted

    Wrong answers are the useful ones. If a drill catches you, open the lesson it names and redo that lab before moving on.

    Retrieval practice · the night before

    Flashcards

    Seventy-five cards graded the way spaced repetition works: anything you mark Again or Hard comes back inside this session, and Got it retires the card. Answer aloud before flipping — recognizing an answer is not the same as producing one.

    Retired cards stay retired until you reset the deck.

    Transfer · 100 marks

    Exam arena

    Older papers point to a stable question grammar. They do not define the current syllabus; they show how the professor asks.

    calculate from a small artifact draw or trace change one condition choose under constraints compare a precise pair challenge a claim

    Method marks matter. If the final number is wrong, show the formula, substitution, intermediate value, direction of change, and why your conclusion follows. Do not erase a defensible method.
    Self-marking total — / 100Mark yourself after each answer

    Write each attempt on paper first; open a model answer only after you have committed to yours, then enter your honest self-mark.

    10 marks

    Q1 · Threshold and metric

    Predict positive when score ≥ threshold. At threshold 0.50: TP=40, FP=10, FN=20, TN=930. Calculate accuracy, precision, recall, and F1. A safety rule requires recall ≥ 80%. In which direction should the threshold usually move, and what is the cost?

    Model answer, rationale, and marking
    Accuracy=9701000=97%Precision=4050=80%
    Recall=406066.7%F1=2(0.80)(0.667)0.80+0.66772.7%

    Rationale: lower the threshold. Some former false negatives cross into the positive region and become true positives, so recall can rise. The usual cost is more false positives and lower precision.

    Marks: 1 formula + 1 result for each metric (8), 1 direction, 1 trade-off.

    8 marks

    Q2 · Find the leakage

    A student standardizes the whole dataset, splits it, trains depths 1–10, selects the depth with the highest test F1, and reports that same F1. Identify two leaks and repair the workflow.

    Model answer, rationale, and marking

    Leak 1: the scaler learned test statistics. Put scaling and the model in one pipeline; inside each CV fold, fit the scaler only on that fold’s training portion and transform its validation portion. Leak 2: the test set selected depth, so it became validation data. Select depth by validation/CV, refit the frozen pipeline on the allowed development data, then use an untouched test set once. Why: any data that changes a model choice is development data, not an unbiased final test. Marks: 2 per leak, 2 per repair.

    12 marks

    Q3 · Weighted information gain

    A node has 6 Yes, 4 No. Split A gives left (4Y,0N), right (2Y,4N). Split B gives left (3Y,1N), right (3Y,3N). Compute both gains and choose the root. Use log2.

    Model answer, rationale, and marking
    H(parent)=0.6log20.60.4log20.40.971 HA410(0)+610(0.918)0.551,IGA0.9710.5510.420 HB410(0.811)+610(1)0.925,IGB0.9710.9250.046

    Rationale: choose A because it produces the larger reduction in weighted impurity.

    Marks: 2 parent entropy, 4 split A (weighted entropy + gain), 4 split B, 2 choice and reason.

    10 marks

    Q4 · KNN and SVM perturbation

    (a) One feature ranges 0–1 and another 0–10000. What fails in Euclidean KNN and how do you repair it? (b) Move a correctly classified non-support SVM point farther from the margin. What changes?

    Model answer, rationale, and marking

    (a) The 0–10000 feature dominates Euclidean distance because numeric units, not relevance, determine the sum. Fit a scaler on training data and apply the same transform to validation, test, and queries. (b) If the moved point remains non-supporting, αi=0, so it contributes nothing to the SVM weight vector and the optimum boundary/margin do not change. Marks: 3 diagnosis, 2 repair, 2 conclusion, 3 dual-weight mechanism.

    12 marks

    Q5 · Neural forward and backward

    Use ReLU in the hidden unit, sigmoid at the output, and binary cross-entropy:

    x=[1,2],Wh=[0.50,0.25],bh=0,v=0.80,bo=0.30,y=1

    Compute zh,h,zo,y^,L,Lzo,Lv, then update v,bo,bh by SGD with η=0.1.

    Model answer, rationale, and marking
    zh=0.5(1)+0.25(2)=1,h=1 zo=0.8(1)0.3=0.5,y^=σ(0.5)0.6225,L=ln(y^)0.4741 Lzo=y^y0.3775,Lv=(y^y)h0.3775 Lbo=Lzo0.3775,Lbh=(y^y)v0.3020 v0.8378,bo0.2622,bh0.0302

    Rationale: since y^y<0, subtracting the negative gradients raises the logit toward target 1.

    Marks: 5 forward quantities (5), output derivative (1), Lv (1), chain-rule bias gradients (2), three SGD updates (3) = 12.

    8 marks

    Q6 · Diagnose training curves

    Training loss falls every epoch; validation loss reaches its minimum at epoch 5 then rises. State the failure, checkpoint rule, two suitable interventions, and when the final test set is used.

    Model answer and marking

    Overfitting/high variance after epoch 5. Restore the epoch-5 validation checkpoint. Suitable interventions include more data/valid augmentation, stronger weight decay/dropout, reduced capacity, or early stopping. Use the final test set once, after the epoch and every other model choice are frozen. Marks: 2 diagnosis, 2 checkpoint, 1 each intervention, 2 test-set principle.

    10 marks

    Q7 · CNN ledger

    Input 28×28×3 enters a convolution with K=5, stride 1, padding 0, dilation 1, 8 filters, and one bias per filter; then a 2×2 max pool uses stride 2 and padding 0. Give both output shapes and the convolution parameter count.

    Model answer, rationale, and marking
    Nout=2851+1=24 Parameters=(52·3+1)·8=608

    Convolution output = 24×24×8. Pool output = 12×12×8 and pooling has no learned parameters.

    Rationale: each of the 8 filters spans all 3 input channels and produces one output channel; pooling changes spatial size but not channel count.

    Marks: 3 formula/substitution, 2 convolution shape, 2 parameters, 2 pool shape, 1 channel reasoning.

    8 marks

    Q8 · RNN to LSTM

    Explain why a plain RNN can lose a dependency across many steps. Then set LSTM f=1, i=0 and explain the result.

    Model answer, rationale, and marking

    Backpropagation through time repeatedly multiplies derivatives; factors mostly below 1 shrink the influence of distant steps. With f=1,i=0, ct=ct1, creating a direct memory path; the output gate still controls exposure in ht. Marks: 3 product mechanism, 1 consequence, 2 equation, 2 gate interpretation.

    12 marks

    Q9 · Masked attention

    For query q=[1,0], keys kA=[1,0],kB=[0,1], values vA=[10,0],vB=[0,10], and dk=2: compute the dot products, scaled scores, softmax weights, and output. Then place A at decoder position 1: B is a future token. Apply the causal mask and recompute the weights and output.

    Model answer, rationale, and marking
    [qTkA,qTkB]=[1,0],s=[12,0][0.707,0] a=softmax(s)[0.670,0.330],o=0.670[10,0]+0.330[0,10][6.70,3.30] smasked=[12,−∞]amasked=[1,0]omasked=[10,0]

    Rationale: the future token receives −∞ before softmax, so its probability is exactly zero.

    Marks: 2 dot products/scaling, 3 softmax, 2 output, 2 mask placement, 3 masked result.

    10 marks

    Q10 · LLM system choice

    A hospital assistant must answer from policies updated weekly, cite the exact passage, and run with limited training budget. Choose the primary adaptation method, outline the pipeline, name two independent failure points, then specify what the verifier checks and what counts as success.

    Model answer, rationale, and marking

    Choose RAG because the missing capability is fresh, citable external knowledge—not a permanent behavior change. Offline: chunk trusted policies, embed, and index them. Online: embed query, retrieve, rerank, place selected passages in the prompt, then generate an answer with passage identifiers. Independent failures include missing/poor chunks, retrieval miss, ranking miss, the generator contradicting evidence, or wrong citation attribution. Verification target: every factual claim and citation span. Success: each claim is entailed by the cited trusted passage, the passage identifier is correct, and unsupported claims are rejected or flagged. Marks: 2 choice/rationale, 3 pipeline, 1 each failure, 3 verification target and success rule.

    One page · print this

    Formula sheet

    Everything you might have to substitute numbers into, grouped by the question that asks for it. Reconstructing it from memory is a strong check that the calculation half of the exam is secure.

    Confusion matrix

    Acc=TP+TNNPrec=TPTP+FPRec=TPTP+FN
    F1=2PRP+RSpec=TNTN+FPFPR=1Spec

    Precision’s denominator is a column of the matrix; recall’s is a row. Zero denominator means undefined, not zero.

    Impurity and splitting

    H(S)=cpclog2pcGini=1cpc2
    IG=H(S)v|Sv||S|H(Sv)

    Useful values: H(0.5)=1, H(13)0.918, H(14)0.811, H(914)0.940.

    Distances and margins

    dp=(j|xjzj|p)1/px~=xμσ
    width=2wminw,b12w2+Ciξi

    p=1 Manhattan, p=2 Euclidean, p Chebyshev. One-vs-one trains K(K1)2 classifiers.

    Losses and their gradients

    LBCE=[ylny^+(1y)ln(1y^)]Lz=y^y
    pi=ezijezjzLCE=py

    σ(0)=0.5, σ(0.5)0.6225, σ(1)0.7311, σ=σ(1σ).

    Optimization and penalties

    vt=βvt1+gtθt+1=θtηvt
    L+λ2iwi2L+λ1i|wi|

    Quadratic stability: η<2λmax. L1 can zero a weight exactly; L2 shrinks without zeroing.

    Convolution shapes

    Nout=N+2PKS+1
    Pconv=(KhKwCin+1)CoutPdense=(nin+1)nout

    Pooling has zero parameters. “Same” padding at stride 1 needs P=K12.

    Recurrence and gating

    ht=tanh(Wxxt+Whht1+b)
    ct=ftct1+itgtht=ottanh(ct)

    Gates use σ (a valve in [0,1]); the candidate g uses tanh (content in [1,1]).

    Attention

    Attn=softmax(QKTdk+M)V
    Mij=0 allowed,−∞ forbiddenΔW=BA

    Cross-attention: queries from the decoder, keys and values from the encoder. LoRA trainable count =2dr.

    Provenance

    Source boundary

    This guide is synthesized from the files in this folder. Standard clarifications are labeled where they go beyond a slide’s wording. Notebook mistakes are taught as leakage/debugging exercises, not repeated as best practice.

    • Week 1 — Introduction to core concepts, part 1
    • Week 2 — Introduction to core concepts, part 2
    • Week 3 — Traditional ML algorithms 1 + sample notebook
    • Week 4 — Traditional ML algorithms 2: SVM
    • Week 5 — DL fundamentals, structure, optimization
    • Week 6 — DL regularization + sample notebook
    • Week 7 — CNN, RNN, LSTM architectures
    • Week 8 — Transformers
    • Weeks 9–10 — Adapting foundation models
    • Four older exam sets — question style only where material differs

    Deliberately excluded as current requirements: old exact datasets, obsolete Naive Bayes calculations, and modified-ID3 coefficients from past exams.

    What the labs actually compute

    No number in any lab is a hand-written illustration. Each one is calculated in the page from the stated inputs, so you can check the arithmetic against your own work and trust it when it disagrees with you.

    LabWhat is genuinely computedWhat is schematic
    Threshold, ROC and PRThe full confusion matrix, every metric, both curves and the ROC AUC, from 30 fixed scores.The 30 scores themselves are invented data.
    Curve clinicSeven-point train/validation curves are a schematic for reading shapes, not a fitted model.
    Impurity curve, split laboratory, tree growthEntropy, Gini, weighted child entropy, information gain, leaf counts and training errors on the real 14-row Play-Tennis table.Nothing.
    KNN boardDistances in the chosen metric and coordinate space, the neighbour vote, and the shaded decision region — recomputed per screen cell.The ten training points are invented data.
    Margin laboratoryA soft-margin SVM solved by sequential minimal optimization on every drag: dual weights, w, b, margin width, slack.Point positions are yours to set.
    Neural update, graph, activations, softmaxFull forward pass, every chain-rule gradient, the SGD step, activation derivatives, softmax and its loss.Nothing.
    Descent playgroundReal gradient descent with momentum on a quadratic, including the divergence check and the 2λmax limit.The loss surface is a chosen quadratic.
    L1 versus L2Closed-form solutions: soft-thresholding for L1, proportional shrinkage for L2, exact for the isotropic loss drawn.The loss is isotropic so the solutions stay checkable by hand.
    Convolution, shape ledgerEvery product and sum, the whole feature map, output shapes, parameter counts and discarded windows.Nothing.
    Gradient decay, LSTM cellExact powers of the per-step factor; exact gate arithmetic for ct and ht.Gates are scalars here; real LSTMs apply the same equations elementwise to vectors.
    Attention stepper, attention matrix, positional encodingScaled dot products, masking, row-wise softmax and the weighted value mixture; the sinusoidal encoding formula itself.Token embeddings and the two head projections are fixed, chosen to make content and positional behaviour visible.
    LoRA budgetExact parameter counts and ratios.Nothing.

    This page is a single file with no network requests: the mathematical typeface is embedded, so every equation renders identically offline, on any machine, and in print. Progress ticks and your theme choice are stored locally in this browser; drill answers and flashcard grades reset on reload by design, so a second attempt is genuinely a second attempt.