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

Function test_model

nlp_class2/word2vec_theano.py:365–401  ·  view source on GitHub ↗
(word2idx, W, V)

Source from the content-addressed store, hash-verified

363
364
365def test_model(word2idx, W, V):
366 # there are multiple ways to get the "final" word embedding
367 # We = (W + V.T) / 2
368 # We = W
369
370 idx2word = {i:w for w, i in word2idx.items()}
371
372 for We in (W, (W + V.T) / 2):
373 print("**********")
374
375 analogy('king', 'man', 'queen', 'woman', word2idx, idx2word, We)
376 analogy('king', 'prince', 'queen', 'princess', word2idx, idx2word, We)
377 analogy('miami', 'florida', 'dallas', 'texas', word2idx, idx2word, We)
378 analogy('einstein', 'scientist', 'picasso', 'painter', word2idx, idx2word, We)
379 analogy('japan', 'sushi', 'germany', 'bratwurst', word2idx, idx2word, We)
380 analogy('man', 'woman', 'he', 'she', word2idx, idx2word, We)
381 analogy('man', 'woman', 'uncle', 'aunt', word2idx, idx2word, We)
382 analogy('man', 'woman', 'brother', 'sister', word2idx, idx2word, We)
383 analogy('man', 'woman', 'husband', 'wife', word2idx, idx2word, We)
384 analogy('man', 'woman', 'actor', 'actress', word2idx, idx2word, We)
385 analogy('man', 'woman', 'father', 'mother', word2idx, idx2word, We)
386 analogy('heir', 'heiress', 'prince', 'princess', word2idx, idx2word, We)
387 analogy('nephew', 'niece', 'uncle', 'aunt', word2idx, idx2word, We)
388 analogy('france', 'paris', 'japan', 'tokyo', word2idx, idx2word, We)
389 analogy('france', 'paris', 'china', 'beijing', word2idx, idx2word, We)
390 analogy('february', 'january', 'december', 'november', word2idx, idx2word, We)
391 analogy('france', 'paris', 'germany', 'berlin', word2idx, idx2word, We)
392 analogy('week', 'day', 'year', 'month', word2idx, idx2word, We)
393 analogy('week', 'day', 'hour', 'minute', word2idx, idx2word, We)
394 analogy('france', 'paris', 'italy', 'rome', word2idx, idx2word, We)
395 analogy('paris', 'france', 'rome', 'italy', word2idx, idx2word, We)
396 analogy('france', 'french', 'england', 'english', word2idx, idx2word, We)
397 analogy('japan', 'japanese', 'china', 'chinese', word2idx, idx2word, We)
398 analogy('china', 'chinese', 'america', 'american', word2idx, idx2word, We)
399 analogy('japan', 'japanese', 'italy', 'italian', word2idx, idx2word, We)
400 analogy('japan', 'japanese', 'australia', 'australian', word2idx, idx2word, We)
401 analogy('walk', 'walking', 'swim', 'swimming', word2idx, idx2word, We)
402
403
404

Callers 1

word2vec_theano.pyFile · 0.70

Calls 1

analogyFunction · 0.70

Tested by

no test coverage detected