Skip to content

Instantly share code, notes, and snippets.

@phoebewong
Last active December 12, 2019 20:59
Show Gist options
  • Select an option

  • Save phoebewong/c1281bfca9e291bd9ee42dba285e8d73 to your computer and use it in GitHub Desktop.

Select an option

Save phoebewong/c1281bfca9e291bd9ee42dba285e8d73 to your computer and use it in GitHub Desktop.
Loade GloVe embeddings
# loading glove data file
# URL to donwload the GloVe embedding: https://nlp.stanford.edu/projects/glove/
D = 50
glove_data_file = f'data/glove.6B.{D}d.txt'
words = pd.read_csv(glove_data_file, sep=" ", index_col=0, header=None, quoting=csv.QUOTE_NONE)
# creating a dictionary for accessing words quickly
words_dict = {word: embed for word, embed in zip(words.index, words.values.tolist())}
print(f'Loaded {len(words_dict.keys())} words from the GloVe file')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment