MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / test_model

Function test_model

nlp_class2/word2vec_tf.py:414–450  ·  view source on GitHub ↗
(word2idx, W, V)

Source from the content-addressed store, hash-verified

412
413
414def test_model(word2idx, W, V):
415 # there are multiple ways to get the "final" word embedding
416 # We = (W + V.T) / 2
417 # We = W
418
419 idx2word = {i:w for w, i in word2idx.items()}
420
421 for We in (W, (W + V.T) / 2):
422 print("**********")
423
424 analogy('king', 'man', 'queen', 'woman', word2idx, idx2word, We)
425 analogy('king', 'prince', 'queen', 'princess', word2idx, idx2word, We)
426 analogy('miami', 'florida', 'dallas', 'texas', word2idx, idx2word, We)
427 analogy('einstein', 'scientist', 'picasso', 'painter', word2idx, idx2word, We)
428 analogy('japan', 'sushi', 'england', 'bread', word2idx, idx2word, We)
429 analogy('man', 'woman', 'he', 'she', word2idx, idx2word, We)
430 analogy('man', 'woman', 'uncle', 'aunt', word2idx, idx2word, We)
431 analogy('man', 'woman', 'brother', 'sister', word2idx, idx2word, We)
432 analogy('man', 'woman', 'husband', 'wife', word2idx, idx2word, We)
433 analogy('man', 'woman', 'actor', 'actress', word2idx, idx2word, We)
434 analogy('man', 'woman', 'father', 'mother', word2idx, idx2word, We)
435 analogy('heir', 'heiress', 'prince', 'princess', word2idx, idx2word, We)
436 analogy('nephew', 'niece', 'uncle', 'aunt', word2idx, idx2word, We)
437 analogy('france', 'paris', 'japan', 'tokyo', word2idx, idx2word, We)
438 analogy('france', 'paris', 'china', 'beijing', word2idx, idx2word, We)
439 analogy('february', 'january', 'december', 'november', word2idx, idx2word, We)
440 analogy('france', 'paris', 'germany', 'berlin', word2idx, idx2word, We)
441 analogy('week', 'day', 'year', 'month', word2idx, idx2word, We)
442 analogy('week', 'day', 'hour', 'minute', word2idx, idx2word, We)
443 analogy('france', 'paris', 'italy', 'rome', word2idx, idx2word, We)
444 analogy('paris', 'france', 'rome', 'italy', word2idx, idx2word, We)
445 analogy('france', 'french', 'england', 'english', word2idx, idx2word, We)
446 analogy('japan', 'japanese', 'china', 'chinese', word2idx, idx2word, We)
447 analogy('china', 'chinese', 'america', 'american', word2idx, idx2word, We)
448 analogy('japan', 'japanese', 'italy', 'italian', word2idx, idx2word, We)
449 analogy('japan', 'japanese', 'australia', 'australian', word2idx, idx2word, We)
450 analogy('walk', 'walking', 'swim', 'swimming', word2idx, idx2word, We)
451
452
453

Callers 1

word2vec_tf.pyFile · 0.70

Calls 1

analogyFunction · 0.70

Tested by

no test coverage detected