Created
July 14, 2019 20:34
-
-
Save michelkana/afbb568231b189a276607c077ebb598b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get word2vec embeddings | |
words = ['russia', 'moscow', 'france', 'paris'] | |
word_vectors = np.array([model[w] for w in words]) | |
# pca transformation | |
twodim = PCA().fit_transform(word_vectors)[:,:2] | |
# t-sne transformation | |
twodim_tsne = TSNE().fit_transform(word_vectors)[:,:2] | |
# pca plot | |
plt.figure(figsize=(3,3)) | |
plt.scatter(twodim[:,0], twodim[:,1], edgecolors='k', c='r') | |
for word, (x,y) in zip(words, twodim): | |
plt.text(x+0.05, y+0.05, word); | |
# t-sne plot | |
plt.figure(figsize=(3,3)) | |
plt.scatter(twodim_tsne[:,0], twodim_tsne[:,1], edgecolors='k', c='r') | |
for word, (x,y) in zip(words, twodim_tsne): | |
plt.text(x+0.05, y+0.05, word); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment