Picture a support desk that receives hundreds of incoming tickets every day. For each ticket, software has to answer one practical question: is this urgent?
Computers and neural networks cannot read text or judge priority directly. Every model begins by encoding a real-world situation into a fixed list of numbers called an input feature vector. Suppose an incoming ticket is summarized by three numerical features: 2 unresolved tickets already open for that customer, a priority score of 8, and 5 hours spent waiting in the queue.
Turning [2, 8, 5] into a decision starts inside a single mathematical unit that multiplies each input by a weight, adds a bias offset, and checks a threshold. That simple unit handles clean cutoffs well until a pattern like exclusive-OR (XOR) breaks every straight line you try to draw. Getting past that geometric wall is the entire reason deep neural networks are stacked out of layers with nonlinear steps in between.
Inside a single neuron
Start with one artificial neuron. Our support ticket feeds it three input features packed into a vector x: x1 = 2 unresolved tickets, x2 = 8 for the priority score, and x3 = 5 hours waiting.
Notice those three features measure completely different quantities (counts, ratings, and hours). Each input receives a weight (w1, w2, w3), a number that controls both how strongly that signal pulls the score and in which direction (positive weights push scores up, negative weights push them down). The neuron multiplies each input by its matching weight, adds the products together, and adds one shared offset called the bias (b):
Do not let the right-hand notation look mysterious. When we collect inputs into a vertical column vector x and weights into a matching column w, writing w^T (transpose) simply tips w on its side into a horizontal row [w1, w2, w3]. Multiplying that row by column x computes their dot product (w1*x1 + w2*x2 + w3*x3), a single shorthand that works just as cleanly for 3 inputs or 3,000. Combining weighted products with a shift + b is called an affine transformation.
Plug in illustrative parameters w = [0.4, 0.7, 0.2] and b = -3. Multiplying each feature by its weight gives 0.4 * 2 = 0.8, 0.7 * 8 = 5.6, and 0.2 * 5 = 1.0. Summing those weighted contributions produces 7.4. Adding the bias shifts that total down by 3, landing at z = 4.4.
Why keep a separate bias term at all? Test what happens when every input equals zero (x1 = x2 = x3 = 0). Without b, multiplying zero by any weight always leaves z = 0, pinning the neuron to zero whenever features disappear. Including b decouples the neuron's baseline from the origin (z = b when all x = 0), acting like an adjustable threshold offset.
Where do numbers like 0.4 or -3 come from in real models? No engineer chooses them by hand. Training begins with small random numbers for weights and biases, feeds labeled tickets through the forward arithmetic, measures how far predictions sit from known urgency labels using a loss function, and nudges each weight and bias repeatedly via gradient updates until prediction error drops. In this article we inspect how the network computes and shapes boundaries once weights exist.
The final step inside the neuron passes z through an activation function, f(z), to produce its output. Swapping f is what turns the same weighted sum into either a rigid threshold switch or a composable unit inside deep networks.
The perceptron and its straight-line boundary
The earliest activation function is a hard step function, introduced by Frank Rosenblatt in 1958 inside the perceptron:
Read the perceptron in three concrete stages: score the weighted evidence (z = w^T x + b), test whether that score clears zero (z >= 0), and emit a binary decision (1 for urgent, 0 for not urgent). On our [2, 8, 5] ticket, z = 4.4 >= 0, so the perceptron predicts 1.
To see what a perceptron can divide, simplify to two inputs x1 and x2 so every input pair (x1, x2) becomes a point on a flat 2D plane. The output flips cleanly between 0 and 1 right where z = 0, along w1 * x1 + w2 * x2 + b = 0. Solving for x2 (assuming w2 != 0) gives x2 = -(w1 / w2) * x1 - (b / w2) (while w2 = 0 gives a vertical line x1 = -b / w1). Either way, it is always a straight line.
Changing the weights alters the ratio -w1 / w2, which changes the slope and rotates the dividing line. Changing the bias alters -b / w2, which changes the intercept and slides the line across the plane without rotating it. Every point on the side where w1 * x1 + w2 * x2 + b >= 0 outputs 1 (the weight vector (w1, w2) points into that positive half-plane), and every point on the opposite side outputs 0. You can always check which side is 0 or 1 by testing (0, 0), which gives z = b.
For any rule that a straight cut can isolate (linearly separable patterns), one perceptron solves it effortlessly. Take logical AND on binary inputs 0 and 1, where output is 1 only when both x1 = 1 and x2 = 1: setting w1 = 1, w2 = 1, and b = -1.5 gives z = x1 + x2 - 1.5. Checking all four corners gives -1.5 -> 0 at (0, 0), -0.5 -> 0 at (0, 1) and (1, 0), and +0.5 -> 1 at (1, 1). Likewise, shifting only the bias to b = -0.5 solves logical OR (x1 + x2 - 0.5 >= 0 whenever at least one input is 1).
The XOR blind spot
A single straight cut breaks as soon as two classes are interleaved across opposite diagonals. The classic failure case, highlighted in Marvin Minsky and Seymour Papert's 1969 analysis of perceptrons, is XOR (exclusive OR): output 1 when exactly one binary input is 1, and 0 when both match:
| x1 | x2 | Target y (x1 XOR x2) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Picture those four corners on a square. The two positive points (0, 1) and (1, 0) sit on one diagonal, while the two negative points (0, 0) and (1, 1) sit on the opposite diagonal. Rotate or slide a single straight ruler anywhere across that square: it is geometrically impossible to keep (0, 1) and (1, 0) on one side while placing (0, 0) and (1, 1) on the other.
Four lines of algebra prove no choice of weights and bias can cheat that geometry. Suppose a single perceptron z = w1 * x1 + w2 * x2 + b gets all four corners right: (0, 0) -> 0 forces b < 0, (1, 0) -> 1 forces w1 + b >= 0, and (0, 1) -> 1 forces w2 + b >= 0. Adding the two positive inequalities gives w1 + w2 + 2b >= 0. Because b < 0, subtracting b makes the right side strictly positive (-b > 0), forcing w1 + w2 + b >= -b > 0. That guarantees input (1, 1) outputs 1 when XOR requires 0. No single linear separator (whether a step perceptron or raw logistic regression on the original features) can represent XOR.
You can test that algebra directly in Python below. Try changing w1, w2, and bias in section 2 (Single perceptron): the error count never drops to 0/4, whereas combining two hidden neurons (h1, h2) feeding an output neuron solves all four cases immediately:
def step(z: float) -> int:return 1 if z >= 0 else 0# 1. Support-ticket neuron from the earlier examplex = [2, 8, 5]w = [0.4, 0.7, 0.2]b = -3.0z = sum(wi * xi for wi, xi in zip(w, x)) + bprint(f"Ticket score z = {z:.1f}, step(z) = {step(z)}")# 2. Try ANY single straight line (w1, w2, bias) on XORxor_cases = [((0, 0), 0), ((0, 1), 1), ((1, 0), 1), ((1, 1), 0)]w1, w2, bias = 1.0, 1.0, -0.5 # Edit these weights and re-runsingle_errors = sum(step(w1 * a + w2 * c + bias) != y for (a, c), y in xor_cases)print(f"Single perceptron errors on XOR: {single_errors}/4")# 3. Two hidden neurons + one output neuron solve XORdef xor_mlp(a: float, c: float) -> int:h1 = step(a + c - 0.5) # fires if at least one input is 1 (OR)h2 = step(a + c - 1.5) # fires if both inputs are 1 (AND)return step(h1 - h2 - 0.5) # keeps the band where h1=1 and h2=0mlp_errors = sum(xor_mlp(a, c) != y for (a, c), y in xor_cases)print(f"Two-layer MLP errors on XOR: {mlp_errors}/4")
Rather than treating xor_mlp as magic, trace every input pair through both hidden neurons (h1, h2) and the final output neuron (y_hat = step(h1 - h2 - 0.5)). Notice what h1 and h2 actually compute: h1 checks the OR boundary (x1 + x2 - 0.5 >= 0), and h2 checks the AND boundary (x1 + x2 - 1.5 >= 0). Because XOR means "at least one input is on (h1 = 1), and not both (h2 = 0)", giving h1 weight +1, h2 weight -1, and bias -0.5 turns (h1 = 1, h2 = 0) into +0.5 -> 1 while leaving every other combination negative:
| (x1, x2) | h1 = step(x1+x2-0.5) | h2 = step(x1+x2-1.5) | step(h1 - h2 - 0.5) |
|---|---|---|---|
| (0, 0) | 0 | 0 | 0 (score -0.5) |
| (0, 1) | 1 | 0 | 1 (score +0.5) |
| (1, 0) | 1 | 0 | 1 (score +0.5) |
| (1, 1) | 1 | 1 | 0 (score -0.5) |
Multi-layer perceptrons and why nonlinearity matters
In xor_mlp, putting two neurons (h1, h2) in a hidden layer in front of an output neuron built a multi-layer perceptron (MLP): a network where each layer consumes the outputs produced by the previous layer. Look at what happened geometrically in the trace table above. Originally (0, 1) and (1, 0) sat on opposite corners of the plane. Passing them through (h1, h2) mapped both positive corners onto the exact same hidden coordinate (1, 0), while (0, 0) stayed at (0, 0) and (1, 1) moved to (1, 1). Inside that new hidden coordinate space, a single straight cut cleanly separates (1, 0) from the rest.
When we pack several neurons side by side into one layer, we write the whole layer in matrix notation: stack each neuron's weight vector as one row inside weight matrix W, stack their biases into vector b, multiply Wx + b, and apply an activation function f independently to every neuron's score (element-wise), written h = f(Wx + b).
Why does f have to be nonlinear (something that bends or clamps rather than scaling cleanly along flat lines)? Look at what happens if you remove f and stack two purely linear transformations back to back (h = W1 x + b1, then y = W2 h + b2). Think of a simple 1D example first: running 3x + 1 and multiplying the output by 2 gives 2(3x + 1) - 5 = 6x - 3, which is still just one straight line. The exact same algebraic collapse holds for matrices of any size:
Because the product of two matrices W2 W1 is just another matrix W' and W2 b1 + b2 is just another bias vector b', stacking two (or two hundred) linear layers without nonlinear activations can never represent anything a single linear layer could not already draw. Every hyperplane stays flat.
Modern neural networks prevent linear collapse, and fix a fatal limitation of the 1958 step function, using ReLU (Rectified Linear Unit), defined simply as ReLU(z) = max(0, z). Any negative score becomes 0, while positive scores pass through unchanged with slope 1. Unlike the binary step(z), which stays completely flat (slope = 0) everywhere except the threshold jump and starves gradient-based learning of directional feedback, ReLU keeps a constant active slope for positive values while still putting a sharp bend at z = 0:
Trace how two standard ReLU neurons solve XOR when inputs enter as s = x1 + x2: build neuron 1 as h1 = ReLU(1*x1 + 1*x2 + 0) = ReLU(s), build neuron 2 with a -1 bias as h2 = ReLU(1*x1 + 1*x2 - 1) = ReLU(s - 1), and combine them at the output as 1 * h1 - 2 * h2. Watch every checkpoint along s:
- At
s = 0((0, 0)):ReLU(0) - 2 * ReLU(-1) = 0 - 0 = 0. - At
s = 1((0, 1)and(1, 0)):ReLU(1) - 2 * ReLU(0) = 1 - 0 = 1, peaking right at the target. - At
s = 2((1, 1)):ReLU(2) - 2 * ReLU(1) = 2 - 2 = 0, folding the ramp back down to zero.
Computed from s = x1 + x2 (XOR targets: 0 at s = 0, 1 at s = 1, 0 at s = 2)
Seeing the sum piece by piece: ReLU(s) climbs steadily, -2 * ReLU(s - 1) switches on downward past s = 1, and adding both curves folds the flat linear diagonal into the XOR tent peaking at s = 1.
| sum of inputs (x1 + x2) | Combined XOR tent: ReLU(s) - 2 * ReLU(s - 1) | Linear layer only: 0.5 * s | Neuron 1: ReLU(s) | Weighted Neuron 2: -2 * ReLU(s - 1) |
|---|---|---|---|---|
| 0.0 | 0 | 0 | 0 | 0 |
| 0.5 | 0.5 | 0.25 | 0.5 | 0 |
| 1.0 | 1 | 0.5 | 1 | 0 |
| 1.5 | 0.5 | 0.75 | 1.5 | -1 |
| 2.0 | 0 | 1 | 2 | -2 |
Hidden layers and why depth helps
Any layer sitting between the raw input and the final prediction is called a hidden layer. Nothing about the math is secretive. It simply holds intermediate activation vectors (for example, [0.0, 1.3, 0.0, 2.1, 0.7, 0.4]) that a user never sees as the model's final answer, yet downstream layers use as cleaner coordinates than the raw inputs.
Think of classifying a photograph. Raw inputs are just grids of pixel intensities where moving an object by one pixel changes almost every number. Early hidden layers learn to detect simple local contrast edges (horizontal, diagonal, bright-to-dark). Subsequent hidden layers combine edges into corners and textures, deeper layers combine textures into recognizable parts like wheels or windows, and the final layer turns those high-level parts into class scores. Nobody programs rules for wheels or edges manually. Training adjusts the weights so useful intermediate representations emerge automatically because they drive prediction error down.
Mathematically, stacking hidden layers turns one monolithic mapping into function composition, much like breaking one enormous 2,000-line script into modular steps (parse() -> validate() -> transform() -> predict()) where each stage prepares easier structure for the next:
Notice how widening one layer and adding deeper layers grow a network along two completely different axes:
| Dimension | What increases | Role in the network |
|---|---|---|
| Width | More neurons working side by side in one layer | Computes more parallel detectors at the same representation level |
| Depth | More transformation layers stacked sequentially | Adds more steps of composition so later layers reuse what earlier layers already found |
A quick geometric example shows why composition is so economical. Build one two-neuron tent t(x) = 2 * ReLU(x) - 4 * ReLU(x - 0.5) on [0, 1]: it rises cleanly from 0 at x = 0 to 1 at x = 0.5 and drops back to 0 at x = 1, creating 2 linear segments. Pass t(x) back through a second identical 2-neuron layer (t(t(x))), and both halves fold again into 4 segments (2 peaks using 4 total neurons). Adding one more layer (t(t(t(x))), 6 total neurons) doubles again to 4 peaks (8 segments). Repeat across 10 layers (20 total neurons), and repeated folding produces 2^10 = 1,024 linear pieces. Under the Universal Approximation Theorem, a single wide hidden layer can represent continuous curves arbitrarily well too, yet building 1,024 distinct hinges flatly in one layer requires around a thousand parallel units rather than 20. Depth shines whenever structure repeats or composes.
Reading a real MLP in PyTorch
Once you connect neurons, affine matrices, ReLU bends, and layer composition, real neural network code stops looking opaque and reads like a clear wiring diagram. Inspect this compact PyTorch classifier:
import torch.nn as nnmodel = nn.Sequential(nn.Linear(20, 64),nn.ReLU(),nn.Linear(64, 10),)
Under the hood, nn.Sequential chains those modules in exact top-to-bottom order (out = layer2(relu(layer1(x)))), passing each layer's output tensor straight into the next:
nn.Linear(20, 64)creates64artificial neurons running side by side on the same20inputs (Wx + b), transforming every20-number input vector into a64-dimensional intermediate vector.nn.ReLU()clamps any negative entries among those64numbers to0element-wise so the second linear layer cannot collapse linearly back into the first.nn.Linear(64, 10)combines the64hidden features via10output neurons to emit10raw class scores called logits (unbounded scores such as[-1.2, 3.8, 0.4, ...]). Notice there is deliberately nonn.ReLU()after this final layer: clamping negative scores to zero would erase how strongly the model rejects unlikely classes and prevent loss functions likeCrossEntropyLoss(which convert logits into class probabilities internally via softmax) from training across negative values.
Brain Link on YouTube
How Neural Networks Actually Learn: Step-by-Step
Watch the full animated Brain Link episode covering the ticket neuron, rotating perceptron lines, the XOR grid, ReLU bending space, and this PyTorch architecture.
Every engineering trade-off for this classifier flows directly out of those three numbers (20, 64, and 10): they fix the exact shapes of every weight matrix and bias vector, how many bytes the network stores in memory, and how many arithmetic operations run per example. In Part 2 of this series, we derive parameter counts and FLOPs directly from those layer dimensions and examine where wide single layers hit practical limits.
References
- [1]Deep Feedforward Networks (Chapter 6, Deep Learning) · Ian Goodfellow, Yoshua Bengio, and Aaron CourvilleCovers the XOR problem, linear collapse, ReLU representation, and depth vs. width.
- [2]torch.nn.Linear documentation · PyTorch documentationApplies an affine linear transformation y = xA^T + b across input features.
- [3]torch.nn.ReLU documentation · PyTorch documentationApplies the rectified linear unit max(0, x) element-wise.
- [4]torch.nn.Sequential documentation · PyTorch documentationSequential container that passes inputs through modules in order.
- [5]How Neural Networks Actually Learn: Step-by-Step (video) · Brain Link on YouTube
- [6]Deep Learning Fundamentals playlist · Brain Link on YouTube







