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

Function test_model

nlp_class2/word2vec.py:314–350  ·  view source on GitHub ↗
(word2idx, W, V)

Source from the content-addressed store, hash-verified

312
313
314def test_model(word2idx, W, V):
315 # there are multiple ways to get the "final" word embedding
316 # We = (W + V.T) / 2
317 # We = W
318
319 idx2word = {i:w for w, i in word2idx.items()}
320
321 for We in (W, (W + V.T) / 2):
322 print("**********")
323
324 analogy('king', 'man', 'queen', 'woman', word2idx, idx2word, We)
325 analogy('king', 'prince', 'queen', 'princess', word2idx, idx2word, We)
326 analogy('miami', 'florida', 'dallas', 'texas', word2idx, idx2word, We)
327 analogy('einstein', 'scientist', 'picasso', 'painter', word2idx, idx2word, We)
328 analogy('japan', 'sushi', 'germany', 'bratwurst', word2idx, idx2word, We)
329 analogy('man', 'woman', 'he', 'she', word2idx, idx2word, We)
330 analogy('man', 'woman', 'uncle', 'aunt', word2idx, idx2word, We)
331 analogy('man', 'woman', 'brother', 'sister', word2idx, idx2word, We)
332 analogy('man', 'woman', 'husband', 'wife', word2idx, idx2word, We)
333 analogy('man', 'woman', 'actor', 'actress', word2idx, idx2word, We)
334 analogy('man', 'woman', 'father', 'mother', word2idx, idx2word, We)
335 analogy('heir', 'heiress', 'prince', 'princess', word2idx, idx2word, We)
336 analogy('nephew', 'niece', 'uncle', 'aunt', word2idx, idx2word, We)
337 analogy('france', 'paris', 'japan', 'tokyo', word2idx, idx2word, We)
338 analogy('france', 'paris', 'china', 'beijing', word2idx, idx2word, We)
339 analogy('february', 'january', 'december', 'november', word2idx, idx2word, We)
340 analogy('france', 'paris', 'germany', 'berlin', word2idx, idx2word, We)
341 analogy('week', 'day', 'year', 'month', word2idx, idx2word, We)
342 analogy('week', 'day', 'hour', 'minute', word2idx, idx2word, We)
343 analogy('france', 'paris', 'italy', 'rome', word2idx, idx2word, We)
344 analogy('paris', 'france', 'rome', 'italy', word2idx, idx2word, We)
345 analogy('france', 'french', 'england', 'english', word2idx, idx2word, We)
346 analogy('japan', 'japanese', 'china', 'chinese', word2idx, idx2word, We)
347 analogy('china', 'chinese', 'america', 'american', word2idx, idx2word, We)
348 analogy('japan', 'japanese', 'italy', 'italian', word2idx, idx2word, We)
349 analogy('japan', 'japanese', 'australia', 'australian', word2idx, idx2word, We)
350 analogy('walk', 'walking', 'swim', 'swimming', word2idx, idx2word, We)
351
352
353

Callers 1

word2vec.pyFile · 0.70

Calls 1

analogyFunction · 0.70

Tested by

no test coverage detected