Reputation: 45
How to giving a specific word to test a trained word2vec model?
For example
Input "dog", and return nearst word like "cat", "bird" etc..
Thanks!
Upvotes: 2
Views: 516
Reputation: 714
That tensor flow example already has a function to compute similarities and show nearest words. The easiest way is to use that function.
In step 4 after defining valid_examples, you can give your own words.
valid_examples = np.random.choice(valid_window, valid_size, replace=False)
num_sampled = 64 # Number of negative examples to sample.
sample_word = "dog";
if sample_word in dictionary:
sample_index = dictionary[sample_word]
else:
sample_index = 0 # dictionary['UNK']
valid_examples[0] = sample_index
Then you can see the result in first line. For ex, my result was
Nearest to dog: empower, nephew, stationary, marmoset, wow, kvac, dasyprocta, centaur,
Upvotes: 1