Multilayer Perceptrons › Network Architecture and Notation
Language AI HandbookAll chapters Multilayer Perceptrons › Network Architecture and NotationOne section · Sections in this chapter3 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
An MLP consists of an input layer, one or more hidden layers, and an output layer. We describe the architecture by the number of units in each layer. For example, a network with 4 inputs, two hidden layers of 8 and 4 units, and 2 outputs would be written as 4-8-4-2.
Let's establish notation that will serve us throughout this chapter and beyond:
- : total number of layers (excluding input)
- : number of neurons in layer
- : weight matrix for layer , with shape
- : bias vector for layer , with shape
- : pre-activation values at layer
- : activations (post-activation values) at layer
- : the input treated as the activation of layer 0
The weight matrix connects layer to layer . Each row of contains the weights for one neuron in layer . The element represents the weight connecting neuron in layer to neuron in layer .
# Define a simple 3-layer MLP: 2 inputs -> 4 hidden -> 3 hidden -> 1 output
layer_sizes = [2, 4, 3, 1]
# Initialize weight matrices and bias vectors
np.random.seed(42)
weights = []
biases = []
for l in range(1, len(layer_sizes)):
W = np.random.randn(layer_sizes[l], layer_sizes[l - 1]) * 0.5
b = np.zeros((layer_sizes[l], 1))
weights.append(W)
biases.append(b)Network architecture: 2 -> 4 -> 3 -> 1 Weight matrix shapes: W[1]: (4, 2) (connects 2 neurons to 4 neurons) W[2]: (3, 4) (connects 4 neurons to 3 neurons) W[3]: (1, 3) (connects 3 neurons to 1 neurons) Bias vector shapes: b[1]: (4, 1) b[2]: (3, 1) b[3]: (1, 1) Total parameters: 31 (23 weights + 8 biases)
This 3-layer network has a modest parameter count, but the numbers grow quickly. A layer with 512 input neurons and 256 output neurons needs weights alone. Let's visualize what these weight matrices look like:



The weight matrices grow with the product of consecutive layer sizes. This rapid growth in parameters is why network architecture design requires careful consideration.