Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvanZhou committed Dec 31, 2020
1 parent cba91cd commit 9e3252f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ matplotlib==3.2.1
numpy==1.18.5
pandas==1.0.4
requests==2.23.0
sklearn==0.23.0
tensorflow==2.3.1
tensorflow-addons==0.10.0
2 changes: 1 addition & 1 deletion tf_idf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ def get_keywords(n=2):
d_ids = scores.argsort()[-3:][::-1]
print("\ntop 3 docs for '{}':\n{}".format(q, [docs[i] for i in d_ids]))

show_tfidf(tf_idf.T, [i2v[i] for i in range(len(i2v))], "tfidf_matrix")
show_tfidf(tf_idf.T, [i2v[i] for i in range(tf_idf.shape[0])], "tfidf_matrix")
3 changes: 2 additions & 1 deletion tf_idf_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@


i2v = {i: v for v, i in vectorizer.vocabulary_.items()}
show_tfidf(tf_idf.todense(), [i2v[i] for i in range(len(i2v))], "tfidf_sklearn_matrix")
dense_tfidf = tf_idf.todense()
show_tfidf(dense_tfidf, [i2v[i] for i in range(dense_tfidf.shape[1])], "tfidf_sklearn_matrix")
8 changes: 4 additions & 4 deletions visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import utils


def show_tfidf(tfidf, vocb, filename):
# [n_vocab, n_doc]
def show_tfidf(tfidf, vocab, filename):
# [n_doc, n_vocab]
plt.imshow(tfidf, cmap="YlGn", vmin=tfidf.min(), vmax=tfidf.max())
plt.xticks(np.arange(tfidf.shape[1]), vocb, fontsize=6, rotation=90)
plt.yticks(np.arange(tfidf.shape[0]), np.arange(1, tfidf.shape[1]+1), fontsize=6)
plt.xticks(np.arange(tfidf.shape[1]), vocab, fontsize=6, rotation=90)
plt.yticks(np.arange(tfidf.shape[0]), np.arange(1, tfidf.shape[0]+1), fontsize=6)
plt.tight_layout()
plt.savefig("./visual/results/%s.png" % filename, format="png", dpi=500)
plt.show()
Expand Down

0 comments on commit 9e3252f

Please sign in to comment.