![](/img/trans.png)
[英]Is there a method in Gensim to find the most relevant topics between two corpuses?
[英]Gensim find topics in sentences
我已经在语料库上训练了LDA算法,我想要做的是为每个句子获取与之对应的主题,以便在算法找到的内容和我拥有的标签之间进行比较。
我已经尝试使用下面的代码,但是结果非常糟糕,我发现了很多有关主题17的内容(可能是25%,应该接近5%)
谢谢你的帮助
# text lemmatized: list of string lemmatized
dico = Dictionary(texts_lemmatized)
corpus_lda = [dico.doc2bow(text) for text in texts_lemmatized]
lda_ = LdaModel(corpus_lda, num_topics=18)
df_ = pd.DataFrame([])
data = []
# theme_commentaire = label of the string
for i in range(0, len(theme_commentaire)):
# lda_.get_document_topics() gives the distribution of all topic for a specific sentence
algo = max(lda_.get_document_topics(corpus_lda[i]))[0]
human = theme_commentaire[i]
data.append([str(algo), human])
cols = ['algo', 'human']
df_ = pd.DataFrame(data, columns=cols)
df_.head()
解决的评论:
不过,我发现了我的问题,它是max()函数,它对我的元组列表的键值[(num_topics,概率)]起作用,因此基本上我大部分时间都会得到17,因为它是最大的键。 –格洛瓦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.