Theory ofIntelligence
Index
Deep Learning & LLM FoundationsBook Index: Letter S

The Structure of a Neural Network: From Neuron to Network

A ground-up conceptual guide to artificial neurons, weights, biases, activations, matrix layer propagation, and the architecture of modern LLMs.

functionsMathematical Representation
y=f(∑i=1nwixi+b)andZ=XW+by = f\left(\sum_{i=1}^{n} w_i x_i + b\right) \quad \text{and} \quad \mathbf{Z} = \mathbf{X}\mathbf{W} + \mathbf{b}

Before studying how modern Large Language Models (such as GPT-4, Claude, or LLaMA) generate human-like prose, solve code, or reason through complex problems, it is crucial to step back and develop a crystal-clear mental model of the atomic machinery beneath them.

Every modern deep learning system — whether it is classifying medical scans, driving autonomous vehicles, or powering a trillion-parameter Transformer — is built from one foundational abstraction: the artificial neuron.

We will build this understanding progressively:

  1. Understanding the single artificial neuron from first principles.
  2. Observing how inputs, weights, summation, bias, and activations combine.
  3. Connecting multiple neurons into layers via matrix multiplication.
  4. Understanding deep networks as functional compositions.
  5. Discovering where traditional neurons live inside modern Generative Pre-trained Transformers (GPT).

1. What is an Artificial Neuron?

An artificial neuron is a fundamental computational unit that receives numerical inputs, performs a parameterized linear combination, applies an activation function, and broadcasts an output.

Think of it as a specialized mathematical function:

Anatomy of an Artificial Neuron

Every artificial neuron consists of five structural elements:

  1. Inputs (xix_i): Numerical signals entering the neuron.
  2. Weights (wiw_i): Scalers that dictate the relative importance and sign of each input.
  3. Summation (Σ\Sigma): The linear combination of all weighted inputs.
  4. Bias (bb): An independent threshold offset parameter.
  5. Activation Function (ff): A non-linear transformation shaping the final output.

Mathematically, the entire neuron is expressed in a single elegant equation:

y=f(∑i=1nwixi+b)y = f\left(\sum_{i=1}^{n} w_i x_i + b\right)

2. A Concrete Numerical Walkthrough

To make this completely tangible, let us trace an exact calculation through a single artificial neuron.

Step 1: The Inputs (xx)

Suppose our neuron receives three numerical inputs:

x1=2,x2=4,x3=3x_1 = 2, \quad x_2 = 4, \quad x_3 = 3

These are simply raw numbers. To the neuron, numbers have no intrinsic meaning — they could be pixels in an image, acoustic frequencies in an audio clip, or token embedding values inside an LLM.

Step 2: The Weights (ww)

Every input channel has an assigned weight:

w1=0.5,w2=0.2,w3=0.8w_1 = 0.5, \quad w_2 = 0.2, \quad w_3 = 0.8

The neuron multiplies each input by its corresponding weight:

x1w1=2×0.5=1.0x_1 w_1 = 2 \times 0.5 = 1.0 x2w2=4×0.2=0.8x_2 w_2 = 4 \times 0.2 = 0.8 x3w3=3×0.8=2.4x_3 w_3 = 3 \times 0.8 = 2.4
lightbulb

[!NOTE] Why Multiply?
Multiplication acts as an importance dial (attenuation or amplification). A large positive weight amplifies an input's contribution; a weight near zero silences it; a negative weight acts as an inhibitory signal, penalizing the neuron's activation. Crucially, weights are not programmed by humans — they are learned automatically through backpropagation and gradient descent during training.

Step 3: Summation (Σ\Sigma)

Next, the neuron aggregates all weighted inputs into a single combined sum:

Weighted Sum=x1w1+x2w2+x3w3=1.0+0.8+2.4=4.2\text{Weighted Sum} = x_1 w_1 + x_2 w_2 + x_3 w_3 = 1.0 + 0.8 + 2.4 = 4.2

Step 4: Adding the Bias (bb)

Now, we introduce an additional parameter: the bias. Let:

b=0.5b = 0.5

The neuron adds the bias to the weighted sum to produce the pre-activation value zz:

