Skip to content

Commit a0ed5dc

Browse files
committed
fixed a bug related to writing the word vector to the file
1 parent e0fa410 commit a0ed5dc

File tree

3 files changed

+104
-4
lines changed

3 files changed

+104
-4
lines changed

glove.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def train_glove(args):
8686
j = Variable(torch.LongTensor([i]))
8787
vec = (model.l_vecs(j) + model.r_vecs(j)).data.squeeze()
8888
for k in range(vec.size(0)):
89-
s + ' ' + str(vec[k])
89+
s += ' ' + str(round(vec[k], 6))
9090

9191
f.write(s)
9292

test_word_vectors.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def print_nearest_words(args):
10-
word = args.word.lower()
10+
word = args.word.lower().strip()
1111

1212
# Load the word vectors
1313
embeddings_index = {}
@@ -19,8 +19,8 @@ def print_nearest_words(args):
1919
embeddings_index[w] = coefs
2020
f.close()
2121

22-
w_v = np.zeros(50)
23-
for w in word.strip().split():
22+
w_v = np.zeros_like(embeddings_index[w])
23+
for w in word.split():
2424
if w not in embeddings_index.keys():
2525
continue
2626

0 commit comments

Comments
 (0)