TECHNOLOGIESTieInn Technologies

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:

  1. Forward pass: inputs → layers → prediction.
  2. Loss: how wrong the prediction is (cross-entropy for classes, mean squared error for numbers).
  3. Backward pass: work out how each weight affected the loss (gradients).
  4. Update: weight = weight − learning rate × gradient.
  5. 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 →

Questions

Open in Code Lab5 free questions
5 questions

    Neural networks in plain words: layers, weights and the training loop

  1. 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)
  2. Neural networks in plain words: layers, weights and the training loop

  3. Question 2medium

    A visit really bought. Which prediction gives the largest log loss?

  4. Neural networks in plain words: layers, weights and the training loop

  5. Question 3hard

    Do ONE gradient descent step for a sigmoid neuron starting from w and b: p = sigmoid(X @ w + b), w = w - lr * X.T @ (p - y) / n, b = b - lr * mean(p - y). Store the new w (rounded to 4 decimals, as a list) in result.

    Store your answer in result.

  6. Neural networks in plain words: layers, weights and the training loop

  7. Question 4medium

    What are the steps of one round of the training loop?

  8. Neural networks in plain words: layers, weights and the training loop

  9. Question 5medium

    During training the loss jumps around and grows. What's the first thing to try?

5 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.