z=∑i=13wixi+b=4.2+0.5=4.7z = \sum_{i=1}^3 w_i x_i + b = 4.2 + 0.5 = 4.7
lightbulb

[!IMPORTANT] Why Do We Need Bias?
Without a bias term (b=0b = 0), if all inputs are zero (x1=x2=x3=0x_1 = x_2 = x_3 = 0), the weighted sum is permanently trapped at 00 regardless of what the weights are. The bias gives the neuron an independent parameter to shift its activation boundary up or down, allowing it to activate even with zero or low inputs, or stay silent despite moderate inputs. Geometrically, in the equation of a line y=mx+cy = mx + c, bias is the yy-intercept cc.

Step 5: The Activation Function (f(z)f(z))

Finally, the pre-activation z=4.7z = 4.7 passes through an activation function, such as the Rectified Linear Unit (ReLU):

ReLU⁡(z)=max⁡(0,z)\operatorname{ReLU}(z) = \max(0, z) f(4.7)=max⁡(0,4.7)=4.7f(4.7) = \max(0, 4.7) = 4.7

The final output broadcast by the neuron is 4.74.7.

lightbulb

[!TIP] Deep Dive: The Engine of Non-Linearity
Why can't we simply output z=4.7z = 4.7 directly? Without non-linear activation functions, a network of 1,000 layers collapses mathematically into a single linear regression equation (The Linear Collapse Theorem). For an in-depth mathematical breakdown of ReLU, Sigmoid, Tanh, Softmax, and GELU, see our comprehensive guide on Activation Functions in Neural Networks.


3. Perceptron vs. Modern Artificial Neuron: What's the Difference?

While people often use the terms interchangeably in casual conversation, a perceptron is a specific, early type of artificial neuron, whereas an artificial neuron (or node) is the broader, modern concept used in neural networks today.

lightbulb

[!NOTE] The Golden Rule: Every perceptron is an artificial neuron, but not every artificial neuron is a perceptron.

Key Differences

FeaturePerceptronModern Artificial Neuron (Node)
Activation FunctionStrictly uses a step function (outputs a hard 0 or 1).Uses smooth, non-linear functions like ReLU, Sigmoid, or Tanh.
Output ValuesBinary only (0 or 1, yes or no).Continuous numbers (e.g., 0.870.87, 4.24.2, or −0.15-0.15).
Learning CapabilityCannot be trained with backpropagation because a step function has no useful gradient (slope is 00 everywhere except undefined at 00).Can be trained with backpropagation and gradient descent because its activation functions are smooth and differentiable.
Where It Is UsedStandalone binary classifiers and historical 1950s models.Inside hidden and output layers of modern Artificial Neural Networks (ANNs), Transformers, and LLMs.

Why the Confusion Happens

  • Same Core Math: Both take inputs, multiply them by weights, add a bias, and pass the sum through an activation function: y=f(wTx+b)y = f(\mathbf{w}^T\mathbf{x} + b).
  • Multi-Layer Perceptron (MLP) Naming: Modern neural networks are still frequently called "Multi-Layer Perceptrons," even though the units inside them have evolved past the original step-function perceptron into modern artificial neurons equipped with smooth non-linearities.

4. Interactive Laboratory: Experiment with Neuron Parameters

Use the live laboratory below to interactively adjust w1,w2,w3w_1, w_2, w_3, the bias bb, and switch activation functions to observe how the signal transforms in real time:

Interactive Artificial Neuron StudioLIVE VISUALIZER

Manipulate weights and bias to trace signal propagation: y = f(wᵀx + b)

