python - 使用潜在狄利克雷分配器捕获二元组主题而不是一元组
问题描述
我尝试尝试这样的问题
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
未来的操作中使用这些二元组的列表。
推荐阅读
- javascript - 在javascript中取消异步调用链
- javascript - AWS Coginto API,即使不存在经过验证的电话号码和经过验证的电子邮件,忘记密码操作也不会引发 InvalidParameterException
- python - 滑块实时变化波包动画 Matplotlib
- c# - 在我的新 PC 中使用 Visual Studio 运行我的 ASP.NET MVC 时,我对其发出的每个请求都会自动将其重定向到 Microsoft 登录
- python - 如何解决:TypeError:字符串索引必须是整数
- python - 使用机器学习示例执行 AWS 预测性维护时出现导入错误
- opengl - 如何在兼容性配置文件中使用 GL_QUADS?
- python - 熊猫数据框:使用 agregate 和 groupby 函数后如何选择列
- python - 使用 re 和 gspread 的多个搜索字符串
- reporting-services - SSRS 报告订阅历史