Example #1
0
	# 		words.append(a+"_"+n+"_l2")


	#runs pca on the smaller matrix we construct....
	####################
	B = []
	for word in words:
		if word in vecs:
			B.append(vecs[word])
		elif "avg" in word:
			tokens = word.split('_')
			avg = (vecs[tokens[0]] + vecs[tokens[1]]) / 2.0
			B.append(avg)
		elif "l2" in word:
			tokens = word.split('_')
			B.append(tb.local_knn_pred(vecs, tokens[0], tokens[1], "norm"))
		elif "cos" in word:
			tokens = word.split('_')
			B.append(tb.local_knn_pred(vecs, tokens[0], tokens[1], "cos"))
		elif "svr" in word:
			tokens = word.split('_')
			B.append(tnn.pred(vecs[tokens[0]], vecs[tokens[1]]))

	B = np.matrix(B)

	# add other non-plotted bigrams to the matrix before running PCA
	B = np.concatenate((B, wordVecsMatrix[1:500, :]))
	print "Running PCA"
	pca.fit(B)
	B = pca.transform(B)
	#######################
Example #2
0
    # 		words.append(a+"_"+n+"_cos")
    # 		words.append(a+"_"+n+"_l2")

    #runs pca on the smaller matrix we construct....
    ####################
    B = []
    for word in words:
        if word in vecs:
            B.append(vecs[word])
        elif "avg" in word:
            tokens = word.split('_')
            avg = (vecs[tokens[0]] + vecs[tokens[1]]) / 2.0
            B.append(avg)
        elif "l2" in word:
            tokens = word.split('_')
            B.append(tb.local_knn_pred(vecs, tokens[0], tokens[1], "norm"))
        elif "cos" in word:
            tokens = word.split('_')
            B.append(tb.local_knn_pred(vecs, tokens[0], tokens[1], "cos"))
        elif "svr" in word:
            tokens = word.split('_')
            B.append(tnn.pred(vecs[tokens[0]], vecs[tokens[1]]))

    B = np.matrix(B)

    # add other non-plotted bigrams to the matrix before running PCA
    B = np.concatenate((B, wordVecsMatrix[1:500, :]))
    print "Running PCA"
    pca.fit(B)
    B = pca.transform(B)
    #######################
def predict(word1, word2):
    return tb.local_knn_pred(word_vectors, word1, word2, "norm")
def predict (word1, word2):
	return tb.local_knn_pred(word_vectors, word1, word2, "norm")