AI & ML Quick Path Progress

All cheat sheets

Part 4 cheat sheet: deep learning

Neural networks and the families built from them.

One neuron

  • Multiply each input by its weight, add them and a bias, then bend the result with an activation function.
  • ReLU keeps positive numbers and turns negative ones into 0.
  • A network is thousands of these stacked in layers.
output = ReLU(weight1 x input1 + weight2 x input2 + bias)
A neuron drawn as a circle. Two input circles hold 2 and 3. Arrows carry them in, multiplied by the weights 0.5 and minus 1, giving 1 and minus 3. A bias of plus 1 comes in from above. The neuron adds them to get minus 1. That goes through a ReLU box, which turns negative numbers into 0, and the output circle shows 0, so the neuron stays silent. 2 3 inputs × weight 0.5 = 1 × weight −1 = −3 bias +1 add up −1 1 + (−3) + 1 = −1 ReLU negative → 0 0 output: stays silent The invented numbers from the lesson. Training is what finds real weights and biases.
Inputs times weights, plus a bias, then ReLU. With these invented numbers the sum is -1, so the neuron outputs 0.

Training a network

  • Forward pass: compute and remember each step.
  • Backward pass: hand out blame with the chain rule to get a gradient for every weight.
  • The optimiser nudges the weights; a batch is a group of examples; an epoch is one pass over the data.
A row of four boxes, input, step 1, step 2 and loss, with arrows running forward. Below it, arrows run backward from the loss, and text explains that blame is handed back using the chain rule so each weight gets a gradient. Input Step 1 Step 2 Loss Forward pass: compute each step and remember it Backward pass: hand out blame from the loss, step by step Start with one unit of blame at the loss and multiply by each step's slope going back (the chain rule). Each weight ends up with a gradient: how much it contributed to the error. The gradients tell the optimiser which way to nudge each weight, and by how much. The forward pass records; the backward pass uses the record to hand out blame.
The forward pass computes and remembers; the backward pass uses the record to hand out blame as a gradient for every weight.

Training well

  • Dropout switches random neurons off while training so none is relied on too much.
  • Stop early when validation loss stops improving.
  • Normalise, use a sensible learning-rate schedule, clip huge gradients.
Two small networks side by side. In the first, labelled during training, some neurons are crossed out and their connections are faint. In the second, labelled in use, all neurons are on. During training some neurons are switched off at random In use (and when validating) all neurons on: use eval mode so dropout is off Dropout: practice with parts missing so no neuron is relied on too much The neurons that are off change at every training step. This reduces overfitting.
Dropout switches random neurons off during training so no neuron is relied on too much. In use, all neurons are on.

Images

  • A convolution slides a small filter over the image; early filters find edges, later ones shapes.
  • Classification: what is in it. Detection: what and where. Segmentation: which pixels.
  • Transfer learning: start from a pretrained model.
A grid of 5 by 5 pixels with a 3 by 3 window outlined at the top left and a second window, dashed, one pixel to the right. A 3 by 3 filter is shown in the middle. An arrow leads to a 3 by 3 output grid whose first two cells are highlighted to match the two window positions. Text says there are 5 minus 3 plus 1 equals 3 positions across and 3 down, so 9 output numbers. Image: 5 × 5 pixels Solid: first position. Dashed: one pixel to the right. Filter: 3 × 3 slides across, one pixel at a time Output: 3 × 3 5 − 3 + 1 = 3 positions across and 3 down: 3 × 3 = 9 numbers Each output number says how strongly its patch of the image matches the filter. Early filters find edges.
A small filter slides over the image one pixel at a time. Each output number says how well that patch matches the filter.

Text and sequences

  • Tokens become ids, then embeddings: lists of numbers where similar meanings sit close together.
  • An RNN reads one step at a time and carries a memory forward; early words fade.
A map with words as dots. Three groups are circled. Software developer, programmer and engineer sit close together; nurse, doctor and paramedic sit together in another place; baker, chef and bakery sit together in a third. Words with similar meanings are close, words with different meanings are far apart. software developer programmer engineer jobs in tech nurse doctor paramedic health jobs baker chef bakery food Close together = similar meaning. Distance is how a model finds "programmer" when you search "software developer".
An embedding gives each word a list of numbers, which acts like a position on a map. Similar meanings land close together, which is how search can find programmer when you ask for software developer.

Transformers

  • Every word makes a query, a key and a value; attention mixes values by weights that add up to 1.
  • A causal mask hides later words in decoders.
  • A block is attention, then a small network, each with shortcuts and normalisation.
  • Encoder-decoder models add cross-attention.
new value = weight1 x value1 + weight2 x value2   (weights add up to 1)
A seven by seven grid for the sentence The cat sat because it was tired. Each row is a word, each column is a word it can look at. Cells hold made-up attention weights, darker for larger, and each row adds up to 1. Cells above the diagonal are greyed out because the causal mask hides later words. In the row for it, 0.75 goes to cat and 0.25 to sat. word being looked at The cat sat bec. it was tired The 1 cat 0.3 0.7 sat 0.1 0.6 0.3 because 0.05 0.2 0.65 0.1 it 0 0.75 0.25 0 0 was 0.05 0.1 0.05 0.1 0.6 0.1 tired 0 0.1 0.05 0.05 0.3 0.1 0.4 Each row is one word working out its new meaning. The numbers in the row are its attention weights and add up to 1. Darker = more attention. Hidden by the causal mask: a word cannot look at later words. Look at the row for "it": most of its attention goes to "cat" (0.75). Made-up weights (the row for "it" is the one used in the lesson's maths box).
Each row shows how one word spreads its attention over the words before it. Later words are hidden by the causal mask.

Generative models

  • Autoencoder: squeeze and rebuild.
  • GAN: a forger against a detective.
  • Diffusion: add noise step by step, learn to undo each step, then generate from noise.
A generator, called the forger, makes a fake picture from random numbers. A discriminator, called the detective, receives the fake and a real picture from the training data and says real or fake. A dashed arrow carries feedback back to the forger. Both improve: better fakes, sharper detective, repeated until the fakes look real. Generator the forger starts from random numbers and makes a fake picture Discriminator the detective looks at each picture and says "real" or "fake" fake real (from the training data) pictures feedback: where the fake gave itself away Both improve: the forger makes better fakes, the detective gets sharper. They repeat until the fakes look real. The forger and the detective are two neural networks trained against each other.
Two networks trained against each other: the forger learns to make fakes the detective cannot spot, and the detective learns to catch them.

Graphs, speech, reinforcement

  • Graph networks pass messages between neighbours.
  • Speech models read spectrograms: sound over time.
  • Reinforcement learning: act, get a reward and a new state, repeat for the most total reward.
Two boxes. The agent on the left sees a state and picks an action. The environment on the right reacts to the action. Three arrows join them: the action goes from agent to environment, and the new state and a reward come back. An example below: a game character in a maze gets plus 1 for a coin and minus 1 for a trap. Agent sees a state, then picks an action (learned, or sometimes random) Environment reacts to the action: gives a reward and moves to a new state action new state reward (good or bad) Example (made up): a game character in a maze State: where it stands. Action: step left, right, up or down. Reward: +1 for a coin, −1 for a trap. Goal: the most total reward over time. Repeat the loop many times; the agent learns which actions pay off.
The agent acts, the environment answers with a new state and a reward, and the loop repeats to collect the most reward over time.