Neurons and Gradients.
Chenzi Xu · chenzi.xu@ntu.edu.sg
1. The cepstrum as a second transform: what gets transformed, and why the axis is a time
2. Likelihood versus prior in Bayes' rule: which factor is which, and which model supplies each
3. Reading the DTW table: where a cell's value comes from, and what the backtrace means
4. Source and filter: which parts of the spectrum come from the vocal folds (the harmonics) and which from the vocal tract (the formants)
Also today: Assignment 1 is released. In the practical you measure slopes, run gradient descent, and train a vowel classifier.
1. The fundamental equation of classical ASR?
Ŵ = argmaxW P(X | W) · P(W): the acoustic model's likelihood times the language model's prior
2. In the HMM, what did the Gaussian bells do?
emission scores: how likely a frame is under each state; the bell shape was chosen by hand, its centre and width estimated from data
3. What does one Viterbi cell hold?
the probability of the best path that ends in that state at that frame
4. How were the HMM's probabilities trained?
Baum-Welch: start from guesses, work out how probably each frame belongs to each state, re-estimate, repeat
5. What was the classical stack's main weakness?
each frame is scored on its own, so the order of frames is invisible; deltas and triphones were the patches
Released: today, 25 Sep
Data request: this week
Due: Fri 23 Oct (Week 10)
Weight: 30%
Recess is next week: a quiet stretch to read the brief properly.
Take the weighted sum. Add a squash. Let the data choose the weights.
mel_frame = melfb @ power_spec
log_mel = librosa.power_to_db(mel_frame)
y = σ( w · x + b )
Each layer's output is a new set of coordinates for the input, an embedding: nearby points are similar. The F1 × F2 vowel chart is an embedding phoneticians built by hand; a network learns its own, with more dimensions.
A one tidy unit per phoneme, like labelled buttons
B useful acoustic pattern detectors, formant-like but unlabelled
C uninterpretable noise that happens to work
Mostly B, with some C: studies that inspect trained networks find early layers acting like filterbanks and later ones grouping sounds much as phonetic features do, although nobody built that in (Sainath et al. 2013; Nagamine et al. 2015).
Ten minutes.
Then the one new piece of maths this term.
So far the network is frozen: weights fixed, nothing learned. After the break: how to score its mistakes (the loss), then how the weights are learned.
| P(correct answer) | 1.0 | 0.9 | 0.5 | 0.1 | 0.01 |
| loss = −log P | 0 | 0.11 | 0.69 | 2.30 | 4.61 |
natural log; the dots on the curve mark P = 0.9, 0.5 and 0.1
p(x): how often outcome x really occurs (the data)
q(x): the probability the model gives to x
−log: surprisal: small for expected outcomes, large for surprising ones
− Σ p(x) · …: add up over all outcomes, each weighted by how often it occurs: an average
| vowel | /i/ | /ɑ/ | /u/ |
| p (label) | 1 | 0 | 0 |
| q (softmax) | 0.71 | 0.19 | 0.10 |
H(p, q) = −(1 · log 0.71 + 0 · log 0.19 + 0 · log 0.10) = −log 0.71 = 0.34
The zeros remove every term except the correct vowel: cross-entropy = −log P(correct answer), the loss.
Learning is one question:
which way is downhill?
Downhill means: the direction that lowers the loss.
Measure the slope, take one step against it, repeat.
The function: f(x) = x². In Python, ** means “to the power of”: 3.01**2 is 3.01².
(3.01**2 - 3**2) / 0.01
6.009999… the slope of x² at x = 3 is 6
(3.0001**2 - 3**2) / 0.0001
6.0000999… smaller nudge, cleaner slope
Calculus gives the exact answer without nudging: for x² the slope at x is 2x. We will take such recipes as given; the point is what a slope means, and the nudge test always works.
x ← x − η · slope
Move against the slope: downhill. The small number η (eta) is the learning rate: the size of each step.
Illustrative values: input x = 2 and weight w = 0.5 give z = 1, so y = σ(1) ≈ 0.73 (bias left out). σ: the sigmoid, 1 / (1 + e−z).
For the curious: two extra slides on the chain rule, with worked examples, in the appendix at the end of the deck.
loss.backward()
One line: the library differentiates the whole network for you. Understanding the slope is your job; computing a million of them is the machine's.
Week 5's recognizer stored one speaker's token. This one sees many speakers: it learns each vowel's distribution, which the template lacked.
A simplified model for the picture: one centre per vowel, so the boundaries are straight. The practical's network draws its own, curved ones.
Gradient descent uses it at every step
When to stop, how many hidden units, which learning rate. Checked many times
How well the model does on new speakers. Used once, at the end, never for choices
Jurafsky & Martin, §3.2: evaluating any machine learning model needs “at least three distinct datasets”: training, development and test.
Why wait N epochs: the loss goes up and down a little, so one rise is not yet the turn (epochs 6, 9 and 12 in the figure).
No fixed number of epochs: the turn depends on the network's size, the amount of data and the learning rate.
This is the hybrid system on last week's timeline: the HMM structure stays and the network replaces only the emission scores. It reads a window of neighbouring frames at once, which eases last week's frame-independence weakness; error rates fell sharply (Hinton et al. 2012).
At scale: today's example has two inputs and three outputs; production networks take dozens of log-mel channels over many frames and have millions of weights. The same parts: matrix, squash, loss, slope.
No class on Friday 2 October. Before Week 8 (Friday 9 October): the attention video and the Assignment 1 brief.
Nudge. Descend.
Then train a vowel classifier.
Open the Week 7 notebook (link on NTULearn). In the next hour you measure slopes, run gradient descent, and train a vowel classifier yourself.
Stretch (pick one, take-home): overfit on purpose (a large network on 10 tokens per vowel) · sweep the hidden-layer size from 1 to 100 · add your own three vowels measured in Praat: does a model trained on Michigan English classify your accent?
decision regions over the vowel chart, tested on speakers the network never saw
The stretch (pick one) is take-home; the five stages above are the in-class core.
A slope you measured by nudging, a gradient-descent run you broke on purpose, and a vowel classifier scored on speakers it never saw.
If the update line is unfinished, a fallback keeps the descent running.
“The building block of a neural network is a single computational unit. A unit takes a set of real valued numbers as input, performs some computation on them, and produces an output.” Here: a weighted sum plus a bias, then a squash.
Jurafsky & Martin, SLP 3rd ed., §6.1 (quoted; Aug 2026 draft); last sentence: course gloss.“A feedforward network is a multilayer network in which the units are connected with no cycles; the outputs from units in each layer are passed to units in the next higher layer, and no outputs are passed back to lower layers.”
Jurafsky & Martin, SLP 3rd ed., §6.3 (quoted; Aug 2026 draft).The slope of a function at a point: the rate at which the output changes for a small nudge of the input. At a local minimum the derivative is zero.
Standard definition, course wording; see 3Blue1Brown, Essence of Calculus, chs. 1–2.“[G]radient descent requires knowing the gradient of the loss function, the vector that contains the partial derivative of the loss function with respect to each of the parameters.” Each step moves every parameter against its slope, scaled by the learning rate.
Jurafsky & Martin, SLP 3rd ed., §6.6 (quoted; Aug 2026 draft); last sentence: course gloss.A neuron has weights w = [2, −1], bias b = −4, and input x = [3, 1]. Compute w · x + b, then the output σ(w · x + b), given that σ(1) ≈ 0.73.
Measure the slope of f(x) = x³ at x = 2 by nudging: compute (2.01³ − 2³) / 0.01. The calculus recipe says the slope is 3x². Do the two answers agree?
For f(x) = x², the slope at x is 2x. Starting at x = 3, take one gradient-descent step with η = 0.1, and another (from x = 3 again) with η = 1.1. Which step helps, which harms, and how can you tell?
Your vowel net scores 98% on its training speakers and 71% on a new speaker. Name the phenomenon, the data that revealed it, and one remedy.
Worked answers in the appendix at the end of this deck.
1. A neuron is a weighted sum, a bias, and a squash: Week 5's template made soft and learnable
2. The derivative is a slope; the nudge test measures it with arithmetic alone
3. Learning is sliding downhill on the loss; the learning rate decides whether it crawls, settles, or diverges
4. Held-out speakers are the test: a network that memorises its training speakers has not learned the vowels
Radar: recess next week, no class on 2 October. Over the break: the attention video, the Assignment 1 brief, and the data-access request. Quiz 2 (Week 12) covers Weeks 6 to 11, so today's neuron is on it.
§6.1 (units), §6.3 (feedforward networks) and §6.6 (training); skim the backpropagation maths. Chapter numbers follow the Aug 2026 draft. web.stanford.edu/~jurafsky/slp3/6.pdf
Layers and weights, then this week's hardest idea; watching the second video twice is a good use of time. youtube.com/watch?v=aircAruvnKk · youtube.com/watch?v=IHZwWFHWa-w
Watch decision boundaries form in the browser, no code. playground.tensorflow.org
The derivative from first pictures, if today's slope needs a slower treatment. 3blue1brown.com/topics/calculus
Required before Week 8; watch it over the recess. 3blue1brown.com/lessons/attention
Read through the collapsing rule; the animations are the point. distill.pub/2017/ctc
The CTC and Seq2Seq pages. huggingface.co/learn/audio-course/chapter3/introduction
web.stanford.edu/~jurafsky/slp3/16.pdf
The introduction and approach sections of each. arxiv.org/abs/2212.04356 · arxiv.org/abs/2006.11477
One matrix. One squash.
Then slide downhill.
That is a neural network, and you trained one on real vowels. Week 8, after the recess, “The End of the Assembly Line”: end-to-end recognition, attention, and Whisper.
Jurafsky, D. & Martin, J. H. Speech and Language Processing, 3rd ed. (Aug 2026 draft). Ch. 6, §6.1 (units), §6.3 (feedforward networks), §6.6 (training, the cross-entropy loss). Definitions quoted on the formal slide.
Rumelhart, D. E., Hinton, G. E. & Williams, R. J. (1986). “Learning representations by back-propagating errors.” Nature 323(6088), 533–536. Backpropagation.
Hillenbrand, J., Getty, L. A., Clark, M. J. & Wheeler, K. (1995). “Acoustic characteristics of American English vowels.” JASA 97(5), 3099–3111. The vowel data.
Barreda, S. (2023). phonTools: Tools for phonetic and acoustic analyses. R package version 0.2-2.2, CRAN. The copy of the Hillenbrand data used here.
Hinton, G., Deng, L., Yu, D., Dahl, G. E., Mohamed, A., Jaitly, N., Senior, A., Vanhoucke, V., Nguyen, P., Sainath, T. N. & Kingsbury, B. (2012). “Deep neural networks for acoustic modeling in speech recognition.” IEEE Signal Processing Magazine 29(6), 82–97. The hybrid recognizer.
Sainath, T. N., Kingsbury, B., Mohamed, A. & Ramabhadran, B. (2013). “Learning filter banks within a deep neural network framework.” IEEE ASRU 2013, 297–302.
Nagamine, T., Seltzer, M. L. & Mesgarani, N. (2015). “Exploring how deep neural networks form phonemic categories.” Proc. Interspeech 2015, 1912–1916.
Pedregosa, F. et al. (2011). “Scikit-learn: machine learning in Python.” Journal of Machine Learning Research 12, 2825–2830. The practical's classifiers.
Sanderson, G. (3Blue1Brown). Neural networks and Essence of Calculus, video series. 3blue1brown.com
w · x + b = 2·3 + (−1)·1 − 4 = 1. Output σ(1) ≈ 0.73: moderately confident evidence for the pattern this neuron detects.
(2.01³ − 8) / 0.01 = (8.120601 − 8) / 0.01 = 12.06. The recipe gives 3 × 2² = 12. They agree to the accuracy of the nudge; shrink the nudge and the gap shrinks with it.
Slope at 3 is 6. With η = 0.1: x becomes 3 − 0.6 = 2.4, closer to the minimum at 0: the step helps. With η = 1.1: x becomes 3 − 6.6 = −3.6, farther from 0 than where it started: the step overshoots and the run diverges. The tell is distance from the minimum (or simply the loss) increasing after the step.
The phenomenon is overfitting: the net memorised its training speakers. The data that revealed it is held-out data, here a held-out speaker. Remedies: stop training earlier, shrink the network, or train on more speakers; all three trade memorisation for generalisation.
inside u = 3x + 1 → slope 3 outside y = u² → slope 2u = 8 (u = 4 here) whole 8 × 3 = 24
((3*1.001 + 1)**2 - (3*1 + 1)**2) / 0.001
→ 24.009 the nudge test agrees
dy/dx, y′: the slope of y for x, the whole chain
dy/du, f′(g(x)): the outside's slope, at the inside's current value
du/dx, g′(x): the inside's slope
Lagrange writes y = f(g(x)): g is the inside, f the outside, and the prime ′ means “the slope of”. Here g(x) = 3x + 1 and f(u) = u², so y′ = 2(3x + 1) × 3 = 24 at x = 1.
Illustrative values: input x = 2, w1 = 0.5, w2 = 1.5 (biases left out). Local slopes, as on the backpropagation slide: y(1 − y) for the sigmoid σ, −1/y for −log.
When a value feeds several later boxes, the slopes arriving along each path are added.