VISUAL LESSON · 5 PICTURES

What Are Weights

What actually is a weight, and why does changing it rotate a decision boundary in space?

Progress stays on this device · no login
BEFORE THE FIRST PICTURE

How this lesson unfolds.

Weights are often described merely as numerical array elements, but geometrically they are directional dials. Every weight vector acts as an orthogonal normal defining a decision hyperplane, while activations bend and crease high-dimensional space so non-linear classifications become linearly separable.

Picture 1 of 5 · tap to inspect in full resolution
01

What actually is a weight, and why does changing it move a line in space?

INTUITION

Imagine holding a straight wooden ruler flat against a whiteboard. The orientation of the ruler is determined by an arrow sticking out perpendicular from its edge: that arrow is the weight vector w = [w₁, w₂]^T. If you dial w₁ up from 1 to 4, the arrow points sharply rightward, forcing the ruler to tilt steeply vertical. Now, what does the bias b do? It slides the ruler forward or backward along that normal direction without changing its tilt. When w^T x + b = 0, the line separates points where the score is positive from points where it is negative. A weight is a dial that steers the boundary's angle; a bias is a slider that sets its threshold.

  • Learning goalCalculate the normal vector w and perpendicular distance d = (b) / (\|w\|₂) of a separating hyperplane defined by w^T x + b = 0.
  • Helpful foundationsVector Normalization and Orthogonality · Essence of Linear Algebra: Linear Combinations and Span (3Blue1Brown) · Hyperplane Geometry in Machine Learning (Hastie, Tibshirani & Friedman, Elements of Statistical Learning)
  • Common trapBelieving that doubling both all weights and the bias changes the decision boundary. Because w^T x + b = 0 is a homogeneous equality, multiplying by any positive scalar α > 0 yields (α w)^T x + (α b) = 0, which defines the exact same geometric plane. However, scaling changes the slope of the sigmoid activation or the gradient magnitude during backpropagation.
  • Next connectionA single hyperplane can only slice space with a flat cut. To solve non-linear problems like XOR or circular rings, we need an activation function to bend and hinge the coordinate space.
✦ More context & mechanics
Conceptual Mechanics & Logic

The equation w^T x + b = 0 defines an affine hyperplane H of dimension n-1 inside an n-dimensional input space R^n:

  1. Orientation (Normal Vector):

The vector w = [w₁, w₂, ṡ, wₙ]^T is orthogonal (perpendicular) to the hyperplane H. For any two points x_a, x_b ∈ H:

w^T x_a + b = 0 and w^T x_b + b = 0 ⟹ w^T (x_a - x_b) = 0

Hence, adjusting weight wᵢ rotates the normal vector w, pivoting the boundary.

  1. Displacement (Bias Offset):

The signed Euclidean distance from the origin 0 to the hyperplane is:

d = (b) / (\|w\|₂)

If b = 0, the hyperplane passes directly through the origin regardless of w. When b ≠ 0, the plane shifts by distance d along the direction of -w.

Real-World Usage

Support Vector Machines (SVMs), Logistic Regression classifiers, and the final linear projection layer (classifier head / vocabulary un-embedding matrix W_(vocab) in LLMs) compute logits as distances to decision hyperplanes, directly determining token probabilities.

History & Origin Story

Analytic geometry founded by René Descartes in 1637 established equations of lines and planes. In 1957, Frank Rosenblatt interpreted Perceptron weights as physical potentiometers (motor-driven variable resistors) that physically turned to tilt classification boundaries during Mark I Perceptron training at Cornell.

How to Memorize & Golden Words
  • Golden Axiom: "Weights steer the tilt; bias sets the intercept."
  • w points straight into the positive decision region.
  • Points with w^T x + b > 0 lie on the 'yes' side; points with < 0 lie on the 'no' side.
Picture 2 of 5 · tap to inspect in full resolution
02

