首页 文章

用gensim学习印刷双字母

提问于
浏览
0

我想使用gensim从语料库中学习双字母组合,然后只打印学到的双字母组合 . 我没见过这样做的例子 . 帮助赞赏

from gensim.models import Phrases
documents = ["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

1 回答

  • 0
    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)
    

相关问题