File tree 1 file changed +4
-8
lines changed
1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change 8
8
from __future__ import print_function
9
9
from wordcloud import create_cloud
10
10
try :
11
- from gensim import corpora , models
11
+ from gensim import corpora , models , matutils
12
12
except :
13
13
print ("import gensim failed." )
14
14
print ()
44
44
# We first identify the most discussed topic, i.e., the one with the
45
45
# highest total weight
46
46
47
- # First, we need to sum up the weights across all the documents
48
- weight = np .zeros (model .num_topics )
49
- for doc in corpus :
50
- for col , val in model [doc ]:
51
- weight [col ] += val
52
- # As a reasonable alternative, we could have used the log of val:
53
- # weight[col] += np.log(val)
47
+ topics = matutils .corpus2dense (model [corpus ], num_terms = model .num_topics )
48
+ weight = topics .sum (1 )
54
49
max_topic = weight .argmax ()
55
50
51
+
56
52
# Get the top 64 words for this topic
57
53
# Without the argument, show_topic would return only 10 words
58
54
words = model .show_topic (max_topic , 64 )
You can’t perform that action at this time.
0 commit comments