Build a Neural Network from Scratch in NumPy | LLM Course #12
What is a neural network, really? In Lecture 12 of the LLM Masterclass we build one from scratch: a single neuron (weights, bias, a dot product), the ReLU activation function (and GELU, used in GPT models), layers as one matrix multiplication, a signal flowing through a tiny 3-4-2 network, and ChotuGPT's first layer: a Linear class and relu in NumPy. 💻 Code for this lecture (branch lecture-12): https://github.com/programmingline/chotugpt/tree/lecture-12 Lecture 12 of 32 — LLM Masterclass · Module 2: Just enough maths ⚠️ ChotuGPT is a simplified teaching model. The network's weights are random toy numbers, for teaching only. In this lecture: • A neuron: inputs × weights, added up, plus a bias (the chai vector: 0.9×0.5 + 0.8×0.4 + 0.1×(−0.6) + 0.1 = 0.81) • Why we need an activation function: without it, stacked layers collapse into one linear map • ReLU (Rectified Linear Unit): positive numbers stay, negative numbers become zero • GELU, the smoother cousin used in GPT models • A layer = many neurons = one matrix multiplication plus a bias vector (x @ W + b) • Hidden layers, and a signal flowing through a 3 → 4 → 2 network • chotugpt/nn.py: a Linear class and relu in NumPy • Feed-forward networks inside every Transformer block Chapters: 00:00 Lecture 11 quiz answer 00:15 A neural network from scratch 00:27 One neuron: weights and bias 01:06 Building it together 01:11 Activation functions: ReLU and GELU 01:45 Layers are matrix multiplications 02:12 A signal flows through the network 02:37 Linear and ReLU in NumPy 03:09 Quiz 03:29 Inside every Transformer 03:51 Recap & next lecture ✅ Lecture 11 quiz answer: B, dot products. Every number in the result is one row dotted with one column. ❓ Quiz: What does ReLU do to a negative number? A) Turns it into zero B) Doubles it C) Flips its sign. Comment your answer. I reveal it in Lecture 13! 👍 Like, subscribe and comment your quiz answer. ⏮ Previous: Lecture 11 — Vectors, matrices and dot products ⏭ Next: Lecture 13 — How networks learn: gradient descent and backprop Sources: V. Nair and G. Hinton, "Rectified Linear Units Improve Restricted Boltzmann Machines", ICML 2010. D. Hendrycks and K. Gimpel, "Gaussian Error Linear Units (GELUs)", 2016. A. Radford et al., "Improving Language Understanding by Generative Pre-Training", OpenAI 2018 (uses GELU). T. Brown et al., "Language Models are Few-Shot Learners", NeurIPS 2020 (GPT-3, 175B parameters). NumPy documentation: numpy.maximum, the @ operator (numpy.matmul). #NeuralNetwork #ReLU #NumPy…more
What is a neural network, really? In Lecture 12 of the LLM Masterclass we build one from scratch: a single neuron (weights, bias, a dot product), the ReLU activation function (and GELU, used in GPT models), layers as one matrix multiplication, a signal flowing through a tiny 3-4-2 network, and ChotuGPT's first layer: a Linear class and relu in NumPy. 💻 Code for this lecture (branch lecture-12): https://github.com/programmingline/chotugpt/tree/lecture-12 Lecture 12 of 32 — LLM Masterclass · Module 2: Just enough maths ⚠️ ChotuGPT is a simplified teaching model. The network's weights are random toy numbers, for teaching only. In this lecture: • A neuron: inputs × weights, added up, plus a bias (the chai vector: 0.9×0.5 + 0.8×0.4 + 0.1×(−0.6) + 0.1 = 0.81) • Why we need an activation function: without it, stacked layers collapse into one linear map • ReLU (Rectified Linear Unit): positive numbers stay, negative numbers become zero • GELU, the smoother cousin used in GPT models • A layer = many neurons = one matrix multiplication plus a bias vector (x @ W + b) • Hidden layers, and a signal flowing through a 3 → 4 → 2 network • chotugpt/nn.py: a Linear class and relu in NumPy • Feed-forward networks inside every Transformer block Chapters: 00:00 Lecture 11 quiz answer 00:15 A neural network from scratch 00:27 One neuron: weights and bias 01:06 Building it together 01:11 Activation functions: ReLU and GELU 01:45 Layers are matrix multiplications 02:12 A signal flows through the network 02:37 Linear and ReLU in NumPy 03:09 Quiz 03:29 Inside every Transformer 03:51 Recap & next lecture ✅ Lecture 11 quiz answer: B, dot products. Every number in the result is one row dotted with one column. ❓ Quiz: What does ReLU do to a negative number? A) Turns it into zero B) Doubles it C) Flips its sign. Comment your answer. I reveal it in Lecture 13! 👍 Like, subscribe and comment your quiz answer. ⏮ Previous: Lecture 11 — Vectors, matrices and dot products ⏭ Next: Lecture 13 — How networks learn: gradient descent and backprop Sources: V. Nair and G. Hinton, "Rectified Linear Units Improve Restricted Boltzmann Machines", ICML 2010. D. Hendrycks and K. Gimpel, "Gaussian Error Linear Units (GELUs)", 2016. A. Radford et al., "Improving Language Understanding by Generative Pre-Training", OpenAI 2018 (uses GELU). T. Brown et al., "Language Models are Few-Shot Learners", NeurIPS 2020 (GPT-3, 175B parameters). NumPy documentation: numpy.maximum, the @ operator (numpy.matmul). #NeuralNetwork #ReLU #NumPy