Skip to content

Instantly share code, notes, and snippets.

@megha444
Created September 21, 2020 14:17
Show Gist options
  • Save megha444/7d8a1c5795c4905ceab2a5df0f95ad2e to your computer and use it in GitHub Desktop.
Save megha444/7d8a1c5795c4905ceab2a5df0f95ad2e to your computer and use it in GitHub Desktop.
#importing the glove library
from glove import Corpus, Glove
# creating a corpus object
corpus = Corpus()
#training the corpus to generate the co occurence matrix which is used in GloVe
corpus.fit(new_lines, window=10)
#creating a Glove object which will use the matrix created in the above lines to create embeddings
#We can set the learning rate as it uses Gradient Descent and number of components
glove = Glove(no_components=5, learning_rate=0.05)
glove.fit(corpus.matrix, epochs=30, no_threads=4, verbose=True)
glove.add_dictionary(corpus.dictionary)
glove.save('glove.model')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment