Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you point me to glove.6B.300d.pickle? #8

Open
aerinkim opened this issue Oct 24, 2018 · 2 comments
Open

Could you point me to glove.6B.300d.pickle? #8

aerinkim opened this issue Oct 24, 2018 · 2 comments

Comments

@aerinkim
Copy link

Usually, it's glove.6B.300d.txt but I think you did some preprocessing here. I'd appreciate if you could share how you pickled it.

@rjadr
Copy link

rjadr commented Apr 13, 2019

This is how I generated it:

import pickle
import numpy as np

f = open('glove.6B.300d.txt', 'r')
g = open('glove.6B.300d_pickle', 'wb')
word_dict = {}
wordvec = []
for idx, line in enumerate(f.readlines()):
    word_split = line.split(' ')
    word = word_split[0]
    word_dict[word] = idx
    d = word_split[1:]
    d[-1] = d[-1][:-1]
    d = [float(e) for e in d]
    wordvec.append(d)

embedding = np.array(wordvec)
pickling = {}
pickling = {'embedding' : embedding, 'word_dict': word_dict}
pickle.dump(pickling, g)
f.close()
g.close()

@ott-fogliata
Copy link

@rjadr To use it with the paraphraser code, you need some changes:

import pickle
import numpy as np

f = open('glove.6B.300d.txt', 'r')
g = open('glove.6B.300d.pickle', 'wb')

word_to_id = {}
id_to_word = {}

wordvec = []

for idx, line in enumerate(f.readlines()):

    word_split = line.split(' ')
    word = word_split[0]
    word_to_id[word] = idx
    id_to_word[idx] = word

    d = word_split[1:]
    d[-1] = d[-1][:-1]
    d = [float(e) for e in d]
    wordvec.append(d)

embedding = np.array(wordvec)

pickling = word_to_id, id_to_word, embedding

pickle.dump(pickling, g)

f.close()
g.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants