微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用潜在的dirichlet allocat捕获bigram主题而不是unigram

如何解决使用潜在的dirichlet allocat捕获bigram主题而不是unigram

我尝试尝试类似this问题

LDA原始输出

Uni-grams

    topic1 -scuba,water,vapor,diving

    topic2 -dioxide,plants,green,carbon

必需的输出

Bi-gram topics

    topic1 -scuba diving,water vapor

    topic2 -green plants,carbon dioxide

有这个答案

from nltk.util import ngrams

for doc in docs:
    docs[doc] = docs[doc] + ["_".join(w) for w in ngrams(docs[doc],2)]

任何帮助我应该进行哪些更新才能只有二元组吗?

解决方法

仅创建带有双字词的文档:

from nltk.util import ngrams

for doc in docs:
    docs[doc] = ["_".join(w) for w in ngrams(docs[doc],2)]

或针对二元组的特定方法:

from nltk.util import bigrams

for doc in docs:
    docs[doc] = ["_".join(w) for w in bigrams(docs[doc])]

然后将texts中这些二元组的列表用于以后的操作。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。