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

Function main

rnn_class/visualize_embeddings.py:16–28  ·  view source on GitHub ↗
(we_file='word_embeddings.npy', w2i_file='wikipedia_word2idx.json', Model=PCA)

Source from the content-addressed store, hash-verified

14from sklearn.decomposition import PCA, TruncatedSVD
15
16def main(we_file='word_embeddings.npy', w2i_file='wikipedia_word2idx.json', Model=PCA):
17 We = np.load(we_file)
18 V, D = We.shape
19 with open(w2i_file) as f:
20 word2idx = json.load(f)
21 idx2word = {v:k for k,v in iteritems(word2idx)}
22
23 model = Model()
24 Z = model.fit_transform(We)
25 plt.scatter(Z[:,0], Z[:,1])
26 for i in range(V):
27 plt.annotate(s=idx2word[i], xy=(Z[i,0], Z[i,1]))
28 plt.show()
29
30
31if __name__ == '__main__':

Callers 1

Calls 3

ModelClass · 0.50
loadMethod · 0.45
fit_transformMethod · 0.45

Tested by

no test coverage detected