Subsection 1.4 Matrices and Neural Networks
The operation of this neural network can be understood as a series of matrix multiplications. The weights of the model consist of two matrices: one for the input to hidden layer connections and one for the hidden to output layer connections. Each of those is a \(w \times
h\) matrix where \(w\) is the number of words in the vocabulary and \(h\) is the number of dimensions in the embedding space.
Here is our input weight matrix from above:
We would also have an output weight matrix with the dimensions flipped: one row for each dimension in the embedding space and one column for each word in the vocabulary. It would store the weights that lead from each of the hidden nodes to each word in the output layer. For our example, it would be a \(3 \times 17\) matrix.
To activate a particular word, we take a \(1 \times w\) vector with a 1 in the position of the word we want to activate and 0s in all other positions. For example, if we want to activate the word “dog”, we would use a vector like this:
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Multiplying this \(1 \times 17\) matrix by our \(17 \times 3\) matrix would give us a \(1
\times 3\) matrix representing the embedding for “dog”:
w(4,1) w(4,2) w(4,3)
Taking that \(1 \times 3\) and multiplying it by the \(3 \times 17\) output weight matrix would give us a \(1 \times 17\) matrix representing the degree to which “dog” is associated with each word in the vocabulary.
Thus the entire neural network can be implemented as a series of matrix math operations.
Computer graphics also relies heavily on manipulating large matrices of numbers. Because of this, computer graphics cards have special purpose hardware for performing these operations efficiently. Machine learning researchers realized that they could use this hardware, originally designed for computer graphics, to rapidly do the calculations needed for training and using neural networks. It is no coincidence that the dominant manufacturer of hardware for machine learning is NVIDIA, one of the leading companies in computer graphics.