繁体   English   中英

使用tf-idf(Gensim)获取语料库中最重要的词

[英]Get the most important words in the corpus using tf-idf (Gensim)

我正在计算tf-idf如下。

texts=['human interface computer',
 'survey user computer system response time',
 'eps user interface system',
 'system human system eps',
 'user response time']

dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
tfidf = models.TfidfModel(corpus)
corpus_tfidf = tfidf[corpus]
analyzedDocument = namedtuple('AnalyzedDocument', 'word tfidf_score')
d=[]
for doc in corpus_tfidf:
    for id, value in doc:
        word = dictionary.get(id)
        score = value
        d.append(analyzedDocument(word, score))

但是,现在我想使用idf值最高的单词来确定语料库中最重要的3个单词。 请让我知道该怎么做?

假设您的清单确定正确,则应该能够按照以下方式进行排列:最上方:

from operator import itemgetter

然后在底部:

e=sorted(d, key=itemgetter(1))
top3 = e[:3]
print(top3)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM