Neural networks in plain words: layers, weights and the training loop
ML Foundations · 10 questions
Short notes
Key idea
A neural network is layers of simple units. Each multiplies its inputs by weights, adds a bias and applies an activation function. Training repeatedly nudges the weights to reduce a loss, using gradients from backpropagation.
Syntax
The training loop:
- Forward pass: inputs → layers → prediction.
- Loss: how wrong the prediction is (cross-entropy for classes, mean squared error for numbers).
- Backward pass: work out how each weight affected the loss (gradients).
- Update: weight = weight − learning rate × gradient.
- Repeat over batches for several epochs.
import torch.nn as nn
model = nn.Sequential(nn.Linear(10, 32), nn.ReLU(), nn.Linear(32, 1))
Example
A network with 10 inputs, one hidden layer of 32 units and 1 output has 10×32 + 32 + 32×1 + 1 = 385 weights to learn. Each epoch, the loss on training data should fall; if validation loss starts rising, it's overfitting.
Traps
- Learning rate too high: loss jumps around or explodes. Too low: it barely moves.
- Neural networks need lots of data; for small tabular data, tree models usually win.
- Unscaled inputs slow or break training.
- Watch validation loss, not just training loss.
Want the full lesson with step-by-step examples, a project and a certificate? ML Foundations course, ₹180 →
- Question 1easy
What is the neuron's weighted sum plus bias (before the sigmoid)?
import numpy as np x = np.array([2.0, 1.0]) w = np.array([1.5, -0.5]) b = -1.0 print(x @ w + b)
- Question 2medium
A visit really bought. Which prediction gives the largest log loss?
- Question 3hard
Do ONE gradient descent step for a sigmoid neuron starting from
wandb: p = sigmoid(X @ w + b), w = w - lr * X.T @ (p - y) / n, b = b - lr * mean(p - y). Store the neww(rounded to 4 decimals, as a list) inresult.Store your answer in
result. - Question 4medium
What are the steps of one round of the training loop?
- Question 5medium
During training the loss jumps around and grows. What's the first thing to try?
Neural networks in plain words: layers, weights and the training loop
Neural networks in plain words: layers, weights and the training loop
Neural networks in plain words: layers, weights and the training loop
Neural networks in plain words: layers, weights and the training loop
Neural networks in plain words: layers, weights and the training loop
5 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.