为了账号安全,请及时绑定邮箱和手机立即绑定

打印使用 gensim 学习的二元组

打印使用 gensim 学习的二元组

翻阅古今 2021-09-11 17:50:52
我想使用 gensim 从语料库中学习 bigrams,然后打印学习到的 bigrams。我还没有看到这样做的例子。帮助赞赏from gensim.models import Phrasesdocuments = ["the mayor of new york was there", "human computer interaction and machine learning has now become a trending research area","human computer interaction is interesting","human computer interaction is a pretty interesting subject", "human computer interaction is a great and new subject", "machine learning can be useful sometimes","new york mayor was present", "I love machine learning because it is a new subject area", "human computer interaction helps people to get user friendly applications"]sentence_stream = [doc.split(" ") for doc in documents]bigram = Phrases(sentence_stream)# how can I print all bigrams learned and just the bigrams, including "new_york" and "human computer" ?enter code here
查看完整描述

2 回答

?
慕桂英546537

TA贡献1848条经验 获得超10个赞

import operator

sorted(

    {k:v for k,v in bigram.vocab.items() if b'_' in k if v>=bigram.min_count}.items(),

    key=operator.itemgetter(1),

    reverse=True)


查看完整回答
反对 回复 2021-09-11
  • 2 回答
  • 0 关注
  • 166 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信