001 Notes

Neural Network Tutor: Replay, Gradients, And Ablation

Neural networks are often taught from two weak angles.

One angle is pure equations. The equations are correct, but a learner struggles to connect them to behavior.

The other angle is dashboards. Loss curves and accuracy charts show that training changed something, but they hide why a weight moved, why a neuron activated, why a deeper network helped, or why a wider network overfit.

A better teaching primitive is replay.

one example
-> forward pass
-> prediction
-> loss
-> backward pass
-> gradients
-> update preview
-> weight change
-> new prediction

Replay makes the training process inspectable. But a useful tutor should go further than one backprop step. It should show how architecture changes behavior:

one neuron
-> many neurons in one layer
-> wider layer
-> deeper stack
-> dense connectivity
-> bottleneck
-> activation removed
-> neuron ablated
-> layer frozen

This article explains how neurons behave, why width and depth matter differently, when shallow networks are enough, when deep networks help, when dense layers are expensive, and how ablation turns architecture claims into testable evidence.

1. One Neuron Is A Learned Detector

A neuron computes:

z = w1*x1 + w2*x2 + ... + wn*xn + b
a = activation(z)

Vector form:

z = w dot x + b
a = f(z)

Meaning:

SymbolIntuition
xinput features
wwhat the neuron pays attention to
bthreshold shift
zraw match score
factivation/gate
asignal passed to next layer

The weights define a direction in input space. The dot product measures how aligned the input is with that direction.

For two input features:

z = w1*x1 + w2*x2 + b

The boundary is:

w1*x1 + w2*x2 + b = 0

That is a line in 2D. In higher dimensions, it is a hyperplane.

one neuron
-> one learned boundary
-> one detector

The bias moves the boundary:

b larger  -> boundary shifts one way
b smaller -> boundary shifts the other way

The activation decides what the neuron emits after computing the boundary score.

2. A Single Neuron Worked Example

Suppose the input has two features:

x1 = 2.0
x2 = -1.0
w1 = 0.30
w2 = -0.20
b  = 0.10

Forward pass:

z = x1*w1 + x2*w2 + b
z = 2.0*0.30 + (-1.0)*(-0.20) + 0.10
z = 0.60 + 0.20 + 0.10
z = 0.90

If activation is identity for this toy example:

a = z = 0.90
prediction = 0.90

Target:

target = 1.50
error = prediction - target
error = 0.90 - 1.50
error = -0.60

The prediction is too low. Training should push the output upward for this example.

For squared error:

loss = 0.5 * (prediction - target)^2
loss = 0.5 * (-0.60)^2
loss = 0.18

The 0.5 is not magic. It makes the derivative cleaner:

d/dp [0.5 * (p - y)^2] = p - y

The tutor should show this arithmetic before showing matrix notation. Matrix notation is compact, but the learner needs to see where the numbers come from.

3. Backprop For One Weight

Backpropagation is chain rule applied backward through the computation graph.

For the toy neuron:

loss = 0.5 * (prediction - target)^2
prediction = z
z = x1*w1 + x2*w2 + b

Gradient for w1:

dLoss/dw1
= dLoss/dprediction * dprediction/dz * dz/dw1

Substitute values:

dLoss/dprediction = prediction - target = -0.60
dprediction/dz = 1.0
dz/dw1 = x1 = 2.0

So:

dLoss/dw1 = -0.60 * 1.0 * 2.0
dLoss/dw1 = -1.20

For w2:

dLoss/dw2 = -0.60 * 1.0 * (-1.0)
dLoss/dw2 = 0.60

For bias:

dLoss/db = -0.60 * 1.0 * 1.0
dLoss/db = -0.60

With learning rate 0.10:

new_weight = old_weight - learning_rate * gradient
ParameterBeforeGradientDeltaAfter
w10.30-1.20+0.120.42
w2-0.200.60-0.06-0.26
b0.10-0.60+0.060.16

The sign is the central lesson:

negative gradient:
  gradient descent subtracts a negative
  parameter increases

positive gradient:
  gradient descent subtracts a positive
  parameter decreases

Why did w1 increase but w2 decrease?

the output was too low
x1 was positive, so increasing w1 increases output
x2 was negative, so decreasing w2 increases output

This is the kind of explanation a tutor should make visible.

4. Activation Functions Change Neuron Behavior

