Linear Layer
- A linear layer gives linear transformation on its inputs.
- A linear transformation is a function which maps \(\mathbb{R}^n \rightarrow \mathbb{R}^m\).
- This is a linear transformation because the left-side matrix transforms $[x, y, z]^T \in \mathbb{R}^3$ to $\mathbb{R}^2$ .
- All matrix multiplications are linear transformations.
- A linear layer in neural networks does the same thing and then adds a bias vector to the resultant vector.
- Equation (1) is how mathematicians write it, treating vectors as column vectors by default. In neural networks, we also need to consider batches of samples.
- So, $x$ is not a simple column vector, rather a matrix of row vector. Each row is a sample. Hence, $x \in \mathbb{R}^{B \times Dx}$ , where $B$ is the batch size and $Dx$ is the dimension of each input sample.
- The shape of matrix $W \in \mathbb{R}^{Dy \times Dx}$ is determined by the required output dimension and the input dimension.
- The equation then becomes,
Enjoy Reading This Article?
Here are some more articles you might like to read next: