Path: blob/master/2 - Natural Language Processing with Probabilistic Models/Week 4/C2W4_L4_Word Embeddings.ipynb
65 views
Word Embeddings: Hands On
In previous lecture notebooks you saw all the steps needed to train the CBOW model. This notebook will walk you through how to extract the word embedding vectors from a model.
Let's dive into it!
Before moving on, you will be provided with some variables needed for further procedures, which should be familiar by now. Also a trained CBOW model will be simulated, the corresponding weights and biases are provided:
Extracting word embedding vectors
Once you have finished training the neural network, you have three options to get word embedding vectors for the words of your vocabulary, based on the weight matrices and/or .
Option 1: extract embedding vectors from
The first option is to take the columns of as the embedding vectors of the words of the vocabulary, using the same order of the words as for the input and output vectors.
Note: in this practice notebooks the values of the word embedding vectors are meaningless after a single iteration with just one training example, but here's how you would proceed after the training process is complete.
For example is this matrix:
The first column, which is a 3-element vector, is the embedding vector of the first word of your vocabulary. The second column is the word embedding vector for the second word, and so on.
The first, second, etc. words are ordered as follows.
So the word embedding vectors corresponding to each word are:
Option 2: extract embedding vectors from
The second option is to take transposed, and take its columns as the word embedding vectors just like you did for .
Option 3: extract embedding vectors from and
The third option, which is the one you will use in this week's assignment, uses the average of and .
Calculate the average of and , and store the result in W3.
Expected output:
Extracting the word embedding vectors works just like the two previous options, by taking the columns of the matrix you've just created.
Now you know 3 different options to get the word embedding vectors from a model!
How this practice relates to and differs from the upcoming graded assignment
After extracting the word embedding vectors, you will use principal component analysis (PCA) to visualize the vectors, which will enable you to perform an intrinsic evaluation of the quality of the vectors, as explained in the lecture.
Congratulations on finishing all lecture notebooks for this week!
You're now ready to take on this week's assignment!
Keep it up!