If linear lines can only cut straight across, how does a network draw circular boundaries and complex shapes?

INTUITION

Imagine a flat sheet of origami paper with a red circle drawn on it. You have a pair of scissors that can only make one straight slice (a linear classifier); you can never cut out the circle with a single straight line. But what if you can crease and fold the paper along straight lines? If you fold the paper four times along the circle's tangents, points outside the circle fold back upon each other, while the circle's interior is pushed into a raised facet. A single straight cut through the folded paper now cleanly isolates the circle! ReLU (a = max(0, z)) is an origami crease: it leaves one half-space flat while collapsing the negative half-space onto a flat boundary, effectively creasing multidimensional space.

  • Learning goalDemonstrate why deep linear networks collapse to a single matrix multiplication without non-linearities, and derive the piecewise linear partition created by ReLU activations.
  • Helpful foundationsAffine Transformations and Matrix Composition · Deep Learning: Universal Approximation Theorem (Cybenko 1989 / Hornik 1991) · On the Number of Linear Regions of Deep Neural Networks (Montúfar et al., NeurIPS 2014)
  • Common trapBelieving that stacking 100 linear layers creates a deep non-linear model. Because matrix multiplication is associative and closed under composition, W₃(W₂(W₁ x + b₁) + b₂) + b₃ = (W₃ W₂ W₁)x + (W₃ W₂ b₁ + W₃ b₂ + b₃) = W_(eff) x + b_(eff). 100 linear layers have zero additional expressive power over 1 single layer without activation functions.
  • Next connectionWith weights and non-linearities capable of forming complex decision manifolds, the central challenge becomes: how do we calculate exact updates for millions of weights using calculus backpropagation?
✦ More context & mechanics
Conceptual Mechanics & Logic
  1. Linear Collapse Theorem:

Consider a multi-layer network with L purely linear transformations:

h_l = W_l h_(l-1) + b_l

By unrolling the recursion:

h_L = ( ∏_(l=1)^L W_l ) x + b_(total) = W^ x + b^

Thus, depth without non-linearity yields zero additional expressive power beyond a single linear layer.

  1. The ReLU Space Folding:

The Rectified Linear Unit is defined as:

ReLU(z) = max(0, z) = z & if z > 0 \ 0 & if z ≤ 0

Its derivative is the Heaviside step function:

d/dz ReLU(z) = 1 & if z > 0 \ 0 & if z < 0

Each ReLU neuron splits its input space into two halves: an active regime (z > 0) where gradients flow unchanged, and an inactive regime (z ≤ 0) where space is collapsed onto the boundary z = 0. Stacking K ReLU neurons across L layers partitions the input domain into up to O( (K/n)^(n(L-1)) K^n ) distinct linear regions (Montúfar et al., 2014), producing an exponential number of affine facets that wrap around complex target distributions.

Real-World Usage

ReLU and its smooth generalizations (GELU, SwiGLU) are standard across modern deep architectures, from ResNets in computer vision to LLaMA and Mistral in large language models. SwiGLU (x · sigmoid(β x) ⊗ Wx) combines gating with continuous curvature to avoid 'dying neuron' states.

History & Origin Story

Before 2010, sigmoid and hyperbolic tangent (\tanh) functions dominated neural networks, but suffered catastrophic vanishing gradients when saturated. Alex Krizhevsky, Vinod Nair, and Geoffrey Hinton (2010, 2012) demonstrated that the dead-simple piecewise linear ReLU enabled training much deeper architectures without vanishing gradients, fueling the deep learning revolution.

How to Memorize & Golden Words
  • Golden Axiom: "Without non-linearities, a thousand layers collapse to one; with ReLU, space folds like origami."
  • Derivative rule: ReLU'(z) = 1 if positive, 0 if negative.
  • Positive activates the gradient highway; negative gates it shut.
Picture 3 of 5 · tap to inspect in full resolution
03