Without activation, a neuron is just a linear score.

With activation, the neuron becomes a nonlinear gate or squashing function.

ActivationFormulaBehavior
identitya = zpasses raw value
sigmoida = 1 / (1 + exp(-z))squashes to 0..1
tanha = tanh(z)squashes to -1..1
ReLUa = max(0, z)zeroes negative values
softmaxexp(z_i) / sum(exp(z_j))turns logits into class probabilities

ReLU is especially visual:

z <= 0 -> neuron silent
z > 0  -> neuron active

For one example:

z = -0.7
relu(z) = 0

The neuron emits nothing. During backprop, the derivative is also zero for negative z:

d relu(z) / dz = 0 when z <= 0
d relu(z) / dz = 1 when z > 0

That means a ReLU neuron can be inactive for an example and receive no gradient through that activation.

Tutor view:

neuron z: -0.7
activation: 0
activation derivative: 0
gradient through this neuron: blocked for this example

This makes “dead ReLU” concrete. A neuron that is inactive for almost every example will barely learn.

5. Why Nonlinearity Makes Depth Useful

If a network has no nonlinear activation, stacked layers collapse into one linear layer.

y = W3(W2(W1x))
y = (W3 * W2 * W1)x

The product of linear transformations is another linear transformation.

So this:

input -> dense -> dense -> dense -> output

without nonlinear activations behaves like:

input -> one dense linear transform -> output

With nonlinear activations:

y = W3 * relu(W2 * relu(W1x + b1) + b2) + b3

Now different inputs activate different paths. The model becomes piecewise linear.

Intuition:

layer 1 gates the input space
layer 2 combines those gated regions
layer 3 combines combinations

Ablation:

Model A: 3 dense layers with ReLU
Model B: same 3 dense layers, activation removed

Expected behavior:

ObservationMeaning
Model B cannot solve nonlinear datadepth without activation collapsed
Model B trains but plateaus earlylinear capacity is insufficient
Model A improvesnonlinear gates are doing useful work

This is one of the most important experiments in a neural network tutor.

6. Dense Layer Math

A dense layer connects every input feature to every output neuron.

a = activation(Wx + b)

If input dimension is D and output width is H:

W shape = H x D
b shape = H
parameter_count = H*D + H

Example:

input_dim = 20
hidden_width = 64
parameters = 20*64 + 64
parameters = 1,344

Each row of W is one neuron:

W =
[
  neuron_1 weights
  neuron_2 weights
  neuron_3 weights
  ...
]

So a dense layer with 64 neurons learns 64 different detectors over the same input.

The forward pass for a whole layer is:

z1 = w1 dot x + b1
z2 = w2 dot x + b2
...
zH = wH dot x + bH

Then activation is applied:

a1 = f(z1)
a2 = f(z2)
...
aH = f(zH)

The tutor should show a dense layer as parallel detectors, not as a mysterious rectangle.

7. Width: More Detectors In Parallel

Width means more neurons in a layer.

narrow layer:
  8 neurons

medium layer:
  64 neurons

wide layer:
  512 neurons

More width gives the model more parallel detectors.

one neuron:
  one boundary

many neurons:
  many boundaries
  many gated features
  many ways to separate the data

Mathematical effect:

layer output lives in H-dimensional feature space

If H is small, the layer compresses the input into few signals. If H is large, the layer can preserve and expand many directions.

Tradeoff:

WidthEffect
too narrowunderfitting, lost information
moderateenough detectors for useful patterns
very widehigh capacity, more compute, overfit risk

Parameter cost grows linearly with width for one layer:

D -> H
parameters = D*H + H

But if two neighboring layers are both wide, cost can grow sharply:

H1 -> H2
parameters = H1*H2 + H2

Example:

512 -> 512 dense layer
= 512*512 + 512
= 262,656 parameters

4096 -> 4096 dense layer
= 4096*4096 + 4096
= 16,781,312 parameters

Width is not free. The tutor should always show parameter count next to architecture diagrams.

8. Depth: Composition Over Time

Depth means more layers in sequence.

input
-> layer 1
-> layer 2
-> layer 3
-> output

Depth is useful when the task is compositional.

For images:

pixels
-> edges
-> corners/textures
-> object parts
-> full objects

For language:

characters/tokens
-> local patterns
-> phrases
-> sentence meaning
-> task answer

For tabular data:

raw features
-> pairwise interactions
-> higher-order interactions
-> decision

Depth lets the model reuse intermediate features. A later layer does not have to rediscover raw edges or simple interactions. It can combine signals already created by earlier layers.

But depth also makes optimization harder.

Gradient to early layers passes through many transformations:

dLoss/dh0 =
  dLoss/dhL
  * dhL/dhL-1
  * dhL-1/dhL-2
  * ...
  * dh1/dh0

If many terms are small, gradients vanish.

0.5 * 0.5 * 0.5 * 0.5 * 0.5 = 0.03125

If many terms are large, gradients explode.

2 * 2 * 2 * 2 * 2 = 32

Tutor view:

layer 1 gradient norm: 0.00003
layer 2 gradient norm: 0.00210
layer 3 gradient norm: 0.09100
output gradient norm: 0.84000

That view explains why early layers may barely learn in a poorly designed deep network.

9. Shallow Narrow Networks

Shape:

input -> small hidden layer -> output

Example:

20 -> 8 -> 1

Good for:

simple tabular problems
small datasets
linear-ish relationships
fast educational demos

Bad for:

complex nonlinear boundaries
high-dimensional input
many independent patterns
image or language tasks

Failure symptom:

training loss high
validation loss high
model underfits

Ablation:

increase width from 8 to 64
keep depth fixed
compare training loss

If both training and validation improve, the narrow model lacked capacity.

10. Shallow Wide Networks

Shape:

input -> very wide hidden layer -> output

Example:

20 -> 512 -> 1

Good for:

many parallel nonlinear detectors
problems where one hidden layer is enough
fast experiments with simple optimization

Bad for:

small datasets with noise
raw high-dimensional input
tasks that need hierarchical composition

A shallow wide network can approximate many functions, but it may need a lot of neurons to represent structure that a deeper network can represent more compactly.

Example intuition:

shallow wide:
  memorize many local patches of the input space

deep:
  build reusable intermediate features

Overfitting symptom:

training accuracy: 99%
validation accuracy: 65%

Ablation:

train widths: 32, 128, 512, 2048
plot train loss and validation loss

Expected lesson:

training loss keeps improving
validation loss improves then gets worse

That is capacity turning into memorization.

11. Deep Narrow Networks

Shape:

input -> narrow layer -> narrow layer -> narrow layer -> output

Example:

20 -> 16 -> 16 -> 16 -> 1

Good for:

compositional structure
parameter-efficient experiments
forcing intermediate abstractions

Bad for:

tasks needing many independent features at once
optimization without normalization/residual help
datasets where early compression destroys information

Deep narrow networks can be elegant, but a too-narrow early layer becomes a bottleneck.

Example:

input has 100 independent useful features
first hidden layer has 4 neurons

The model must compress 100 useful signals into 4 numbers. If the target depends on many independent details, that compression may be impossible.

Ablation:

20 -> 4 -> 4 -> 4 -> output
20 -> 16 -> 16 -> 16 -> output
20 -> 64 -> 64 -> 64 -> output

Inspect:

training loss
validation loss
activation saturation
gradient norms
examples whose predictions change

If widening the early layer fixes both training and validation, the narrow layer was discarding useful signal.

12. Deep Wide Networks

Shape:

input -> wide -> wide -> wide -> output

Example:

512 -> 1024 -> 1024 -> 1024 -> 10

Good for:

large datasets
complex functions
many feature interactions
high-capacity research experiments

Bad for:

small data
weak regularization
limited memory
slow local training
educational clarity if everything is hidden

Parameter count:

512 -> 1024: 512*1024 + 1024 = 525,312
1024 -> 1024: 1,049,600
1024 -> 1024: 1,049,600
1024 -> 10: 10,250

total: about 2.63M parameters

This may be fine for a real model, but it is too much if the tutor cannot explain what changed.

Ablation:

halve width
remove one layer
freeze first layer
compare validation loss and gradient flow

Lesson:

high capacity is useful only when data, optimization, and regularization support it

13. Bottlenecks

A bottleneck is a narrow layer between wider layers.

128 -> 16 -> 128

It forces compression.

Mathematical intuition for a linear bottleneck:

D -> K -> D
rank <= K

If K is small, the network cannot preserve all independent directions through that bottleneck.

Good bottleneck case:

input has 100 features
only 10 are useful
many features are noise

Architecture:

100 -> 16 -> 64 -> output

The bottleneck can force the model to ignore noise and keep useful structure.

Bad bottleneck case:

input contains many independent useful facts
small differences matter

Architecture:

512 -> 8 -> 512

The bottleneck may destroy important distinctions.

Ablation:

hidden width 128
hidden width 32
hidden width 8

Watch:

which classes collapse together
which examples become confused
whether training loss itself gets stuck

If training loss is bad, the bottleneck is too restrictive. If training loss is good but validation improves, the bottleneck may be regularizing.

14. Dense Connectivity

Dense connectivity means every output neuron sees every input from the previous layer.

output_j = activation(sum_i input_i * weight_j_i + bias_j)

Parameter count:

params = input_dim * output_dim + output_dim

Good dense case:

20 tabular features -> 64 hidden units
params = 20*64 + 64 = 1,344

This is manageable. Every feature can interact with every hidden detector.

Bad dense case:

224 * 224 * 3 image pixels -> 4096 hidden units
input_dim = 150,528
params = 150,528 * 4096 + 4096
params = 616,566,784

That is only one dense layer.

For raw images, dense connectivity wastes parameters because it ignores locality. Neighboring pixels are related, but a dense layer treats every pixel-position interaction as separate. CNNs use local filters and weight sharing to avoid that explosion.

Tutor lesson:

dense layers are flexible for compact features
dense layers are expensive for raw high-dimensional inputs

15. Sparse, Local, And Residual Connections

Not every architecture should be fully dense.

Sparse/local connection:

each neuron sees only part of previous layer

Convolution:

small filter reused across image positions

Residual connection:

output = layer(input) + input

Why residual helps:

gradient has a shortcut path backward
signal has a shortcut path forward
deep network can learn modifications instead of everything from scratch

A tutor does not need to implement every architecture first. But it should explain that “dense” is one connectivity choice, not the definition of neural networks.

16. Case Study: Linear Boundary

Task:

classify points separated by one straight line

Example:

approve if income - debt > threshold

A single neuron can solve it:

z = w1*income + w2*debt + b
output = sigmoid(z)

Expected comparison:

ModelBehavior
one neuronlearns well
one hidden layeralso learns, extra capacity unused
deep networkmay learn, but unnecessary
deep network without enough datamay overfit or train slower

Ablation:

train one neuron
train 3-layer network
compare validation loss and parameter count

Lesson:

If the true boundary is simple, depth is extra machinery.

17. Case Study: XOR

Task:

x1 XOR x2

Truth table:

x1x2output
000
011
101
110

One linear neuron fails because XOR is not linearly separable.

no single straight line separates the 1s from the 0s

A hidden layer solves it:

2 inputs -> 2 hidden nonlinear neurons -> output

Intuition:

hidden neuron A detects one region
hidden neuron B detects another region
output combines the regions

Ablation:

ModelExpected result
no hidden layercannot solve XOR
hidden width 1usually insufficient
hidden width 2can solve
remove activationfails again

Lesson:

width plus nonlinearity creates multiple regions.

18. Case Study: Circle Inside Square

Task:

classify points inside a circle as 1
outside as 0

A single neuron draws one line. It cannot draw a circle.

A shallow wide network can approximate the circle by combining many linear boundaries:

many ReLU/sigmoid neurons
-> many half-spaces
-> polygon-like approximation of circle

Visual intuition:

4 neurons  -> rough diamond/square boundary
8 neurons  -> rough octagon
32 neurons -> smoother circle-like boundary

Depth can help by composing simpler regions, but this task is also a clean example of width helping directly.

Ablation:

hidden width: 2, 4, 8, 32
same depth: 1 hidden layer
compare decision boundary

Expected lesson:

wider hidden layer creates more boundary pieces

19. Case Study: Image Recognition

Task:

recognize cats in images

A raw dense shallow model sees:

pixel_1, pixel_2, pixel_3, ..., pixel_150528

It must learn:

all pixels -> cat/not cat

That is inefficient because image structure is hierarchical and local.

Deep visual model intuition:

early layers:
  edges, colors, simple textures

middle layers:
  corners, fur textures, eye-like patterns

later layers:
  ears, face shapes, object parts

output:
  class decision

Ablation:

ModelExpected weakness
raw pixels -> dense outputunderfits or overfits badly
shallow huge dense modelenormous parameter count
deep model with local filtersbetter hierarchy
deep model without activationloses nonlinear composition

Lesson:

Depth helps when useful features are built from smaller reusable features.

20. Case Study: Small Tabular Dataset

Task:

predict house price from 20 features and 2,000 examples

A modest model may work:

20 -> 64 -> 1

A very large model may memorize:

20 -> 512 -> 512 -> 512 -> 1

Symptoms:

training loss falls
validation loss rises
predictions become brittle
small input changes create unstable outputs

Ablation:

reduce width
remove one layer
add weight decay/dropout
compare validation loss

Lesson:

data size limits useful model capacity.

The tutor should show train and validation curves together. Training loss alone encourages bad conclusions.

21. Case Study: Noisy Labels

Task:

classify examples where 15% of labels are wrong

A high-capacity model may eventually memorize mislabeled examples.

Training pattern:

early training:
  model learns broad real pattern

late training:
  model starts fitting noisy exceptions

Symptoms:

training accuracy keeps rising
validation accuracy peaks then falls
high-confidence wrong predictions increase

Ablation:

train narrow model
train wide model
train wide model with early stopping
train wide model with weight decay

Lesson:

more capacity can fit truth first and noise later.

The tutor should show example-level prediction changes so the learner can see which examples were memorized.

22. Case Study: Too Deep Without Support

Task:

simple classification, plain 30-layer MLP

Problem:

gradients must pass through many layers

Symptoms:

loss plateaus
early-layer gradients near zero
some layers saturate
training unstable

Ablation:

3 layers
10 layers
30 layers
30 layers with residual connections
30 layers with normalization

Expected lesson:

depth adds representational power
but optimization needs architecture support

The tutor should show gradient norms per layer:

layer 1: 0.000001
layer 2: 0.000004
layer 3: 0.000020
...
output: 0.810000

That makes vanishing gradient visible.

23. Case Study: Bad Bottleneck

Task:

classify objects where small details matter

Architecture:

512 -> 8 -> 512 -> output

If the important signal requires many independent directions, 8 hidden values cannot carry enough information.

Symptoms:

training loss remains high
classes with subtle differences collapse
hidden activations look similar across examples

Ablation:

bottleneck width 8
bottleneck width 32
bottleneck width 128

If training improves as bottleneck width increases, the small bottleneck was limiting capacity.

24. Case Study: Good Bottleneck

Task:

input has many noisy features but few real factors

Architecture:

100 -> 16 -> 64 -> output

The bottleneck can force compression and reduce noise.

Symptoms:

training loss slightly worse than huge model
validation loss better
predictions less sensitive to noisy features

Ablation:

no bottleneck
wide bottleneck
narrow bottleneck

Lesson:

compression can regularize when signal is lower-dimensional than input.

25. Mini-Batches And Architecture

Training usually averages gradients across a mini-batch.

batch_gradient =
  average(example_1_gradient,
          example_2_gradient,
          ...
          example_n_gradient)

This matters for architecture inspection because different examples can push the same neuron in opposite directions.

Example:

example A gradient for w1: -1.20
example B gradient for w1:  0.40
example C gradient for w1: -0.10

batch average: -0.30

The final update is smaller than example A alone.

Tutor display:

selected weight: w1
example contributions:
  A: increase strongly
  B: decrease mildly
  C: increase mildly
batch update:
  increase slightly

This helps learners understand why one example may look “ignored” in a batch update.

26. Optimizers Change Motion

Plain gradient descent:

w = w - lr * gradient

Momentum adds velocity:

velocity = momentum * velocity + gradient
w = w - lr * velocity

Adam tracks adaptive moments:

first moment: average gradient direction
second moment: average squared gradient scale

The same architecture can behave differently under different optimizers.

Ablation:

same network
same data
same initialization
train with SGD, momentum, Adam
compare update paths

Tutor lesson:

architecture defines capacity
optimizer defines how parameters move through that capacity

27. Architecture Ablation Lab

Ablation means remove or change one thing and measure the effect.

Useful ablations:

