4 Multilayer Perceptrons
In this chapter, we introduce your first deep neural networks. In Chapter 3, softmax regression assigned a fixed weight to each of the 784 pixels of a Fashion-MNIST garment image and summed the evidence, so every pixel cast the same vote toward a class regardless of what surrounded it. Yet a bright pixel might belong to a sleeve, a handbag strap, or a collar, and only its neighbors can tell which. Even on four binary points, no single linear layer can compute the exclusive-OR (XOR) of two bits, the limitation Marvin Minsky and Seymour Papert highlighted in 1969 for Frank Rosenblatt’s single-layer perceptron.
Multilayer perceptrons (MLPs) overcome this linear barrier by stacking one or more fully connected hidden layers—each pairing an affine transformation with a nonlinear activation function—before the output layer, and training all layers jointly via backpropagation (Rumelhart et al. 1986). We begin by showing why linear models fail on feature interactions like XOR, how hidden layers fold input space into exponentially many linear regions with depth, and how common activation functions (ReLU, GELU, sigmoid, and \(\tanh\)) behave under differentiation (Section 4.1). Implementing a 256-unit ReLU MLP from scratch and concisely on Fashion-MNIST (Section 4.2) eliminates roughly a fifth of softmax regression’s classification errors (\(\sim 87\%\) vs. \(\sim 84\%\) accuracy) at nearly the same GPU epoch time, replacing blurred whole-garment templates with localized contrast detectors.
Adding hidden layers also raises three foundational questions of deep learning that occupy the rest of the chapter. First, Section 4.3 derives the three matrix-calculus rules of reverse-mode differentiation through an MLP, checks them against automatic differentiation to machine precision, and accounts for training’s activation-memory and FLOP budgets. Second, Section 4.4 tracks signal and gradient variance across \(K\) layers, derives Xavier and He initialization to prevent vanishing and exploding gradients in a 10-layer MLP, and shows why random weights are needed to break hidden-unit symmetry. Third, Section 4.5 and Section 4.6 examine why heavily overparameterized networks generalize—covering random-label memorization, double descent, the implicit bias of gradient descent, early stopping, and multiplicative noise regularization via dropout—before Section 4.7 puts the full toolkit to work on Kaggle’s Ames Housing regression benchmark.