I am Working On Sentiment Analysis on Amazon Food Reviews and I am trying to apply Word2Vec on the Reviews and Visualise it Using t-SNE.
I was easily able to Visualise using Bag of words representation of the same using following code:
from sklearn.manifold import TSNE
data_2000 = final_counts[0:2000,:]
top_2000 = data_2000.toarray()
labels = final['Score']
labels_2000 = labels[0:2000]
model = TSNE(n_components=2, random_state=0)
tsne_data = model.fit_transform(top_2000)
# creating a new data frame which help us in ploting the result
tsne_data = np.vstack((tsne_data.T, labels_2000)).T
tsne_df = pd.DataFrame(data=tsne_data, columns=("Dim_1", "Dim_2",
"label"))
# Ploting the result of tsne
sns.FacetGrid(tsne_df, hue="label", size=6).map(plt.scatter,
'Dim_1', 'Dim_2').add_legend()
plt.show()
Also, The same code doesn't work when I feed w2v_model model which is of type gensim.models.word2vec.Word2Vec
I obtained the model by using following Code:
w2v_model=gensim.models.Word2Vec(list_of_sent,min_count=5,size=50,
workers=4)