def plot(self, filename="./corpus/model/blog.png"):
tsne = TSNE(perplexity=30, n_components=2, init="pca", n_iter=5000)
plot_only=500
low_dim_embeddings = tsne.fit_transform(self.final_embeddings[:plot_only, :])
reversed_dictionary = dict(zip(self.dictionary.values(), self.dictionary.keys()))
labels = [reversed_dictionary[i] for i in range(plot_only)]
plt.figure(figsize=(18, 18))
for i, label in enumerate(labels):
x, y = low_dim_embeddings[i, :]
plt.scatter(x, y)
plt.annotate(label,
xy=(x, y),
xytext=(5, 2),
textcoords="offset points",
ha="right",
va="bottom")
plt.savefig(filename)
print("Scatter plot was saved to", filename)
评论列表
文章目录