HT
How Things Work
System Online

Neural Networks Basics

The building block of modern AI โ€” neurons, weights and biases, activation functions, forward propagation, and how backpropagation + gradient descent let a network learn.

How It Works

A neural network is layers of simple units (neurons) that each compute a weighted sum of inputs plus a bias, then apply a non-linear activation. Data flows forward through the layers to a prediction; training uses backpropagation and gradient descent to adjust the weights so predictions improve. This same machinery โ€” scaled to billions of parameters โ€” underlies today's large language models.

1
The Neuron

A neuron takes several inputs, multiplies each by a learned weight, adds a bias, and passes the sum through an activation function. The weights encode 'how much each input matters'; the bias shifts the threshold. That's the entire computational unit โ€” everything else is wiring many of them together.

2
Layers & Forward Propagation

Neurons are organized into layers: an input layer, one or more hidden layers, and an output layer. Data flows forward โ€” each layer's outputs become the next layer's inputs โ€” until the network produces a prediction. In practice this is efficient matrix multiplication: outputs = activation(W ยท inputs + b).

3
Non-Linear Activations

Activation functions (ReLU, sigmoid, tanh) introduce non-linearity. This is essential: without it, stacking layers would collapse into a single linear transformation, no matter how deep. Non-linearity is what lets networks approximate complex functions and learn intricate patterns.

4
Learning via Backpropagation

Training compares the network's output to the correct answer using a loss function, then backpropagation computes how much each weight contributed to the error (the gradient). Gradient descent nudges every weight a little in the direction that reduces loss. Repeat over many examples and the network learns.

Key Concepts

โš–๏ธWeights & Bias

Learned parameters: weights scale each input's influence; bias shifts the activation threshold.

๐Ÿ“ˆActivation Function

A non-linearity (ReLU, sigmoid, tanh) applied to a neuron's sum โ€” what makes deep networks expressive.

โžก๏ธForward Propagation

Computing outputs layer by layer from inputs to prediction โ€” a chain of matrix multiplies + activations.

๐ŸŽฏLoss Function

Measures how wrong the prediction is (e.g. cross-entropy, MSE) โ€” the objective training minimizes.

๐Ÿ”™Backpropagation

Efficiently computes the gradient of the loss w.r.t. every weight using the chain rule.

โ›ฐ๏ธGradient Descent

Iteratively adjusts weights in the direction that reduces loss, scaled by a learning rate.

A layer's forward pass
tsx
1# One forward pass through a layer is just matrix math + a non-linearity.
2import numpy as np
3
4def relu(z): return np.maximum(0, z)
5
6# A "layer" = weights W, bias b. Inputs x โ†’ outputs a.
7def layer(x, W, b, activation):
8 z = W @ x + b # weighted sum (linear)
9 return activation(z) # non-linearity makes deep nets expressive
10
11x = np.array([0.6, 0.3]) # inputs
12W1 = np.array([[0.9, -0.6], # hidden layer weights (3ร—2)
13 [-0.4, 0.8],
14 [0.5, 0.5]])
15h = layer(x, W1, np.array([0.1, -0.2, 0.0]), relu) # hidden activations
16out = 1 / (1 + np.exp(-(W2 @ h + b2))) # sigmoid output (0..1)
17
18# TRAINING (backprop): compute loss, then gradient descent on the weights
19# W -= learning_rate * dLoss/dW ... repeated over many batches.
๐Ÿ’ก
Why This Matters

Neural networks are the foundation of deep learning and every modern AI system, from image recognition to LLMs. Understanding neurons, activations, forward propagation, and gradient-based training is the prerequisite for everything that follows โ€” transformers, embeddings, fine-tuning โ€” and is a baseline expectation for AI/ML interviews and informed AI engineering.

Common Pitfalls

โš Omitting non-linear activations โ€” stacked linear layers collapse to a single linear function.
โš Poor weight initialization or learning rate โ€” training diverges or gets stuck (vanishing/exploding gradients).
โš Overfitting: a big network memorizes training data; needs regularization, dropout, and validation.
โš Treating networks as pure magic โ€” without the weights/forward/backprop model, higher concepts feel arbitrary.
โš Ignoring data quality and scale โ€” model performance is bounded by the data far more than by clever architecture.
Real-World Use Cases

1Why 'Just Add More Layers' Isn't Enough

Scenario

A beginner builds a deep network for a non-linear classification task but accidentally uses linear (identity) activations everywhere. No matter how many layers they stack, accuracy is no better than a single linear model.

Problem

Without non-linear activations, composing linear layers yields another linear function โ€” the depth is wasted. The network literally cannot represent the curved decision boundary the data requires.

Solution

Insert non-linear activations (ReLU is the common default) between layers. Now each layer can bend the representation, and the stack can approximate complex, non-linear functions. Accuracy jumps because the network can finally model the data's structure.

๐Ÿ’ก

Takeaway: Depth alone doesn't add power โ€” non-linearity does. Activation functions are what let neural networks learn complex patterns; remove them and a deep net collapses to linear regression.

2Understanding LLMs From the Ground Up

Scenario

An engineer wants to reason about why large language models behave the way they do โ€” context limits, training cost, fine-tuning โ€” but treats them as magic black boxes.

Problem

Without the mental model of weights, layers, forward passes, and gradient-based training, higher-level topics (transformers, fine-tuning, quantization, inference cost) feel arbitrary and hard to reason about.

Solution

Ground everything in the basics: an LLM is an enormous neural network (billions of weights) doing forward passes of matrix math, trained by gradient descent on next-token prediction. Transformers, attention, LoRA, and quantization all become concrete once you see them as operations on these weights and activations.

๐Ÿ’ก

Takeaway: Neural-network fundamentals are the foundation for all of modern AI. Weights, activations, forward propagation, and backprop are the vocabulary that makes transformers, fine-tuning, and inference optimization comprehensible rather than magical.

Join the discussion

Comments

?

Loading comments...

Cookie preferences

We use essential cookies for sign-in and preferences. With your permission, we also use basic analytics to improve lessons.