Created
January 5, 2017 14:18
-
-
Save Adagio-cantabile/d6261073c184abd0ebfb728dcb335eab to your computer and use it in GitHub Desktop.
note from Stanford NLP lecture
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
#written in python 3.5 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
la = np.linalg | |
words = ['I', 'like', 'enjoy', 'deep', 'learning', 'NLP', 'flying', '.'] | |
X = np.array([[0,2,1,0,0,0,0,0], | |
[2,0,0,1,0,1,0,0], | |
[1,0,0,0,0,0,1,0], | |
[0,1,0,0,1,0,0,0], | |
[0,0,0,1,0,0,0,1], | |
[0,1,0,0,0,0,0,1], | |
[0,0,1,0,0,0,0,1], | |
[0,0,0,0,1,1,1,0]]) | |
#U for left vector, s for diagonal matrix | |
#use svd to reduce dimensions | |
U, s, Vh = la.svd(X, full_matrices=False) | |
for i in range(len(words)): | |
#use the first and second element of each word vector to represent X and Y position | |
#for making sure that we picked up the most important information of original vector | |
plt.text(U[i,0], U[i,1], words[i]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment