Neural Networks
Layers of simple units, each a weighted sum passed through a nonlinear function, composed into a function that can fit almost anything.
Needs a step first: 33
A layer computes : a matrix multiplication, a shift, then a nonlinearity such as ReLU, , applied to each entry; stacking layers lets the network build features out of features. Without the nonlinearity the layers would collapse into one matrix, so a deep linear network can do no more than linear regression. With it, even one hidden layer can approximate any reasonable function given enough units. The weights are learned by backpropagation and gradient descent, and the same building blocks make up convolutional networks and transformers.
Where it shows up: Backpropagation trains them, and convolutional networks, embeddings and transformers are neural networks with particular structure.
How to hold it: In your head
See a layer as multiply by a matrix, shift, then bend with a nonlinearity, and why without the bend any stack of layers collapses into one matrix.
What knowing it looks like
- Compute the output of a small two-layer ReLU network by hand, layer by layer.
- Show that two linear layers without an activation equal one linear layer.
- Count the parameters of a fully connected network from its layer sizes.
Test yourself
A network has hidden units and and output . Compute for the inputs , , , . What function is it, and why can no single linear unit followed by a threshold compute it?
Show the worked answer
Needs a step first: 33
Learn it with an AI
Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.
Be my maths tutor. I'm learning "Neural Networks" (Frontier tier): Layers of simple units, each a weighted sum passed through a nonlinear function, composed into a function that can fit almost anything.
I already know: Logistic Regression and Classification, Matrices as Transformations.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: A network has hidden units $h_1 = \mathrm{ReLU}(x_1 + x_2)$ and $h_2 = \mathrm{ReLU}(x_1 + x_2 - 1)$ and output $y = h_1 - 2h_2$. Compute $y$ for the inputs $(0, 0)$, $(0, 1)$, $(1, 0)$, $(1, 1)$. What function is it, and why can no single linear unit $y = w_1x_1 + w_2x_2 + b$ followed by a threshold compute it?
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.Needs first
- Logistic Regression and ClassificationA linear score passed through the sigmoid to give a probability, trained by minimising cross-entropy.Undergraduate II · Machine Learning
- Matrices as TransformationsA matrix is a rule that moves every vector in a straight-line-preserving way; its columns say where the basis vectors land.Core · Linear Algebra
Leads to
- BackpropagationComputing the gradient of the loss with respect to every weight by applying the chain rule backwards through the network, layer by layer.Frontier · Machine Learning
- Embeddings and SimilarityRepresenting words, images or items as vectors learned so that similar things point in similar directions, compared by cosine similarity.Frontier · Machine Learning
- Softmax and Language ModelsSoftmax turns a list of scores into probabilities; a language model uses it to predict the next token, trained by cross-entropy.Frontier · Machine Learning
On the way to
Recommended
- Neural Networks: Zero to HeroAndrej Karpathy · VideosFree lectures that build backpropagation, a language model and a small GPT from scratch in Python, explaining every line.
- Understanding Deep LearningSimon J. D. Prince (MIT Press) · BookA clear, well-illustrated 2023 textbook covering networks, training, transformers, diffusion models and reinforcement learning, free as a PDF with Python notebooks.
- 动手学深度学习阿斯顿·张、李沐等 · Book · 中文The Chinese edition of Dive into Deep Learning: a free textbook in which every model, from linear regression to transformers, runs as code beside the maths.
- 跟李沐学AI李沐 · Videos · 中文Mu Li's own Bilibili channel: the video course for Dive into Deep Learning and paragraph-by-paragraph readings of key papers, including the Transformer paper.