Welcome to your first lesson. This course is designed to rebuild your foundational knowledge of mathematics through the lens of modern deep learning. We will begin our journey with linear algebra, not as a collection of abstract rules, but as the geometric language that describes the core operations within neural networks.
Today's lesson focuses on the most fundamental of these operations: matrix multiplication. We will move beyond the rote computational algorithm to interpret it in two powerful ways. First, we will see it as the composition of linear maps, which is essential for understanding how data is transformed as it flows through the layers of a network. Second, we'll view it as a sum of outer products, a perspective that unlocks insights into modern techniques like network fine-tuning with LoRA.
Matrix Multiplication as Composition of Linear Maps
At its heart, a matrix is a way to represent a linear transformation—a function that takes a vector as input and produces a vector as output, all while keeping the grid lines of the space parallel and evenly spaced. Multiplying a vector by a matrix is equivalent to applying that transformation to the vector.
When we have a sequence of such transformations, like in a multi-layer perceptron (MLP), we apply one after another. The combined effect of this sequence is itself a single, composite linear transformation. The matrix representing this composite transformation is precisely the product of the individual matrices.
To build a strong visual intuition for this, the following video from the "Essence of linear algebra" series by 3Blue1Brown is an excellent starting point.
Matrix multiplication as composition | Chapter 4, Essence of linear algebra
This video provides a superb geometric interpretation of matrix multiplication. Pay close attention to how applying one transformation after another corresponds to multiplying their matrices.
Please watch the following segments: A quick recap on how a matrix represents a linear transformation by encoding where the basis vectors land. The core idea of this section: viewing the product of two matrices as the composition of two successive transformations. The right-to-left convention, which is a crucial detail stemming from standard function notation. The numerical computation of the product matrix, derived directly from tracking the basis vectors through the two transformations. Finally, a beautiful geometric proof of the associativity of matrix multiplication, (AB)C = A(BC). This exemplifies the power of geometric intuition over rote algebraic manipulation.
As the video demonstrates, if we have a transformation represented by matrix and a transformation represented by , applying and then to a vector is computed as . Because matrix multiplication is associative, this is equivalent to . The product is a single matrix that captures the entire composite transformation.
This is exactly what happens in a neural network. A sequence of layers, each with its own weight matrix, composes a series of transformations. For a simple two-layer linear network, the output is a function of the input :
The product of the weight matrices defines the single, equivalent linear map from the input space directly to the output space.
The following StatQuest video provides a concrete, practical walkthrough of these matrix operations within a simple neural network, connecting the math directly to the structure of nn.Linear in PyTorch.
Essential Matrix Algebra for Neural Networks, Clearly Explained!!!
This video demonstrates how the forward pass of a simple neural network is a sequence of matrix multiplications and additions.
Focus on the segment from how this applies to a neural network. It shows how the inputs are transformed by a weight matrix and bias vector, which corresponds to an affine transformation (a linear map followed by a translation). The nn.Linear class in PyTorch encapsulates precisely this operation.
Visualizing Compositions in Neural Networks
This compositional view gives us a powerful geometric handle on network architecture. For example, a standard feed-forward network (FFN) block in a Transformer often expands the dimension of the data, applies a nonlinearity, and then projects it back down. This can be seen as a sequence of matrix multiplications, e.g., . The shapes of these matrices determine whether information is being expanded into a higher-dimensional space or compressed through a bottleneck.
The PyTorch blog post "Inside the Matrix" offers a unique 3D visualization for these compositions.
Inside the Matrix: Visualizing Matrix Multiplication, Attention and Beyond – PyTorch
This article introduces a novel way to visualize matrix expressions as 3D objects, making the relationships between dimensions intuitive. We'll look at how it depicts a chain of matrix multiplications, typical of an FFN.
In the article, find section 3a Left-associative expressions. Read the paragraphs discussing the FFN shape, where the hidden dimension is wider, and the bottleneck shape, where the hidden dimension is narrower. Observe how the geometric "shape" of the computation reflects the expansion or compression of the data representation.
Matrix Multiplication as a Sum of Outer Products
A second, equally important interpretation of matrix multiplication is as a sum of outer products. The outer product of a column vector and a row vector is the matrix , whose entries are . This results in an matrix. A key property is that this matrix always has a rank of 1.

The product of two matrices can be expressed as a sum of outer products. If we let be the -th column of and be the -th row of , then:
where is the common dimension (number of columns in and rows in ). Each term in the sum is a rank-1 matrix, and we are adding them up to form the final matrix .
This perspective is crucial for understanding low-rank approximations. If we can approximate a large matrix with the product of two "thin" matrices, and , where , we are essentially saying that can be well-approximated by a short sum of outer products. This is the central idea behind Low-Rank Adaptation (LoRA), a parameter-efficient fine-tuning technique for large language models.
LoRA freezes the massive pre-trained weights of a model and learns only the low-rank factors of the change in weights. This dramatically reduces the number of trainable parameters.
Inside the Matrix: Visualizing Matrix Multiplication, Attention and Beyond – PyTorch
This same article provides a great visualization for the LoRA concept.
Please navigate to Section 7 LoRA. Read the subsection 7a The basic idea. Notice how replacing a single large weight matrix with a product of two smaller ones corresponds directly to the outer product viewpoint we just discussed. The visualization of the rank-4 factorization clearly shows the structured, low-rank nature of the resulting matrix.
Unifying the Views
These two viewpoints—composition of maps and sum of outer products—are simply different ways of decomposing the same underlying computation. The conventional "dot product" algorithm, where you compute each element of the result matrix by taking the dot product of the -th row of and the -th column of , is a third way.
The "Inside the Matrix" article proposes a unified geometric picture that holds all these views.
Inside the Matrix: Visualizing Matrix Multiplication, Attention and Beyond – PyTorch
Let's conclude by looking at the core visualization primitive from the article, which provides a mental model to unify these different interpretations.
Read Section 1 Pitch. Focus on the central idea that matrix multiplication makes geometric sense when viewed as a 3D cube. The three dimensions of this cube correspond to the three indices involved in the operation (i, j, and the shared/summation index k). The different ways of "slicing" this cube correspond to different interpretations of the multiplication.
Conclusion
In this lesson, we established a geometric foundation for understanding matrix multiplication, the cornerstone of deep learning computations.
Key Takeaways:
- Composition of Linear Maps: Multiplying matrices is equivalent to applying transformation followed by . This helps us reason about the flow of information through sequential layers in a neural network.
- Sum of Outer Products: A matrix product can be seen as . This view is critical for understanding low-rank structures and parameter-efficient techniques like LoRA.
- A Unified View: These different interpretations are just different ways to parse the same fundamental operation, which can be visualized as a 3D computation involving the matrix dimensions.
Your familiarity with the PyTorch stack and mathematical background will allow you to fluidly switch between these interpretations depending on the context—from analyzing the architecture of a network to implementing efficient training strategies.
In the next lesson, we will build directly on this geometric foundation. We will use the concepts of vector subspaces, span, basis, and dimension to more formally describe the "spaces" that weight matrices create and where activations live. This will give us the tools to analyze information flow, bottlenecks, and the expressive capacity of neural network layers.