Skip to content

Commit

Permalink
Minor change in the test script
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikp committed May 1, 2017
1 parent fda36c7 commit e0fa410
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,13 @@ Let's check if the closest words make sense.

```bash
$ python3 test_word_vectors.py --word IRA
Roth
SEP
IRAs
401
retirement
roth, iras, sep, 401, contribute

$ python3 test_word_vectors.py --word option
call
put
options
exercise
underlying
call, options, put, exercise, underlying

$ python3 test_word_vectors.py --word stock
shares
market
stocks
share
price
shares, share, market, stocks, price
```

## Notes
Expand Down
6 changes: 4 additions & 2 deletions test_word_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@


def print_nearest_words(args):
word = args.word.lower()

# Load the word vectors
embeddings_index = {}
f = open(args.vectors)
Expand All @@ -18,7 +20,7 @@ def print_nearest_words(args):
f.close()

w_v = np.zeros(50)
for w in args.word.strip().split():
for w in word.strip().split():
if w not in embeddings_index.keys():
continue

Expand All @@ -27,7 +29,7 @@ def print_nearest_words(args):
# Get the similarity scores
score_dict = {}
for w in embeddings_index.keys():
if args.word == w:
if word == w:
continue

score = cosine_similarity(w_v.reshape(1, -1), embeddings_index[w].reshape(1, -1))[0][0]
Expand Down

0 comments on commit e0fa410

Please sign in to comment.