AblationQuestion
remove one neurondid this detector matter?
zero one weightwas this connection important?
freeze one layerdoes this layer need learning?
widen a layerdoes capacity help?
narrow a layerdoes compression hurt?
add depthdoes composition help?
remove activationwas nonlinearity essential?
remove biasdid thresholds matter?
add bottleneckdoes compression regularize?
change optimizerwas motion, not capacity, the issue?
shuffle labelscan the model memorize noise?

Each ablation should report:

parameter count
training loss
validation loss
gradient norm per layer
activation sparsity
examples changed most
confidence distribution
runtime cost

The important part is controlled comparison.

Bad experiment:

changed depth, width, optimizer, learning rate, and dataset split

Good experiment:

same data
same seed
same optimizer
same training steps
only width changed

Without controlled ablation, architecture claims are guesses.

28. Replay UI For Architecture

The tutor should make architecture behavior clickable.

Click a neuron:

incoming weights
bias
z value
activation value
activation derivative
examples where it activates
examples where it stays silent
gradient received
update magnitude

Click a layer:

width
parameter count
activation distribution
dead/inactive neurons
gradient norm
input/output shape
role in architecture

Click a connection:

before weight
input activation
upstream error
gradient
learning rate
delta
after weight

Click an architecture variant:

shallow narrow
shallow wide
deep narrow
deep wide
bottlenecked
activation removed
layer frozen

Then compare:

did it learn faster?
did it generalize better?
which examples changed?
which neurons activated?
which gradients disappeared?
which parameters mattered?

This turns model design into a causal lab.

29. Implementation Blueprint

A replay record should store:

architecture id
dataset split id
training step
batch ids
layer shapes
parameter counts
forward activations
pre-activation z values
loss
gradients
optimizer state where relevant
before parameters
after parameters
validation metrics
ablation id if active

For large networks, store summaries by default and detailed traces only for selected examples/layers:

always store:
  loss
  accuracy
  gradient norms
  activation sparsity
  parameter counts

store on demand:
  full activation vectors
  per-weight gradients
  per-example contribution

This keeps the tutor responsive while still allowing deep inspection.

UI rule:

training and replay generation run off the UI thread
large diagrams render lazily
only selected detail panes compute heavy traces
generated replay artifacts are visible and deletable

Educational tools still need production discipline.

30. What Was Done And Why

The tutor centers replay because neural networks are easier to understand as time-varying systems. A learner needs to see how one input creates activations, how activations create loss, how loss creates gradients, and how gradients change weights.

One-neuron inspection is included because every larger architecture is built from the same primitive: weighted sum, bias, activation, gradient, update.

Width comparisons are included because more neurons create more parallel detectors. This helps on nonlinear region carving, but can also overfit noisy or small datasets.

Depth comparisons are included because deeper networks compose features. This helps hierarchical tasks, but introduces vanishing/exploding gradients and optimization difficulty.

Dense-layer parameter counts are included because flexibility has a cost. A dense layer over compact features can be reasonable; a dense layer over raw images can be absurdly large.

Bottleneck experiments are included because compression can be good or bad depending on whether the task has low-dimensional signal or needs many independent details.

Ablation is included because it is the only honest way to test architecture explanations. If removing a neuron changes nothing, that neuron was not important for the measured behavior. If removing activation breaks the model, nonlinearity was doing real work. If widening improves training but hurts validation, capacity turned into memorization.

31. What Was Used, Removed, Or Deferred

Used:

step-by-step replay
single-neuron inspection
forward-pass arithmetic
chain-rule traces
weight update tables
activation behavior views
width/depth architecture comparisons
parameter-count visibility
gradient norm inspection
activation sparsity inspection
architecture ablation experiments
train-vs-validation comparisons
example-level prediction deltas

Removed or avoided:

teaching neural networks only as equations
showing only final accuracy
hiding gradients behind charts
generic network diagrams with no numbers
claiming depth is always better
claiming width is always better
ignoring parameter count
changing multiple experiment variables at once

Deferred:

large-model training
GPU-heavy training runtime
automatic architecture search
full tracing for every weight in large networks
over-general visual framework for every model family

The core lesson is that architecture is behavior. Width gives parallel detectors. Depth gives composition. Dense connectivity gives flexible interaction at parameter cost. Bottlenecks force compression. Activations make depth meaningful. Optimizers decide how parameters move. Ablation proves which of those choices actually mattered.

Comments