MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / main

Function main

nlp_class2/visualize_countries.py:15–35  ·  view source on GitHub ↗
(we_file='glove_model_50.npz', w2i_file='glove_word2idx_50.json')

Source from the content-addressed store, hash-verified

13from sklearn.manifold import TSNE
14
15def main(we_file='glove_model_50.npz', w2i_file='glove_word2idx_50.json'):
16 words = ['japan', 'japanese', 'england', 'english', 'australia', 'australian', 'china', 'chinese', 'italy', 'italian', 'french', 'france', 'spain', 'spanish']
17
18 with open(w2i_file) as f:
19 word2idx = json.load(f)
20
21 npz = np.load(we_file)
22 W = npz['arr_0']
23 V = npz['arr_1']
24 We = (W + V.T) / 2
25
26 idx = [word2idx[w] for w in words]
27 # We = We[idx]
28
29 tsne = TSNE()
30 Z = tsne.fit_transform(We)
31 Z = Z[idx]
32 plt.scatter(Z[:,0], Z[:,1])
33 for i in range(len(words)):
34 plt.annotate(s=words[i], xy=(Z[i,0], Z[i,1]))
35 plt.show()
36
37
38if __name__ == '__main__':

Callers 1

Calls 2

loadMethod · 0.45
fit_transformMethod · 0.45

Tested by

no test coverage detected