Why does scaling random Gaussian weights by 0.01 prevent early activation explosion and sigmoid/tanh saturation?

INTUITION

Imagine tuning an acoustic guitar before a concert. If you tighten the tuning pegs with a power drill (massive weights of 10.0), the strings snap instantly or sound like a screeching drill (neuron saturation). If you leave the strings completely loose and floppy with zero tension (weights = 0), plucking them produces no sound at all (zero gradient flow). Scaling random weights by 0.01 sets the perfect gentle tension: the guitar strings are ready to vibrate, and the neural network is primed to learn on the very first note.

  • Learning goalCalculate the variance of pre-activation distributions under scaled random Gaussian initializations and prevent activation saturation.
  • Helpful foundationsVariance of independent products · Understanding the Difficulty of Training Deep Feedforward Neural Networks (Glorot & Bengio, 2010)
  • Common trapInitializing all weights to exact zero; if all weights are zero, every neuron in a hidden layer computes the identical output and receives the identical gradient, destroying symmetry.
  • Next connectionWhen normalizing probabilities across batches in NumPy, omitting keepdims=True causes silent broadcasting catastrophes. We examine the keepdims bug.
✦ More context & mechanics
Conceptual Mechanics & Logic

Consider a neuron receiving n_(inputs) activations with weight vector w:

z = ∑_(i=1)^n_(inputs) wᵢ xᵢ + b

If wᵢ ~ N(0, 1) without scaling, the variance of the pre-activation sum is:

Var(z) = ∑_(i=1)^n_(inputs) Var(wᵢ) Var(xᵢ) = n_(inputs) × 1 × 1 = n_(inputs)

For n_(inputs) = 512, the standard deviation is σ_z = √(512) ≈ 22.6.

Pre-activations swing between -45 and +45:

  • For Sigmoid: σ(45) = 1.0, derivative σ'(45) = 0.00000 (dead gradient!).
  • For ReLU: activations explode to +45, cascading through layers into `NaN` overflow.

Multiplying by scalar scale factor s = 0.01:

Var(z) = s² · n_(inputs) = 0.0001 × 512 = 0.0512 ⟹ σ_z ≈ 0.226

Pre-activations sit tightly clustered around zero in the linear active regime of activations, preserving gradient flow.

Real-World Usage

While 0.01 is the canonical pedagogical standard, modern deep networks use Glorot/Xavier (s = √(2 / (n_(in) + n_(out)))) or He/Kaiming (s = √(2 / n_(in))) initialization.

History & Origin Story

Xavier Glorot and Yoshua Bengio formalized variance scaling in 2010 ('Understanding the difficulty of training deep feedforward neural networks'), curing early saturation.

How to Memorize & Golden Words
  • Large weights saturate neurons; zero weights break symmetry.
  • 0.01 keeps pre-activations in the sweet spot near zero.
Picture 4 of 5 · tap to inspect in full resolution
04

What is the mathematical foundation and geometric intuition of Parameter Storage Duality: Pure Math vs. Code?

INTUITION

Understand Parameter Storage Duality: Pure Math vs. Code visually: Resolving the perpetual confusion: when and why parameter matrices are transposed.. Every transformation preserves core structural invariants while mapping coordinate spaces.

  • Learning goalMaster the algebraic and geometric derivation of Parameter Storage Duality: Pure Math vs. Code.
  • Helpful foundationsLinear Algebra Fundamentals · Matrix Transformations · Vector Spaces
  • Common trapAssuming Parameter Storage Duality: Pure Math vs. Code is merely a computational trick rather than an invariant spatial law.
  • Next connectionConnects to upstream spectral theory and downstream tensor operations.
✦ More context & mechanics
Conceptual Mechanics & Mathematical Rigor

