-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglove.py
More file actions
33 lines (25 loc) · 730 Bytes
/
glove.py
File metadata and controls
33 lines (25 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
def loadGlove():
print("Loading glove")
print("--------------")
words = []
idx = 0
word2idx = {}
weights = []
count = 0
with open(f'./glove.6B.50d.txt', 'rb') as doc:
for line in doc:
line = line.decode().split()
word = line[0]
words.append(word)
word2idx[word] = idx
idx += 1
weight = np.array(line[1:]).astype(np.float)
weights.append(weight)
count += 1
if(count % 50000 == 0):
print("{}/400000".format(count))
glove = {word: weights[word2idx[word]] for word in words}
return glove
if __name__ == "__main__":
loadGlove()