Live Signal Flow SchematicFeed-Forward Propagation
w₁=+0.50 (→+1.0)w₂=+0.20 (→+0.8)w₃=+0.80 (→+2.4)x₁= 2x₂= 4x₃= 3Bias (b)+0.5∑Σ=4.20z=4.70z = 4.70ACTIVATIONRELUf(4.7)OUTPUT y4.70
Neuron Parameters & Synapse Weights
w₁Weight 1x₁ = 2
Contrib: +1.00+0.50
-2.0 (Inhibitory)w₁ · x₁ = +1.00+2.0 (Excitatory)
w₂Weight 2x₂ = 4
Contrib: +0.80+0.20
-2.0 (Inhibitory)w₂ · x₂ = +0.80+2.0 (Excitatory)
w₃Weight 3x₃ = 3
Contrib: +2.40+0.80
-2.0 (Inhibitory)w₃ · x₃ = +2.40+2.0 (Excitatory)
bNeuron Bias (b)Threshold Offset
+0.50
-5.0 (Inhibitory shift)Threshold Shift = +0.50+5.0 (Excitatory shift)
Non-Linear Activation Function f(z)Select Transfer Curve
Step-by-Step Mathematical CalculationFormula Trace
1. Weighted Evidence Sum (Σ wᵢ · xᵢ)
(2 × 0.50) + (4 × 0.20) + (3 × 0.80)= 4.20
2. Add Bias Offset (z = Σ + b)
4.20 + (+0.50)z = 4.70
3. Non-Linear Activation (y = RELU(z))
RELU(4.70)y = 4.7000
Conceptual Takeaway: The neuron is actively firing with output y = 4.70. In deep neural networks and Transformer FFNs, millions of these units compute simultaneously via matrix multiplication.

5. What is a Neural Network?

A single neuron can only make linear decisions. But when we connect dozens, thousands, or billions of neurons together, we create an Artificial Neural Network (ANN).

Perceptron vs. Artificial Neural Network (ANN)

A perceptron is a single artificial neuron designed for simple binary classification, whereas an Artificial Neural Network (ANN) is a broader network made up of multiple interconnected neurons organized into layers to solve complex problems.

lightbulb

[!TIP] Mental Model: Think of the perceptron as a single building block and an ANN as the entire structure built from those blocks.

Core Differences

FeaturePerceptronArtificial Neural Network (ANN)
ArchitectureConsists of a single layer with one computational node (neuron).Consists of multiple layers (input, one or more hidden layers, and output) with many interconnected neurons.
Problem ComplexityCan only solve linearly separable problems (where data can be split by a single straight line or plane).Can solve complex, non-linear problems (like image recognition, speech processing, and XOR logic).
Activation FunctionsTypically uses a simple step function (threshold) that outputs only binary values (00 or 11).Uses non-linear activation functions like ReLU, Sigmoid, or Tanh to learn intricate patterns.
Training MethodUses the basic Perceptron Learning Rule to adjust weights directly based on prediction errors.Uses gradient descent combined with backpropagation to update weights across all hidden layers.
Output TypeLimited to binary classification (two possible outcomes).Supports binary classification, multi-class classification, and continuous value prediction (regression).

How They Relate

  • Foundation: The single-layer perceptron was the earliest mathematical model of a biological neuron and laid the groundwork for modern neural networks.
  • Scaling Up: When you stack multiple perceptrons together into hidden layers and swap the rigid step function for smooth, non-linear activation functions, you get a Multi-Layer Perceptron (MLP) — which is the standard form of a basic ANN.

In a feedforward network, neurons are organized into distinct layers:

Neural Networks & Deep Learning Architecture

  1. Input Layer: Receives the external raw feature vector (e.g., token IDs, pixel values). It performs no arithmetic; it merely holds the numbers.
  2. Hidden Layers: Intermediate layers where neurons perform parameterized transformations. "Hidden" simply means their outputs are internal to the network and not directly observed as the final target.
  3. Output Layer: The final layer that formats the result into the desired objective — such as a continuous value (regression), a binary decision (classification), or a probability distribution over a vocabulary (next-token prediction in LLMs).

6. How Layers Connect Mathematically: Matrix Multiplication

Computing billions of neurons one by one in loops would be prohibitively slow. Instead, modern computing harnesses linear algebra to evaluate an entire layer of neurons simultaneously using matrix multiplication.

Suppose an input vector with 33 features enters a layer with 22 neurons:

X=[243](1×3 vector)\mathbf{X} = \begin{bmatrix} 2 & 4 & 3 \end{bmatrix} \quad (1 \times 3 \text{ vector})

The weight matrix W\mathbf{W} contains the weights for all connections: each column represents the weights for one specific neuron:

W=[0.50.20.20.40.80.1](3×2 matrix)\mathbf{W} = \begin{bmatrix} 0.5 & 0.2 \\ 0.2 & 0.4 \\ 0.8 & 0.1 \end{bmatrix} \quad (3 \times 2 \text{ matrix})

The forward calculation for the entire layer is:

Z=XW+b\mathbf{Z} = \mathbf{X}\mathbf{W} + \mathbf{b}

Let the bias vector be b=[00]\mathbf{b} = \begin{bmatrix} 0 & 0 \end{bmatrix} for clarity:

Z=[243][0.50.20.20.40.80.1]\mathbf{Z} = \begin{bmatrix} 2 & 4 & 3 \end{bmatrix} \begin{bmatrix} 0.5 & 0.2 \\ 0.2 & 0.4 \\ 0.8 & 0.1 \end{bmatrix}

Calculating the two neuron outputs in parallel:

  • Neuron 1 (Column 1): (2×0.5)+(4×0.2)+(3×0.8)=1.0+0.8+2.4=4.2(2 \times 0.5) + (4 \times 0.2) + (3 \times 0.8) = 1.0 + 0.8 + 2.4 = \mathbf{4.2}
  • Neuron 2 (Column 2): (2×0.2)+(4×0.4)+(3×0.1)=0.4+1.6+0.3=2.3(2 \times 0.2) + (4 \times 0.4) + (3 \times 0.1) = 0.4 + 1.6 + 0.3 = \mathbf{2.3}
Z=[4.22.3]\mathbf{Z} = \begin{bmatrix} 4.2 & 2.3 \end{bmatrix}

In a single matrix operation, the network evaluated both neurons at the exact same moment. This mathematical elegance is why Graphics Processing Units (GPUs) — which contain thousands of tensor cores optimized for matrix multiplications — power the entire deep learning revolution.


7. Shallow vs. Deep: Composition of Functions

  • Shallow Network: A network with only one hidden layer.
  • Deep Neural Network (DNN): A network with multiple (often dozens or hundreds) of stacked hidden layers.

The term Deep Learning literally refers to stacking multiple layers of non-linear transformations.

Mathematically, a neural network is nothing more than a composition of functions:

h1=f1(XW1+b1)\mathbf{h}_1 = f_1(\mathbf{X}\mathbf{W}_1 + \mathbf{b}_1) h2=f2(h1W2+b2)\mathbf{h}_2 = f_2(\mathbf{h}_1\mathbf{W}_2 + \mathbf{b}_2) y=f3(h2W3+b3)=f3(f2(f1(X)))\mathbf{y} = f_3(\mathbf{h}_2\mathbf{W}_3 + \mathbf{b}_3) = f_3\Big(f_2\big(f_1(\mathbf{X})\big)\Big)

Each layer transforms the geometric representation of the data:

  • Early layers detect primitive features (edges in images, simple grammatical patterns in text).
  • Middle layers compose these into structured concepts (textures, semantic phrases).
  • Final layers synthesize high-level reasoning (object identity, next token probability).

8. How Does This Connect to LLMs and GPT?

Now we reach the bridge to modern Large Language Models.

When someone says "GPT is a neural network," what does that actually mean? Is it just a massive collection of the neurons we just studied?

A Transformer (the architecture behind GPT) is indeed a deep neural network, but with a highly specialized modular architecture:

ComponentStructural RoleRelationship to Basic Neurons
Token EmbeddingsConverts discrete words/tokens into continuous numerical vectors.A lookup matrix acting as the initial input layer X\mathbf{X}.
Multi-Head AttentionDynamically allows tokens to communicate across positions in a sentence.Unlike fixed-weight neurons, attention weights are computed dynamically based on token relevance (Queries ×\times Keys).
Feed-Forward Network (FFN / MLP)Processes and transforms the information extracted by attention at each token position.This is literally the exact dense neural network we just studied! Two dense matrix multiplications with a non-linear activation (typically GELU or SwiGLU) in between.
Layer NormalizationStabilizes activations across layers to prevent gradients from exploding or vanishing.Standardizes pre-activation values to zero mean and unit variance.
Output Projection Head (Unembedding)Projects final vector representations back to the vocabulary size (e.g. 50,000 words).A large final linear layer followed by Softmax: Softmax⁡(hWvocab)\operatorname{Softmax}(\mathbf{h} \mathbf{W}_{\text{vocab}}).

Transformer Block and Feed-Forward Neural Network

lightbulb

[!TIP] The Key Takeaway for LLMs:
In GPT-3 (175 billion parameters), approximately two-thirds of all parameters reside inside the Feed-Forward Networks (FFNs) — which are pure dense layers composed of the matrix multiplications, weights, and biases we explored above. Attention determines where to look; the dense neurons store and recall the factual knowledge and patterns.


9. Test Your Conceptual Mastery

schoolQuestion 1: What happens if you remove the activation function f(z) from every layer in a deep network?
expand_more

Answer: If all activation functions are removed, every layer becomes a purely linear transformation: Z=XW+b\mathbf{Z} = \mathbf{X}\mathbf{W} + \mathbf{b}. Because the composition of linear functions is always linear: W2(W1X+b1)+b2=(W2W1)X+(W2b1+b2)=WeffectiveX+beffective\mathbf{W}_2(\mathbf{W}_1 \mathbf{X} + \mathbf{b}_1) + \mathbf{b}_2 = (\mathbf{W}_2 \mathbf{W}_1)\mathbf{X} + (\mathbf{W}_2 \mathbf{b}_1 + \mathbf{b}_2) = \mathbf{W}_{\text{effective}}\mathbf{X} + \mathbf{b}_{\text{effective}} A 100-layer deep network without non-linear activations collapses mathematically into a single linear layer, completely incapable of learning non-linear patterns, decision boundaries, or language modeling.

schoolQuestion 2: Why can't a single neuron with b = 0 model a threshold when all inputs are 0?
expand_more

Answer: When inputs x1=x2=⋯=xn=0x_1 = x_2 = \dots = x_n = 0, the weighted sum ∑wixi=0\sum w_i x_i = 0 regardless of what numerical values the weights hold. If bias b=0b = 0, the pre-activation zz is unconditionally forced to be 00. A bias term is mathematically required to shift the hyper-plane away from the origin, allowing the neuron to output non-zero values even when input features are inactive.

schoolQuestion 3: How does matrix multiplication compute multiple neurons simultaneously?
expand_more

Answer: In the matrix formulation Z=XW+b\mathbf{Z} = \mathbf{X}\mathbf{W} + \mathbf{b}:

  • The input X\mathbf{X} has dimensions B×NinB \times N_{\text{in}} (where BB is batch size and NinN_{\text{in}} is input dimension).
  • The weight matrix W\mathbf{W} has dimensions Nin×NoutN_{\text{in}} \times N_{\text{out}}. Each column jj of W\mathbf{W} contains the incoming weights for neuron jj.
  • Taking the dot product of the input row with column jj computes the weighted sum for neuron jj. Thus, all NoutN_{\text{out}} neurons are computed across the entire batch in one hardware-accelerated matrix multiplication.
schoolQuestion 4: Where do dense neurons appear inside a modern Transformer like GPT?
expand_more

Answer: Inside every single Transformer block, there is a dedicated Feed-Forward Network (FFN) sublayer directly following the Attention sublayer. The FFN consists of a linear projection that expands the token dimension (usually by 4×4\times, e.g., 4096→163844096 \to 16384), passes it through a non-linear activation (GELU or SwiGLU), and projects it back (16384→409616384 \to 4096). This MLP block accounts for roughly 66%66\% of the parameters in a decoder-only LLM.


To continue your journey from fundamental neurons to modern AI architectures:

  1. Deep Learning: Neural Networks Track — Study perceptron learning rules, backpropagation gradients, and universal approximation.
  2. Generative AI: LLM Foundations — Trace how dense layers combine with Multi-Head Attention to build language models.
  3. Build an LLM from Scratch — Implement the Transformer architecture, multi-head attention, and feed-forward layers line-by-line in PyTorch.