An educational code-to-math rosetta stone diagram on clean ivory linen (#f7f6ee) with a thin graphite frame (#d1d5db).

Top section: Title in technical grotesque: "Parameter Storage Duality: Pure Math vs. Code". Subtitle: "Resolving the perpetual confusion: when and why parameter matrices are transposed."

Middle section: Three structured horizontal comparison blocks:

  1. Pure Textbook Linear Algebra: Vectors are column vectors x ∈ R^(D x 1). Weight matrix W ∈ R^(M x D). Output: z = W x + b.
  2. Pure NumPy Implementation: Data is batched row-major X ∈ R^(B x D). Weights pre-stored transposed: W_(numpy) ∈ R^(D x M). Forward pass: Z = np.dot(X, W) + b.
  3. PyTorch nn.Linear: Weights stored as (out_features, in_features) = (M, D). Forward pass executes: F.linear(X, weight, bias) = X @ weight.T + bias.

Bottom section: Summary Rule: "Always match inner contraction dimensions: (B, D) × (D, M) = (B, M); whether transposition happens at init or runtime is purely a memory stride optimization."

Spacious typography, clean code tags, generous margins.

Practical AI & Systems Usage

This principle is foundational across deep learning optimization, high-dimensional representation, and modern LLM architectures.

Golden Axiom

"Parameter Storage Duality: Pure Math vs. Code: Invariance and structure determine stability under spatial and numerical transformations."

Picture 5 of 5 · tap to inspect in full resolution
05

How does Parameter Storage Duality: Pure Math vs. Implementation Code operate mathematically at scale?

INTUITION

Side-by-side comparative table:

  • Learning goalMaster the algebraic and geometric derivation of Parameter Storage Duality: Pure Math vs. Implementation Code.
  • Helpful foundationsFoundations of Neural Networks From Scratch · Coordinate Invariance & Geometric Projections · Goodfellow, Bengio, and Courville (2016), Deep Learning, MIT Press
  • Common trapAssuming Parameter Storage Duality: Pure Math vs. Implementation Code is an arbitrary computational trick rather than an invariant spatial law.
  • Next connectionConnects upstream foundational lemmas to modern high-dimensional computational systems.
✦ More context & mechanics
Conceptual Mechanics & Mathematical Rigor

A notation duality comparison card in square 1:1 format on warm cream parchment (#fcf0db) with a sepia frame.

Top section: Title in navy serif: "Parameter Storage Duality: Pure Math vs. Code". Subtitle: "Resolving the perpetual confusion between theoretical row vectors and PyTorch weight shapes."

Middle section: Side-by-side comparative table:

Left Column (Pure Mathematics / Textbook):

  • Vector Convention: Column vectors x ∈ R^d_(in) × 1.
  • Forward Pass: y = W x + b.
  • Matrix Shape: W ∈ R^d_(out) × d_(in).
  • Row i of W contains all input weights leading into neuron i.

Right Column (PyTorch / Production Code):

  • Batch Convention: Row inputs X ∈ R^B × d_(in).
  • Forward Pass: Y = X W^T + b or Y = X W_(code).
  • Implementation: In PyTorch `nn.Linear(in_features, out_features)`, parameter tensor `weight` is stored as shape (out_features, in_features) so that `X @ W.T` executes optimal BLAS GEMM.

Bottom section: Developer golden rule: "Always check tensor shapes before debugging gradients: (out_features, in_features) in memory; (in_features, out_features) in diagram drawings."

Clean side-by-side alignment, contrasting math serif vs monospace code, balanced square frame.

Invariance & Structural Proof

Every transformation preserves structural invariants while mapping coordinate spaces. When operating in high dimensions, numerical precision and computational efficiency require adhering strictly to canonical mathematical laws.

Canonical Literature Reference

Formal derivation and peer-reviewed analysis:

Goodfellow, Bengio, and Courville (2016), Deep Learning, MIT Press

Golden Axiom

"Parameter Storage Duality: Pure Math vs. Implementation Code: Invariance, symmetry, and structure govern mathematical truth across continuous and discrete domains."