Skip to content

Commit 9e3252f

Browse files
committed
fix bug
1 parent cba91cd commit 9e3252f

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ matplotlib==3.2.1
22
numpy==1.18.5
33
pandas==1.0.4
44
requests==2.23.0
5+
sklearn==0.23.0
56
tensorflow==2.3.1
67
tensorflow-addons==0.10.0

‎tf_idf.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ def get_keywords(n=2):
136136
d_ids = scores.argsort()[-3:][::-1]
137137
print("\ntop 3 docs for '{}':\n{}".format(q, [docs[i] for i in d_ids]))
138138

139-
show_tfidf(tf_idf.T, [i2v[i] for i in range(len(i2v))], "tfidf_matrix")
139+
show_tfidf(tf_idf.T, [i2v[i] for i in range(tf_idf.shape[0])], "tfidf_matrix")

‎tf_idf_sklearn.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@
3535

3636

3737
i2v = {i: v for v, i in vectorizer.vocabulary_.items()}
38-
show_tfidf(tf_idf.todense(), [i2v[i] for i in range(len(i2v))], "tfidf_sklearn_matrix")
38+
dense_tfidf = tf_idf.todense()
39+
show_tfidf(dense_tfidf, [i2v[i] for i in range(dense_tfidf.shape[1])], "tfidf_sklearn_matrix")

‎visual.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import utils
77

88

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

0 commit comments

Comments
 (0)