Stanford CS229 Machine Learning | Spring 2026 | Lecture 7: Neural Networks 1 (Architecture)

The lecture introduces neural network architectures, covering key concepts such as nonlinear models, ReLU activations, multilayer structures, residual connections, and normalization techniques like layer norm, highlighting their roles in improving learning and optimization. It also briefly discusses convolutional neural networks and sets the stage for future exploration of advanced models like transformers.

The lecture begins with an introduction to deep learning, focusing on supervised learning and nonlinear models. The instructor revisits the concept of linear models, emphasizing the extension to nonlinear models where the relationship between parameters and inputs is nonlinear. Unlike simple nonlinear transformations of inputs, such as squaring features, the lecture highlights the importance of nonlinearities in parameters, which cannot be reduced to linear models through input transformations. The framework for supervised learning is reviewed, including the definition of loss functions for regression and classification tasks, with particular attention to the cross-entropy loss used in multiclass classification. The instructor explains the probabilistic interpretation of these losses and the rationale behind using stochastic gradient descent (SGD) for optimization, noting its efficiency and noise characteristics compared to full gradient descent.

The discussion then moves to the architecture of neural networks, starting with the introduction of the Rectified Linear Unit (ReLU) activation function, a fundamental nonlinear component that outputs zero for negative inputs and a linear response for positive inputs. This activation function is motivated by biological neurons’ firing behavior and has become a standard in deep learning due to its computational advantages over earlier sigmoid functions. The lecture progresses to building neural networks with multiple layers, where each layer applies a linear transformation followed by a nonlinear activation. The concept of neurons and layers is formalized using matrix and vector notation, explaining how inputs are transformed through weight matrices and biases to produce outputs. The instructor also discusses the dimensionality considerations when stacking layers and the typical practice of reducing dimensionality in intermediate layers.

Further, the lecture introduces residual networks, a significant architectural innovation that adds shortcut connections allowing the input to bypass certain layers and be added directly to the output of those layers. This design helps model residuals or differences rather than the entire transformation, which can simplify learning and improve optimization. The rationale behind residual connections is explained through the idea that when intermediate representations are close to the target outputs, modeling the residual error is easier. The instructor notes that residual networks have been empirically successful and discusses some theoretical perspectives on why they facilitate better optimization, though a definitive explanation remains elusive.

Normalization techniques, specifically layer normalization, are also covered. Layer norm standardizes the inputs to a layer by subtracting the mean and dividing by the standard deviation, followed by learnable scaling and shifting parameters. This normalization helps stabilize training by maintaining consistent scaling of activations, preventing issues like exploding values during forward passes. The lecture contrasts layer norm with a simplified variant called RMS norm, which omits mean subtraction but retains scaling. The benefits of normalization include improved training stability and easier parameter initialization, though it introduces complexities in gradient behavior during optimization.

Finally, the lecture briefly touches on convolutional neural networks (CNNs), explaining that convolutions can be viewed as structured matrix multiplications with sparse, shared parameters called filters. These filters slide over input data to capture local patterns, making CNNs particularly effective for image processing tasks. However, the instructor notes that CNNs are less dominant in current architectures compared to transformers, especially in vision and language applications. The lecture concludes by emphasizing that the foundational concepts covered provide a basis for understanding more advanced models like transformers, which will be discussed in future lectures.