Day 25 of 100DaysofML

Charan Soneji
100DaysofMLcode
Published in
4 min readJul 11, 2020

GloVe. Essentially its a continuation of yesterday’s blog where I mentioned about word embeddings. I’m going to start by mentioning that GloVe is a type of word embedding but the application is slightly different from the word2vec model which I had mentioned about in my last blog.

I will start by mentioning the formal definition of GloVe which you would usually get on the internet and simplify it.

GloVe, coined from Global Vectors, is a model for distributed word representation. The model is an unsupervised learning algorithm for obtaining vector representations for words. This is achieved by mapping words into a meaningful space where the distance between words is related to semantic similarity.

The full form of GloVe is given as Global Vector Embeddings. I will start by explanation of the difference between word2vec model and GloVe. So the entire difference mainly lies in the scope of the vector. word2vec model only takes into consideration the local scope of the dataset whereas on the other hand, GloVe takes into consideration the global property of the dataset.

How does it work?
So for the implementation of GloVe, we make sure to use a count matrix which would take into consideration of counts of all the words in your corpus.
I shall explain the concept with an example. Let us take 2 sentences for this instance.

Sentence 1: I love NLP.
Sentence 2: I love to make videos.
Now, from these sentences, we try to build the count matrix whereby we notice the patterns in the sentences. “I love” occurs twice but “love NLP” occurs only once. In a similar pattern, we need to complete all the adjacent word relations and create the matrix shown below:

Count matrix for the following scenario

For the following matrix, we can generalize the values as X(ij) where j appears in the context of i. For instance, X(I love) =2 (because I love occurs twice in the corpus. We have to calculate the overall probability value for each of the given terms so we can generalize this formula as:

Here, we may see that we divide the X(ij) with X(i) which is the total occurrences or count of the words in each of the columns which we obtain from the matrix.

The overall explanation says that each word needs to be represented as a vector. Now, GloVe makes use of this local factor and scales it globally over the entire corpus by using a simple formula.

Glove formula for multiple words

This is dependent on 2 word vectors with indexes i and j and separate context vector with index k. F encodes the information, present in the ratio; the most intuitive way to represent this difference in vector form is to subtract one vector from another. Hereafter a lot of complex properties are used which I found overwhelming so I shall just mention the final formula that we obtain after applying homomorphism.

Glove formula

where f is the weighting function, which is defined manually.

The implementation of GloVe can be done very easily using a library called Gensim. I shall cover the implementation in another blog but i just wanted to give a rough overview of the topic in today’s blog. Just a quick summary of what GloVe is (Picked up a simple definition of the internet):

The approach of global word representation is used to capture the meaning of one word embedding with the structure of the whole observed corpus; word frequency and co-occurrence counts are the main measures on which the majority of unsupervised algorithms are based on. GloVe model trains on global co-occurrence counts of words and makes a sufficient use of statistics by minimizing least-squares error and, as result, producing a word vector space with meaningful substructure. Such an outline sufficiently preserves words similarities with vector distance.

I gave the following paper a rough read before writing this blog and it is an amazing source if you guys wanna get more knowledge on the topic.

The paper is given by stanford and is an amazing source, If y’all cant read the whole thing, then give the video shown below a watch just to get a fair understanding of what glove is.

That's it for today. Hope y’all found it useful. Thanks for reading. Shoutout to my boy @Rounak Stanley for helping me with the cover of this blog at 4am. Keep Learning.

Cheers.

--

--