๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #64

Weight Updates

This closing note of the Neural Network Fundamentals module traces the weight update rule through a complete, concrete example โ€” one real forward pass, one real backward pass, one real update โ€” tying together everything from the Foundations, Math, and this category into a single worked run.

The Full Cycle, Restated Precisely

\[ \hat{y} = f(\mathbf{x}; \mathbf{W}) \quad\rightarrow\quad L = \text{loss}(y, \hat{y}) \quad\rightarrow\quad \nabla_{\mathbf{W}} L \quad\rightarrow\quad \mathbf{W} \leftarrow \mathbf{W} - \eta\nabla_{\mathbf{W}}L \]

Every training step in every network in this hub โ€” from a single Perceptron to a billion-parameter Transformer โ€” executes this exact four-stage cycle. What changes across architectures is only the specific form of \(f\) (the forward computation) and how efficiently \(\nabla_{\mathbf{W}}L\) is computed (backpropagation, applied through whatever operations \(f\) uses).

Complete Worked Example โ€” One Full Update

A single neuron: \(w=0.5, b=0\), input \(x=2\), true label \(y=1\), sigmoid activation, using squared error loss for simplicity, learning rate \(\eta=0.1\).

Forward pass:

\[ z = wx+b = (0.5)(2)+0 = 1.0, \qquad \hat y = \sigma(1.0) = \frac{1}{1+e^{-1}} \approx 0.731 \]

Loss:

\[ L = (y-\hat y)^2 = (1-0.731)^2 \approx 0.0724 \]

Backward pass (applying the chain rule from Chain Rule):

\[ \frac{\partial L}{\partial \hat y} = -2(y-\hat y) = -2(0.269) \approx -0.538 \] \[ \frac{\partial \hat y}{\partial z} = \hat y(1-\hat y) = (0.731)(0.269) \approx 0.197 \quad \text{(sigmoid's own derivative)} \] \[ \frac{\partial z}{\partial w} = x = 2 \] \[ \frac{\partial L}{\partial w} = \frac{\partial L}{\partial \hat y}\cdot\frac{\partial \hat y}{\partial z}\cdot\frac{\partial z}{\partial w} = (-0.538)(0.197)(2) \approx -0.212 \]

Weight update:

\[ w_{\text{new}} = w - \eta\frac{\partial L}{\partial w} = 0.5 - (0.1)(-0.212) = 0.5 + 0.0212 = 0.5212 \]

The weight increased slightly โ€” makes sense: the true label was 1 but the prediction (0.731) was too low, so increasing the weight (which increases \(z\), which increases \(\hat y\) toward 1) is exactly the right direction.

Code โ€” Verifying This Exact Example with Autograd

import torch

w = torch.tensor(0.5, requires_grad=True)
b = torch.tensor(0.0, requires_grad=True)
x = torch.tensor(2.0)
y_true = torch.tensor(1.0)

z = w * x + b
y_pred = torch.sigmoid(z)
loss = (y_true - y_pred) ** 2

loss.backward()
print("dL/dw:", w.grad.item())   # approximately -0.212, matching the manual derivation

lr = 0.1
with torch.no_grad():
    w -= lr * w.grad
print("updated w:", w.item())    # approximately 0.5212

Why One Update Isn't Enough

A single update nudges the weight only slightly closer to reducing the loss for this one example. Training repeats this cycle across every example (or batch of examples) in the dataset, across many epochs โ€” gradually, the accumulated small steps converge the weights toward values that predict well across the whole training distribution, not just one example. Everything about how to do this efficiently, robustly and at scale is the subject of the Optimization, Training Deep Networks, and Backpropagation categories that follow.

Common Mistakes

  • Expecting a single weight update to produce a dramatic accuracy jump โ€” with a small learning rate (by design, for stability), each step makes only a small, incremental improvement; real training requires many such steps.
  • Losing track of which quantities are computed during the forward pass (needed later for the backward pass) vs which are only computed during backpropagation itself.

Interview Relevance

Q: "Trace through, with real numbers, what happens during one training step of a neural network." A strong answer walks the same four stages as this note: compute a prediction via forward propagation, compute the loss by comparing to the true label, compute gradients via backpropagation (the chain rule applied layer by layer), then update every weight by subtracting the learning rate times its gradient โ€” and can name the shapes/values involved for a concrete tiny example, not just the abstract formula.

Key Takeaways โ€” Neural Network Fundamentals

  • The artificial neuron (weighted sum + activation) is a loose mathematical metaphor for a biological neuron, refined from the McCulloch-Pitts model (fixed, hand-designed) through the Perceptron (learnable, but only linearly separable problems) to the MLP (learnable, non-linear, universal).
  • A single Perceptron cannot solve XOR; stacking layers with non-linear activations between them (an MLP) resolves this completely.
  • Parameters (weights, biases) are learned by training; hyperparameters (learning rate, architecture size) are chosen by you beforehand.
  • The full training cycle โ€” forward propagation, loss, backpropagation, gradient descent weight update โ€” is the same four-stage loop underlying every network in this entire hub, however large or specialized.

Next: Activation Functions covers every non-linearity referenced loosely in this category (ReLU, sigmoid, softmax and more) in full mathematical and practical detail.

Practice Question

Using the same numbers as the worked example above but with true label \(y=0\) instead of \(y=1\), recompute \(\frac{\partial L}{\partial \hat y}\) and predict, without fully recalculating, whether the updated weight should increase or decrease from 0.5.

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Weight Updates โ€“ FAQs

Quick answers about learning Weight Updates in Deep Learning.

This free note from CodingNow 2.0 explains Weight Updates in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Weight Updates, is 100% free with no signup required.
With focused practice, most students grasp Weight Updates in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now