Skip to content

Instantly share code, notes, and snippets.

@Adagio-cantabile
Created January 5, 2017 14:18
Show Gist options
  • Save Adagio-cantabile/d6261073c184abd0ebfb728dcb335eab to your computer and use it in GitHub Desktop.
Save Adagio-cantabile/d6261073c184abd0ebfb728dcb335eab to your computer and use it in GitHub Desktop.
note from Stanford NLP lecture
#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