SBU · MSc · Exam Deck · 14 chapters
The whole course, compressed: every formula, architecture and trade-off you need to walk into the exam with. Arrow keys to move, T for contents, R to hide formulas and quiz yourself.
Part I · Chapters 1–4
CH 01 · Introduction · neuron model
weights = synaptic strength: $w\gt0$ excitatory, $w\lt0$ inhibitory. Bias shifts the firing threshold.
$z \ne y$. Net input in, activation out — classic exam trap.
CH 01 · Introduction · why parallelism wins
Intelligence is emergent — many simple units, massively parallel, asynchronous, with plastic connectivity (= learning).
| Brain | Computer | |
|---|---|---|
| Switching time | ~1 ms (10⁻³ s) | ~1 ns (10⁻⁹ s) |
| Signal speed | ~100 m/s | ~3×10⁸ m/s |
| Speed gap | machine ≈ 10⁶× faster per unit | |
| Units | ~10¹¹ neurons · 10¹³ synapses | ~10¹⁰ transistors |
| Wins at | perception, robustness | arithmetic, precision |
In: engineering view — neuron → layer → network. Out: neurobiology, VLSI hardware.
Local, direct weight updates — MCP · Hebb · Perceptron · Adaline · RBF · SOM · Hopfield
Chain rule pushes error backward — MLP · Deep nets · CNN · RNN · Autoencoders (+ SGD, dropout, batch-norm)
CH 01 · Introduction · 70 years in one line
1969: single-layer perceptron can't do XOR — wrongly generalized to all neural nets → funding collapse.
1986: backprop trains hidden layers → non-separable problems solved, critique voided.
2012: AlexNet = depth + GPUs + data. Deep learning era begins.
CH 02 · Origins · McCulloch–Pitts 1943
Unweighted binary inputs; the only free parameter is θ. Inhibitory input = absolute veto, not a negative weight.
| gate | weights | θ | note |
|---|---|---|---|
| AND | +1, +1 | 2 | line $x_1{+}x_2{=}2$ |
| OR | +1, +1 | 1 | line $x_1{+}x_2{=}1$ |
| NOT | inhibitory | 0 | $y=1-x_1$ · veto |
| XOR | impossible in one layer | ||
| binary inputs | → real-valued $x_i$ |
| hand-set θ | → learnable bias |
| equal weights | → free weights $w_i$ |
| separable only | → hidden layers |
Same summing hardware, but now the threshold is learnable like any weight. Watch the sign flip.
CH 02 · Origins · XOR · depth · UAT
no single line separates ● from ○ — band needs two lines
Stacked linear layers = one linear layer. Without $f$, depth buys nothing. (ReLU's corner at 0 is its nonlinearity.)
| hidden layers | boundary you can draw |
|---|---|
| 0 | straight line only |
| ≥ 1 | closed / connected curves |
| ≥ 2 | disjoint, arbitrary regions |
Existence only — says nothing about width needed or learnability. Params grow $(L{-}1)n^2$: linear in depth, quadratic in width → deep beats wide.
CH 02 · Origins · parameter sharing
The image version is really cross-correlation (no kernel flip) — identical for symmetric kernels.
| kernel 3×3 | effect |
|---|---|
| sharpen | 0,−1,0 / −1,5,−1 / 0,−1,0 — boost contrast |
| blur | (1/16)·[1,2,1 / 2,4,2 / 1,2,1] — smooth |
| outline | −1 ring around 8 — all edges |
| Sobel | 1,2,1 / 0,0,0 / −1,−2,−1 — horizontal edges |
| FC | one weight per input×output — params scale with image size |
| Conv | 9 weights + 1 bias (3×3), any image size |
Cat visual cortex (1959, Nobel 1981): simple → complex → hypercomplex cells = kernel → stacked conv layers. Local receptive fields, hierarchy of features.
CH 03 · Neuron models · hagan notation
Whole feedforward net = composition: $\mathbf{a}^3=f^3(\mathbf{W}^3 f^2(\mathbf{W}^2 f^1(\mathbf{W}^1\mathbf{p}+\mathbf{b}^1)+\mathbf{b}^2)+\mathbf{b}^3)$
Depth = number of weight layers. Input layer computes nothing and is not counted. First $L{-}1$ layers hidden, last is output.
Membrane as RC circuit; Nobel 1963. Model spectrum: HH → … → integrate-and-fire → our neuron (only the I/O relation survives).
| MCP | general | |
|---|---|---|
| inputs | {0,1} | ℝ |
| weights | fixed ±1 | learnable |
| threshold | hand-set θ | bias b = −θ |
| activation | hardlim | any f |
CH 03 · Neuron models · interactive
solid = f(n) · dashed = f′(n)
| name | range | use |
|---|---|---|
| hardlim / hardlims | {0,1} / {−1,1} | perceptron |
| purelin | ℝ | regression, Adaline |
| satlin / satlins | [0,1] / [−1,1] | clipped linear |
| logsig | (0,1) | output prob. |
| tansig | (−1,1) | hidden (zero-centered) |
| poslin = ReLU | [0,∞) | deep nets |
| compet | one-hot | winner-take-all (layer-wise) |
Corners (hardlim, satlin) break differentiability; sigmoids saturate; ReLU keeps gradient = 1 for n>0.
CH 03 · Neuron models · architectures
| feedforward | recurrent | |
|---|---|---|
| computes | static $a{=}F(p)$ | trajectory $a(t)$ |
| feedback | none | delay block D |
| needs | — | initial state $a(0)$ |
| behavior | one pass | converge · oscillate · diverge |
Depth counts forward weight layers; recurrence is feedback to an already-visited point. A 1-layer net can be fully recurrent.
Fully connected → sees entire input. Convolutional → local subset. Same math $f(\mathbf{Wp}+\mathbf{b})$, different sparsity of W.
CH 04 · Perceptron · rosenblatt 1958
1. pick $\mathbf w$ ⊥ desired boundary, pointing at class 1 · 2. plug one boundary point into $\mathbf w^T\mathbf p+b=0$, solve $b$. Any positive scaling works — solutions not unique.
Convention: $n=0$ outputs 1 — easy to miss under pressure.
$S$ neurons → $S$-bit code → up to $2^S$ classes (upper bound, not all realizable). OR: $\mathbf w=[0.5,0.5]^T, b=-0.25$ · AND: $[1,1]^T, b=-1.5$
CH 04 · Perceptron · learning rule + convergence
Don't forget the bias update — top exam error. Trace protocol: show $n, a, e$ for every sample before updating.
| error | meaning | action |
|---|---|---|
| e = +1 | said 0, truth 1 | w += p (pull toward) |
| e = −1 | said 1, truth 0 | w −= p (push away) |
| e = 0 | correct | no change |
Proof skeleton: alignment grows linearly $\mathbf u^T\mathbf w^{(k)}\ge k\gamma_g$, norm grows as √k $\|\mathbf w^{(k)}\|\le\sqrt{k}R$; Cauchy–Schwarz squeezes $k\le R^2/\gamma_g^2$.
Need $b\lt0$, $w_1\ge-b$, $w_2\ge-b$ → $w_1{+}w_2{+}b\ge-b\gt0$, but XOR(1,1)=0 needs it $\lt0$. ∎ Converges iff linearly separable — else updates forever.
Part II · Chapters 5–8
CH 05 · MLP · why hidden layers
Index convention: first = destination, second = source. Params: $M(D{+}1)+K(M{+}1)$.
GLM: features $\phi_i$ fixed by hand (engineering doesn't scale — $\binom{D+p}{p}$ monomials). MLP: hidden units are learned features.
| output activation | loss (from ML) | task |
|---|---|---|
| identity | SSE (Gaussian noise) | regression |
| sigmoid | binary CE (Bernoulli) | 2-class |
| softmax | multi-class CE | K-class |
1. all-linear layers collapse: $\sum_j w^{(2)}_{kj}w^{(1)}_{ji}=W_{ki}$ · 2. output $f$ only interprets range · 3. power lives in hidden nonlinearity.
Ridge (σ, tanh — global directions) vs RBF $e^{-\|\mathbf x-\boldsymbol\mu\|^2/2s^2}$ (local regions). tanh $=2\sigma(2a)-1$ — same model class.
CH 05 · MLP · the exam derivation
δ is sensitivity to the net input, not the weight gradient itself.
identity+SSE, sigmoid+BCE, softmax+CE — all give the same line (softmax: $\sum_k t_k{=}1$ one-hot).
Sum over downstream units; reuses forward weights in reverse. Deep nets: apply per layer, $\delta^{(l)}_i=h'(a^{(l)}_i)\sum_k w^{(l+1)}_{ki}\delta^{(l+1)}_k$.
tanh: $h'(a)=1-z^2$. Cost: one multiply per weight — vs finite differences' full pass per weight.
CH 05 · MLP · symmetry · init · early stop
permute hidden units (M!) × sign-flip odd activations ($2^M$). M=5 → 3840 copies of every minimum.
Equal weights → equal δ → identical updates forever → one effective hidden unit. Random init breaks the symmetry.
early stopping = capacity control by epochs
$E(\mathbf w)$ non-convex → only local minima guaranteed; use random restarts. Validation set touches no gradients.
x=(1, .5), tanh hidden: $z_1{=}.2913$, y=.1222, t=1 → $\delta_y{=}-.8778$, $\delta_1=h'(a_1)w^{(2)}_{11}\delta_y=-.4017$ — know how each number is produced.
CH 06 · SGD · three batch regimes
Training loss is a surrogate — the true target is unseen-data loss, so cheap noisy gradient estimates are legitimate.
| batch | stochastic | mini-batch | |
|---|---|---|---|
| m | N | 1 | 32–512 |
| gradient | exact | unbiased, very noisy | noise ∝ 1/√m |
| cost/update | O(N) | O(1) | O(m) |
| near minimum | step → 0 | noise ball — needs η decay | |
Steps shrink, total travel unbounded, total noise variance bounded.
1. vectorized hardware (matrix–matrix ≫ matrix–vector) · 2. 1/√m noise reduction with diminishing returns (100× data → only 10× less noise). Stability: $\epsilon\lt 2/H$.
CH 06 · SGD · heavy ball 1964 · nesterov 1983
Sign trap: $v$ already contains $-\epsilon g$, so update is $\theta{+}v$. Unrolled: $v_t=-\epsilon\sum_i\alpha^i g_{t-i}$ — an EWMA. α=0.9 → horizon ≈10; α=0.99 → ≈100.
Only difference: gradient at $\tilde\theta$, not θ. First step identical when $v_0=0$. Faster on smooth convex problems.
| high curvature | opposing gradients cancel → no zig-zag |
| small steady g | accumulates → bigger step |
| noisy g | averaged over horizon |
$L=0.5w_1^2+10w_2^2$, ε=0.1: plain GD gives $w_2\leftarrow-w_2$ — oscillates forever; momentum (α=0.5) kills it in 2 steps. Cause: one shared ε capped by the steepest Hessian direction.
CH 07 · Adaptive rates · live race, real update rules
■ SGD · ■ momentum · ■ RMSProp · ■ Adam
Equalizes scales, but $r$ only grows → η → 0 → premature stall on non-convex problems.
ρ=0.9. Accumulator saturates at $g^2$ → effective rate stabilizes non-zero. All ops elementwise ⊙ — never $g^Tg$.
CH 07 · Adaptive rates · kingma & ba 2015
Why correct: zero-init EWMAs underestimate by $(1-\rho^t)$ — $\mathbb E[s^{(t)}]=\mathbb E[g](1-\rho_1^t)$; dividing removes the bias exactly, matters most at small $t$.
| method | one-line identity |
|---|---|
| Delta-bar-delta | grow η if sign stable — full-batch only |
| AdaGrad | ÷√(sum g²) — rate dies |
| RMSProp | ÷√(EWMA g²) — the go-to |
| Adam | + 1st moment + bias fix |
| AdaDelta | numerator = RMS(Δθ) — no ε to tune |
| AdaMax | ℓ∞ norm: u←max(ρ₂u,|g|) |
| Nadam | Adam + Nesterov look-ahead |
Adam fastest early; tuned SGD+Nesterov often lowest at epoch 45; AdaGrad lags badly non-convex. Adaptive methods damp dropout noise.
CH 08 · Regularization · penalized loss
Constant percentage shrink — never exact zeros. Gaussian prior, $\lambda=1/\sigma^2$. Unhalved penalty ⇒ $(1-2\eta\lambda)$ — watch the convention.
Constant amount $\eta\lambda$ per step → exact zeros → feature selection. Laplace prior, $\lambda=1/b$.
Biases don't multiply inputs — penalizing them just shifts outputs wrong.
| diagnosis | signature | fix |
|---|---|---|
| underfit | both errors high | capacity / optimize |
| overfit | train low, val high (gap) | regularize |
CH 08 · Regularization · hinton 2012 · ioffe–szegedy 2015
Same mask forward and backward (fresh mask = corrupted gradient). Output layer never masked. Test: scale by $1{-}p$, or inverted dropout $\tfrac{1}{1-p}$ at train.
Kills co-adaptation; trains an implicit ensemble of $2^{\#units}$ weight-sharing subnets; p=0.5 default. ≈ adaptive data-dependent L2.
Between linear map and nonlinearity. γ, β can undo normalization ($\gamma{=}\sqrt{\epsilon+\sigma^2},\beta{=}\mu$) → capacity unchanged, only optimization dynamics.
Inference uses running averages, not batch stats → deterministic. Batch noise = incidental regularizer; modern view (2018): benefit = smoother loss landscape, not covariate shift.
Part III · Chapters 9–11
CH 09 · CNNs · the workhorse formula, live
Weights independent of position (r,s) = sharing. DL "convolution" = cross-correlation (no flip) — irrelevant for learned kernels.
blue = kernel footprint · gray ring = zero padding
Images are stationary — same local statistics everywhere. LeNet C1: conv = 156 params vs FC alternative > 4.8 M.
CH 09 · CNNs · favorite exam distinction
Convolution is equivariant to translation, NOT invariant. Pooling supplies local approximate invariance.
Fixed rule, zero parameters. Typically 2×2 stride 2. Max ≳ average empirically. Cost: precise positions unrecoverable after a few rounds — genuine trade-off.
Paired test on disagreements; same error totals can be significant (9²/12=6.75) or not (9²/40=2.03).
CH 09 · CNNs · landmark architectures
ReLU · local response norm · dropout p=.5 in FC · augmentation (crops+flips, 10-patch test) · 2× GTX 580 GPUs
$\lfloor(224{-}11)/4\rfloor{+}1=54\ne55$; solving gives $W=227$.
[conv+ReLU ×n → pool]* → flatten → FC → softmax. Spatial ↓ while channels ↑ — resolution traded for representation.
CH 10 · CNN backprop · the headline results
FC: each weight used once → single product $g_ih_j$. Conv: kernel reused at every position → sum over all positions.
Same op used forward as upsampling (segmentation, generative nets). "Deconvolution" is not an inverse — it's $W^\top$, not $W^{-1}$.
| conv layer | 2 gradients: ∂J/∂K + ∂J/∂V |
| pooling layer | 1 gradient: ∂J/∂V only (no params) |
Generic backprop: recurse over consumers with a memo table; cost ∝ #edges ≈ forward pass. Symbol-to-symbol graphs enable higher-order grads.
V 3×3, K=[[1,0],[−1,2]], G=[[1,−1],[2,0]] → ∂J/∂K=[[−1,4],[3,0]], ∂J/∂V=[[1,−1,0],[1,3,−2],[−2,4,0]].
CH 10 · CNN backprop · routing the gradient
Common mistake: dividing the max gradient by window size. All of $G$ goes to the argmax; losers get exactly 0 — and zero training signal.
worked ex 10.3 — each G lands on its window's max
| fully connected | no locality, no sharing |
| locally connected | local, private per position |
| tiled (period t) | t kernels cycle; bias $C_{out}{\times}t{\times}t$ |
| standard conv | t=1 · full sharing · bias $C_{out}$ |
Index shift $j{+}m{-}1\to(j{-}1)s{+}m$; s=1 recovers standard. Can replace pooling.
Max pool: a.e. differentiable (ties = measure zero). Average: smooth everywhere.
CH 11 · CNN design · three structural priors
| 320×280 img · 2×1 kernel | stored floats | ops |
|---|---|---|
| dense matrix | > 8×10⁹ | > 16×10⁹ |
| sparse matrix | 178,640 | 267,960 |
| convolution | 2 | 267,960 |
Sparsity fixes the op count; only sharing fixes storage — the sparse→conv gap is entirely parameter sharing.
Width-3 kernels: layer-2 unit already sees 5 inputs. Deep stacks of small kernels capture long-range structure.
No padding: lose $F{-}1$ width per layer → forced shallow. "Same" padding → arbitrarily deep.
CH 11 · CNN design · from trunk to prediction
| head (trunk → 16×16×64) | extra params | var. size? |
|---|---|---|
| flatten + dense 1000 | ≈ 16.4 M | no |
| pool to 3×3 + dense | ≈ 0.58 M | yes |
| fully conv + global avg pool | ≈ 0 | yes |
| family | one-line identity |
|---|---|
| spatial transducer | fully convolutional, no dense anywhere |
| all-convolutional | no pooling — strided conv downsamples |
| Inception | parallel multi-scale kernels per stage |
| ResNet | additive identity skips → extreme depth |
y = ReLU( x + F(x) ) — gradient rides the skip undiminished
Trained first-layer kernels ≈ Gabor functions (V1 simple cells) — real but limited analogy: first layer only, backprop implausible.
Part IV · Chapters 12–14
CH 12 · RNNs · three matrices, any length
folded self-loop = unrolled chain · same three matrices at every step
$h_t$ is an activation, not a parameter — init to zeros, reset between sequences (stale-context bug).
| variable length | ✓ recurrence |
| long-term deps | ✗ fixed window |
| order matters | ✗ bag-of-words |
| share params | ✗ big slotted window |
|V|=10k, window 20, H=100: slotted = 20 M weights; shared = 1 M, independent of length. CNN shares across space, RNN across time.
CH 12 · RNNs · karpathy taxonomy
two axes only: input single/sequence × output single/sequence — cell equations never change
Each shared weight collects one gradient contribution per step used — that sum is BPTT.
Aligned equal-length (POS tags, music) works directly; translation needs encoder–decoder — whole input → one bottleneck vector → decode.
CH 13 · BPTT · werbos 1990
Recurrent term absent only at $t{=}T$. Omitting it = most common error. Then $\partial L/\partial W_{hh}=\sum_t\delta_t^a h_{t-1}^\top$ with $\delta_t^a=g_t\odot(1-h_t^2)$.
$\rho\gt1$ → explode; $\rho\lt1$ (typical — $|\tanh'|\le1$) → vanish. Systematic bias toward short-term deps: "clouds → sky" survives, "France → French" dies.
By value: $\mathrm{sign}(g_i)\min(|g_i|,\text{thr})$ — can bend direction. Clipping cannot fix vanishing — it only shrinks. Classic trap.
| ReLU | f′=1 for a>0, but W_hh untouched |
| identity init | W_hh=I — drifts during training |
| gated cells | the only architectural fix → |
CH 13 · LSTM · hochreiter & schmidhuber 1997 · hover a gate
memory crosses time through × and + only — never a matrix multiply
No $W_{hh}$ factor — with $f_t\!\approx\!1$ the product needn't vanish. Two states $(c_t,h_t)$; 4× the weights of vanilla.
CH 13 · GRU · cho et al. 2014
$z_t$ couples keep/write ($1{-}z_t$ and $z_t$ sum to 1) ≈ combined $f_t,i_t$; $r_t$ gates the candidate's view of the past; no output gate, no $c_t$.
Empirically comparable. GRU cheaper (3× weight sets); LSTM can keep old memory and write lots of new info at once — GRU's coupling can't. Neither universally wins.
| vanilla RNN | LSTM | GRU | |
|---|---|---|---|
| state | $h_t$ | $c_t$ + $h_t$ | $h_t$ |
| gates | — | f, i, o + c̃ | r, z + h̃ |
| update | full overwrite | additive | interpolation |
| memory Jacobian | diag(tanh′)·Whh | ≈ diag(ft) | ≈ diag(1−zt) |
| vanishing | severe | mitigated | mitigated |
| weight sets | 1× | 4× | 3× |
$h_{t-1}{=}.5, c_{t-1}{=}.2, x_t{=}1$: LSTM → $f{=}.818, i{=}.777, \tilde c{=}.762, c_t{=}.755, h_t{=}\mathbf{.522}$ · GRU → $r{=}.818, z{=}.777, \tilde h{=}.721, h_t{=}\mathbf{.672}$
CH 14 · Transformers · vaswani et al. 2017
Each query scores every key by dot product; softmax turns scores into weights; output = weighted average of values. A dictionary lookup, but soft — every entry contributes.
Dot products grow with dimension → softmax saturates at one-hot → gradients vanish. Scaling keeps variance ≈ 1. Same saturation story as sigmoids in ch 3.
| tensor | role | asks |
|---|---|---|
| Q query | what I'm looking for | "who is relevant to me?" |
| K key | what I advertise | "match me against queries" |
| V value | what I hand over | "take this if I win" |
Encoder–decoder RNNs squeeze the whole source sentence into one fixed vector — long sentences degrade. Attention lets the decoder look back at all encoder states, weighted per step (Bahdanau 2014).
CH 14 · Transformers · self-attention · heads · position
Every token queries every token — including itself. The three learned projections let "what I seek", "what I show" and "what I give" differ; without them attention would be plain symmetric similarity.
$d_k=d_{model}/h$ (512/8 = 64): h views for ≈ the price of one full-width head. Heads specialize — syntax, coreference, position — emergently, never by supervision.
Self-attention is permutation-equivariant — shuffle the tokens, outputs shuffle identically. Adding a position fingerprint to each embedding breaks the tie.
Geometric wavelengths $2\pi\!\to\!10000\!\cdot\!2\pi$: each position gets a unique multi-frequency code, and $PE_{pos+k}$ is a linear function of $PE_{pos}$ — relative offsets are easy to learn. Learned position embeddings work equally well (BERT uses them).
"Multi-head = more parameters" — false. Heads split $d_{model}$; total projection cost stays ≈ constant. The win is diversity of attention patterns, not capacity.
CH 14 · Transformers · attention is all you need
residual skips (dashed) = the gradient highway
| RNN / LSTM | Transformer | |
|---|---|---|
| max path length | O(n) | O(1) |
| sequential ops | O(n) — no parallel train | O(1) — fully parallel |
| per-layer cost | O(n·d²) | O(n²·d) — length hurts |
| order handling | built-in recurrence | injected via PE |
| long memory | gated (ch 13) | direct access |
−∞ before softmax → weight exactly 0: no peeking at the future. Plus cross-attention: Q from decoder, K,V from encoder.
Finale · if you remember nothing else
Press R and run the deck again — if you can recall each card from its label alone, you're ready. Good luck. Σ