fresh
fresh

Reputation: 45

How to giving a specific word to word2vec model in tensorflow

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!

word2vec_basic_py

Upvotes: 2

Views: 516

Answers (1)

Jin
Jin

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

Related Questions