Discover: one line that switches neurons off
Dropout is one of the simplest tricks in deep learning, and one of the most widely used. While a network trains, you switch off a random selection of its units at every step, so that no unit can lean too heavily on any other. Here is how the 2014 journal paper on dropout writes that idea down:
Spotted in the wild
You can already read half of it. From Chamber 1: is an with two addresses, unit in layer , and the bracketed superscript is an index, not a power. The bold is the vector of layer 's outputs, and the tilde on marks a modified copy. The is this paper's symbol for multiplying two vectors entry by entry (Chamber 6 writes it ).
What's new is the language of chance: the and the word . Each is a coin toss that comes up 1 (keep the unit) or 0 (drop it), and multiplying by it zeroes out the dropped units. By the end of this chamber you'll read every symbol of this line, and of the much more intimidating objective that trains a generative adversarial network (GAN).
Take a guess before reading on. How would you read aloud?
Learn: outcomes, events and P
Every probability statement starts with an experiment whose result is uncertain: rolling a die, picking a training example, initialising a network. The set of every possible outcome is the sample space, written (capital omega). For one roll of a die, .
An event is a set of outcomes, so it's a subset , in the language of Chamber 2. “The roll is even” is the event . The probability , read “P of A”, is a number between 0 and 1 saying how likely is. For a fair die, every outcome has probability , so .
Three rules, known as Kolmogorov's axioms, are all the theory needs:
- for every event .
- : something happens.
- If and can't happen together (), then .
Everything else follows. For example, and its complement (“not ”) never happen together, and between them they cover all of . So the third rule and then the second give , which means . That's a complete proof, three lines long.
Set operations from Chamber 2 become sentences about chance. is “P of A and B”: both happen. Papers often write it with a comma, , because in probability a comma means “and”. is “P of A or B”, where “or” means at least one of them. With , “at least 4”:
The union formula is inclusion–exclusion again: without the subtraction, the outcomes 4 and 6 would be counted twice.
- “capital omega, the sample space”The sample space: the set of every possible outcome of the experiment.
- “A, an event”An event is a set of outcomes, so a subset of . “The roll is even” is the event .
- “P of A”The probability of event : a number from 0 (impossible) to 1 (certain).
- “P of A complement”The probability that does not happen. It always equals .
- “P of A and B”The probability that both happen. Often written with a comma instead: .
- “P of A or B”The probability that at least one happens. Inclusion–exclusion from Chamber 2 gives the formula.
- “P of A given B”Conditional probability: how likely is once you know happened. The bar is read “given”.
| Symbol | Say it | Meaning | LaTeX |
|---|---|---|---|
| “capital omega, the sample space” | The sample space: the set of every possible outcome of the experiment. | ||
| “A, an event” | An event is a set of outcomes, so a subset of . “The roll is even” is the event . | ||
| “P of A” | The probability of event : a number from 0 (impossible) to 1 (certain). | ||
| “P of A complement” | The probability that does not happen. It always equals . | ||
| “P of A and B” | The probability that both happen. Often written with a comma instead: . | ||
| “P of A or B” | The probability that at least one happens. Inclusion–exclusion from Chamber 2 gives the formula. | ||
| “P of A given B” | Conditional probability: how likely is once you know happened. The bar is read “given”. |
Learn: the vertical bar means “given”
Information changes probabilities. Suppose a friend peeks at the die and tells you only “it's at least 4”. The chance that it's even is no longer : the world has shrunk to , and two of those three outcomes are even. That's conditional probability:
Read it “P of A given B”. The recipe is to keep only the part of that lies inside , then divide by so that the new, smaller world has total probability 1. For the die, .
Multiplying both sides by gives the product rule, : the chance of both is the chance of , times the chance of once has happened.
Two events are independent when knowing one tells you nothing about the other: . By the product rule that's the same as . Independence can surprise you. On a fair die, “even” and “at most 2” are independent: , which is exactly .
Roll one fair die. What is ? A fraction like 1/2 is fine.
Learn: Bayes' rule, derived
The product rule works in both directions, and that's all you need to derive the most famous formula in probability. Here is the derivation in full.
- 1
Write the joint probability one way
Condition on : .
- 2
Write it the other way
is the same event as , so we can also condition on : .
- 3
Set the two equal and divide
Both right-hand sides equal , so they equal each other. Dividing by :
- 4
Expand the bottom
happens either together with or together with , never both, so the third axiom and the product rule give the law of total probability:
That's Bayes' rule. It turns a probability you can measure, , into the one you actually want, . In machine learning, is usually a hypothesis and is data , and each piece has a name:
A worked example shows why it matters. A condition affects 1% of people. A test detects it 90% of the time, but also comes back positive for 9% of healthy people. You test positive. How worried should you be?
About 9%, not 90%. Picture 1,000 people: 10 are ill and 9 of them test positive, but about 89 of the 990 healthy people test positive too. Only 9 of the roughly 98 positives are actually ill. The prior, 1%, matters enormously.
Learn: random variables and the little p
Most of the time we care about numbers, not events: the number rolled, a pixel's brightness, a model's loss. A random variable is a number whose value depends on chance. Convention: a capital letter for the random variable, and a lower-case for a particular value it might take. So reads “P of big X equals little x”, the probability that comes out as .
Papers abbreviate this constantly. , with a lower-case , is the distribution of at the value :
- For a discrete (finitely many values, like a die), . This is a probability mass function (pmf), and its values add up to 1.
- For a continuous (any real number, like a height), is a probability density function (pdf). A single value has probability zero, and probabilities are areas: , the continuous sum of Chamber 7. A density can be larger than 1. Only the total area must be 1.
With two random variables, is their joint distribution. Here is a small one, for tomorrow's weather and whether someone carries an umbrella :
| umbrella | no umbrella | total | |
|---|---|---|---|
| sun | 0.05 | 0.55 | 0.60 |
| rain | 0.30 | 0.10 | 0.40 |
| total | 0.35 | 0.65 | 1 |
The marginal distribution of one variable comes from adding the other one up: . The name is literal: those totals are written in the margins of the table. For continuous variables the sum becomes an integral, . Either way, people say that has been summed out, or marginalised out.
The conditional distribution works just like conditional probability: . So . And and are independent, written , when for every pair. Here they're not: , far from .
Now the most important line in this chamber for machine learning. A classifier with parameters doesn't just output a label. It outputs a whole distribution over labels, written
read “p theta of y given x”: the probability the model gives to label when it sees input . The subscript is Chamber 4's again, saying which model's probabilities these are.
- “random variable X”A capital letter is a random variable: a number whose value depends on chance, like the result of a roll.
- “P of big X equals little x”The probability that the random variable takes the particular value . Capital: the random quantity. Lower case: one value it could take.
- “p of x”The distribution of at the value . For discrete it's a pmf, . For continuous it's a density: areas under it are probabilities.
- “p of x comma y”The joint distribution: how likely and are together.
- “p of y given x”The conditional distribution of once is known: .
- “p theta of y given x”A model: the probability that a network with parameters assigns to label for input .
- “sum over y of p of x comma y”Marginalising: add up the joint over every value of and you're left with . People say has been “summed out”.
- “integral of p of x comma y, d y”The same marginalisation when is continuous: the integral is a continuous sum (Chamber 7).
- “X is independent of Y”Independence: knowing one tells you nothing about the other, so the joint factorises: .
| Symbol | Say it | Meaning | LaTeX |
|---|---|---|---|
| “random variable X” | A capital letter is a random variable: a number whose value depends on chance, like the result of a roll. | ||
| “P of big X equals little x” | The probability that the random variable takes the particular value . Capital: the random quantity. Lower case: one value it could take. | ||
| “p of x” | The distribution of at the value . For discrete it's a pmf, . For continuous it's a density: areas under it are probabilities. | ||
| “p of x comma y” | The joint distribution: how likely and are together. | ||
| “p of y given x” | The conditional distribution of once is known: . | ||
| “p theta of y given x” | A model: the probability that a network with parameters assigns to label for input . | ||
| “sum over y of p of x comma y” | Marginalising: add up the joint over every value of and you're left with . People say has been “summed out”. | ||
| “integral of p of x comma y, d y” | The same marginalisation when is continuous: the integral is a continuous sum (Chamber 7). | ||
| “X is independent of Y” | Independence: knowing one tells you nothing about the other, so the joint factorises: . |
Use the weather table above: , , , . You see someone carrying an umbrella. What is ? Give 3 decimal places or a fraction.
Learn: drawing samples
To say that is a sample from a distribution , papers write , read “x is drawn from p” or “x is distributed as p”. It's a different symbol from Chamber 1's , and a different job from the tilde decoration on .
A handful of distributions have their own names:
- Bernoulli, : a biased coin. The value is 1 with probability and 0 with probability . Dropout's masks are Bernoulli.
- Normal (or Gaussian), : the bell curve centred at the mean with spread . is the standard normal.
- Uniform, : every value between and equally likely.
The normal distribution's density is worth reading once, symbol by symbol. It's Chamber 4's applied to a squared distance from , scaled by , with a constant in front that makes the total area 1:
When a whole dataset is drawn, papers add “i.i.d.”: means independent and identically distributed. Every sample comes from the same , and none influences another. It's the standing assumption behind the dataset of Chamber 2.
You'll meet everywhere: random initial weights such as , noise added to data, a minibatch sampled from the training set, and dropout's coins. In Chamber 9 you'll see a variational autoencoder draw and set , which gives .
- “is drawn from”Between a variable and a distribution, says the variable is a sample from it (“is distributed as”). Not to be confused with .
- “independent and identically distributed as”Every sample comes from the same distribution, and none depends on any other. The standing assumption about datasets.
- “Bernoulli p”A biased coin: the value 1 with probability and 0 otherwise. Dropout's masks are Bernoulli.
- “normal with mean mu and variance sigma squared”The bell curve centred at . The second slot is the variance , not the standard deviation.
- “uniform from a to b”Every value between and equally likely. A common way to initialise weights.
| Symbol | Say it | Meaning | LaTeX |
|---|---|---|---|
| “is drawn from” | Between a variable and a distribution, says the variable is a sample from it (“is distributed as”). Not to be confused with . | ||
| “independent and identically distributed as” | Every sample comes from the same distribution, and none depends on any other. The standing assumption about datasets. | ||
| “Bernoulli p” | A biased coin: the value 1 with probability and 0 otherwise. Dropout's masks are Bernoulli. | ||
| “normal with mean mu and variance sigma squared” | The bell curve centred at . The second slot is the variance , not the standard deviation. | ||
| “uniform from a to b” | Every value between and equally likely. A common way to initialise weights. |
Learn: expectation, the long-run average
The expectation (or expected value) of is its average, with each value weighted by its probability:
Read as “the expectation of X”; the is blackboard bold (Chamber 1). For a fair die, : a value the die never actually shows, but the balance point of its distribution.
Often we want the average of some function of a random variable. The subscript says what's random and where it comes from:
read “the expectation of f of x, with x drawn from p”. You'll meet this shape in the GAN objective at the end of this chamber. And here's the idea that makes it usable: if , then
and the approximation gets better as grows. That's the law of large numbers. It's why a training loss, , is a sensible stand-in for the expected loss on data you haven't seen, and why a minibatch gradient is a sensible stand-in for the full gradient.
A proof: expectation is linear
Here is a complete proof of the property you'll use most, for a discrete random variable.
Claim. For any constants and , .
Proof. The random variable takes the value whenever , so by the definition of expectation applied to ,
The middle step splits one sum into two and pulls the constants out (Chamber 5's linearity of sums). The last step uses the definition of for the first sum, and the fact that probabilities add up to 1 for the second.
The same argument shows for any two random variables, independent or not.
Two more summaries measure spread. The variance is the expected squared distance from the mean, and its square root is the standard deviation :
For the die, and . The covariance asks whether two variables move together. Positive means they tend to be high together, negative means one is high when the other is low. Independent variables have covariance zero.
- “the expectation of X”The expected value: the average of , weighting each value by its probability. The long-run mean of many samples.
- “expectation of f of x, x drawn from p”The average of when is drawn from . The subscript names the random variable and its distribution.
- “the variance of X”How spread out is: the expected squared distance from its mean. Its square root is the standard deviation .
- “the covariance of X and Y”Whether two random variables move together (positive), oppositely (negative), or neither (zero).
| Symbol | Say it | Meaning | LaTeX |
|---|---|---|---|
| “the expectation of X” | The expected value: the average of , weighting each value by its probability. The long-run mean of many samples. | ||
| “expectation of f of x, x drawn from p” | The average of when is drawn from . The subscript names the random variable and its distribution. | ||
| “the variance of X” | How spread out is: the expected squared distance from its mean. Its square root is the standard deviation . | ||
| “the covariance of X and Y” | Whether two random variables move together (positive), oppositely (negative), or neither (zero). |
Flip two fair coins and let be the number of heads, so is 0, 1 or 2 with probabilities 0.25, 0.5 and 0.25. What is ?
Now watch the law of large numbers happen. Each sample is unpredictable, but their running average (Chamber 1's bar) is not.
Interactive lab
Sampling and the law of large numbers
Draw samples. The challenge: reach n ≥ 500 with the running mean within 0.05 of 𝔼[X].
Each face 1 to 6 with probability 1/6.
Draw samples
samples
0
mean
…
𝔼[X]
3.5
distance
…
Things to try:
- With the fair die, draw one sample at a time for a while. The running mean jumps around. Then add a thousand and watch it flatten onto the dashed line at 3.5.
- Compare Bernoulli with against the die. Which settles within 0.05 of its expectation faster? The typical distance after samples is about , so the smaller wins.
- Pick the normal distribution and set . Check that the histogram's width matches the second argument of as the lab writes it: , not 2.
Learn: likelihood and KL divergence
Two more pieces of notation turn probability into training objectives.
Given a dataset of i.i.d. examples, independence lets the probability of the whole dataset factorise into a product. Read as a function of , it's the likelihood:
Multiplying thousands of numbers below 1 underflows to 0 on a computer, so papers take the log, which turns the product into a sum (Chamber 5):
Maximum likelihood picks , the argmax of Chamber 7 wearing the hat of Chamber 1. Flip the sign and average, and you have the most common loss in deep learning, the cross-entropy or negative log-likelihood: .
Finally, papers often need to say how different two distributions are. The Kullback–Leibler (KL) divergence is
read “the KL divergence of p from q”. You don't need to compute with it yet, only to read it. Three facts are enough: it's never negative, it's zero exactly when , and it is not symmetric. For a fair coin and a biased one , but . The double bar is only a separator between the two arguments. It has nothing to do with the norm of Chamber 6.
- “the likelihood, p of D given theta”The likelihood: how probable the whole dataset is under parameters . For i.i.d. data it's a product.
- “the log-likelihood”The log turns the product into a sum (Chamber 5). Maximising it is maximum likelihood; minimising its negative is the usual cross-entropy loss.
- “the K L divergence of p from q”The Kullback–Leibler divergence: how different is from . Never negative, zero only when , and not symmetric. The is a separator, not a norm.
| Symbol | Say it | Meaning | LaTeX |
|---|---|---|---|
| “the likelihood, p of D given theta” | The likelihood: how probable the whole dataset is under parameters . For i.i.d. data it's a product. | ||
| “the log-likelihood” | The log turns the product into a sum (Chamber 5). Maximising it is maximum likelihood; minimising its negative is the usual cross-entropy loss. | ||
| “the K L divergence of p from q” | The Kullback–Leibler divergence: how different is from . Never negative, zero only when , and not symmetric. The is a separator, not a norm. |
Read beyond the course
Probability rewards seeing it from several angles: pictures, careful definitions, and the way machine-learning books use it. These are all free.
Interactive · free online · ~30 min
Seeing TheoryDaniel Kunin (Brown University) · Chapters 1–3: Basic Probability, Compound Probability, Probability Distributions
A beautiful visual introduction where you flip coins, roll dice and watch expectations and distributions take shape. Its first chapters cover this chamber's ideas with animations, including the law of large numbers you just watched.
Lecture notes · free online · ~40 min
Review of Probability TheoryArian Maleki & Tom Do (Stanford CS229) · Sections 1–3
The probability primer handed to Stanford's machine-learning students. Twelve compact pages with Ω, events, pmfs, pdfs, expectation, Bayes' rule and independence in exactly the notation of this chamber. A good test of how much you can now read.
Book · free online · ~60 min
Deep Learning, Chapter 3: Probability and Information TheoryIan Goodfellow, Yoshua Bengio & Aaron Courville · Sections 3.1–3.9, then 3.11 (Bayes' rule) and 3.13 (information theory, for KL)
The probability every deep-learning paper assumes, in the notation those papers copy. Section 3.13 introduces the KL divergence properly, if you want more than the reading-level treatment here.
Book · free online · ~60 min
Mathematics for Machine Learning, Chapter 6: Probability and DistributionsMarc Peter Deisenroth, A. Aldo Faisal & Cheng Soon Ong · Sections 6.1–6.5
A slower, more mathematical treatment with worked examples: sum and product rules, Bayes' theorem, summary statistics, and the Gaussian in depth. Read Section 6.3 alongside this chamber's derivation of Bayes' rule.
Papers and lectures
You met the dropout paper at the top of this chamber. It's long, but the part you need is short. Open it at Section 4, Model Description: one page, with Figure 3 drawing a standard layer next to a dropout layer. Read the equations aloud with this chamber's tables, then read the paragraph beneath them. If you want more, Section 10 compares Bernoulli masks with Gaussian ones and states their mean and variance, which is exactly what you'll prove below.
The GAN paper is a harder read, but its heart is also one page. Read Section 3, Adversarial nets, which ends in Equation 1. Then look at Proposition 1 at the start of Section 4.1, which states the best possible discriminator in one fraction. Skip the convergence proof and the experiments for now.
Dropout: A Simple Way to Prevent Neural Networks from OverfittingNitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, Ruslan Salakhutdinov · Journal of Machine Learning Research 15, 2014The full account of dropout: what it does, why it works as a cheap way of averaging many thinned networks, and how to tune it. Section 4 defines every symbol before it uses it, which makes it a good first paper to read closely.
Generative Adversarial NetsIan J. Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, Yoshua Bengio · NIPS, 2014The paper that pitted a generator against a discriminator and started a decade of image synthesis. Its objective is written almost entirely in this chamber's notation.
Decode the paper · Section 4 (Model Description), the first two lines of the dropout equations
Dropout: A Simple Way to Prevent Neural Networks from OverfittingNitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, Ruslan Salakhutdinov · JMLR 15, 2014
During training, dropout switches off a random subset of units at every step, so the network can't rely on any single unit. These two lines are how the paper says it.
Options
Decode the paper · Eq. (1), Section 3
Generative Adversarial NetsIan J. Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, Yoshua Bengio · NIPS, 2014
Two networks play a game. The generator turns random noise into fake examples; the discriminator tries to tell real from fake. This one line is the whole game. Match each piece to its meaning.
Options
Watch
Grant Sanderson derives Bayes' rule from a picture of all the possibilities, drawn as areas. Watch for the idea that evidence restricts the space of possibilities, and that the answer is a proportion of what's left: the same recipe as the definition of above.
Your turn
Translate between symbols, words and code. Then prove two facts about expectations and dropout masks, and finish with three problems, the last taken straight from the GAN paper.
Match · Symbols ↔ Read aloud as
Say it aloud
Match each piece of probability notation to the way a researcher would read it.
Options
Match · Maths ↔ NumPy
From symbols to NumPy
Match each formula to the NumPy that computes or samples it. Assume rng = np.random.default_rng(), that xs is an array of samples, and that a and b are boolean arrays marking which samples fall in events and . One trap: rng.normal takes the standard deviation , not the variance.
Options
Proofs
The puzzle proves a shortcut for variance. You'll need that shortcut in the proof you write yourself, which explains why dropout's rescaled masks leave every unit's output unchanged on average.
Proof puzzle
The variance shortcut
Claim
For any random variable with a finite mean,
Tap lines in the order they should appear. Not every line belongs. Tap a line in your proof to send it back.
Your proof
- Pick the first line below.
Available lines
Prove it yourself
The mean and variance of a dropout mask
Claim
Let with . Prove that and . Then deduce that the rescaled mask , used by “inverted dropout”, has and .
Your typeset proof appears here.
Code it up
Problem 22·Warm-up
The expected maximum
Roll two fair six-sided dice. Let and be the two results, with : each value from 1 to 6 has probability , independently.
What is ? Give your answer as a fraction in lowest terms.
Problem 23·Standard
Which coin is it?
A bag holds three coins: a fair coin, a biased coin that lands heads with probability , and a two-headed coin. You draw one at random, so each hypothesis has prior . You flip it times and every flip is heads. Call that evidence .
Flips are independent given the coin, so , where is that coin's probability of heads. Bayes' rule gives the posterior
What is the smallest for which ?
Problem 24·Challenge
The value of the game
Apply the paper. Goodfellow et al.'s GAN value function (Eq. 1) is
written here, as the paper does in its proofs, with the generator's samples drawn straight from its distribution . Their Proposition 1 shows that for a fixed generator the best discriminator is
Take a tiny world with . The real data are a fair die, , and the generator is loaded towards high numbers, . Using natural logarithms, compute and give it to 4 decimal places.
Key takeaways
- Events are sets and measures them. means “A and B”, and the bar in means “given”, never “divided by”. Order matters: .
- Bayes' rule comes from writing two ways: posterior equals likelihood times prior, over evidence.
- Capital is a random variable and lower-case a value. is its distribution, a joint, a conditional, and a model. Sum or integrate a variable out to get a marginal.
- means “x is drawn from p”. takes a variance, is a biased coin, and i.i.d. means independent draws from one distribution.
- is a probability-weighted average, estimated by averaging samples. It's linear, and variance is .
- Likelihoods multiply, log-likelihoods add, and measures how far is from , in one direction only.
Checkpoint
Prove it to the labyrinth
Answer every question to clear this chamber. First-try answers earn the most XP.
A paper trains a classifier by maximising . What is ?
Weights are initialised as . What is the standard deviation of each weight?
A continuous random variable has density at . What can you conclude?
Let . What is ?
20% of emails are spam. The word “winner” appears in 50% of spam and in 5% of other emails. An email contains “winner”. What is ? Give 3 decimal places or a fraction.
A paper assumes its data satisfy . What does that assume?
Why do papers maximise the log-likelihood instead of the likelihood ?
Which statement about is true?
End of the chamber
Clear this chamber
- Questions in this chamber (0/12 solved)Next unsolved
- Bonus: Law of large numbers (+30 XP)
- Bonus: Problem 22: The expected maximum (+20 XP)
- Bonus: Problem 23: Which coin is it? (+35 XP)
- Bonus: Problem 24: The value of the game (+50 XP)
- Bonus: Proof: The variance shortcut (+25 XP)
- Bonus: Proof: The mean and variance of a dropout mask (+40 XP)
- Bonus: Decode the paper (1) (+30 XP)
- Bonus: Decode the paper (2) (+30 XP)
- Bonus: Match: Say it aloud (+25 XP)
- Bonus: Match: From symbols to NumPy (+25 XP)