【问题标题】:How do I use "BigramCollocationFinder" to find "Bigrams"?如何使用“BigramCollocationFinder”查找“Bigrams”?
【发布时间】:2019-04-24 23:39:38
【问题描述】:

我正在研究使用 python 构建编译器,我正在尝试创建文本中所有小写单词的列表,然后生成BigramCollocationFinder,我们可以使用它来查找双连词,它们是成对的单词。

这些二元组是使用 nltk.metrics 包中的关联测量函数找到的。

我正在从“Python 3 Text Processing with NLTK 3 Cookbook”练习,我发现了这个示例代码:

from nltk.corpus import webtext
from nltk.collocations import BigramCollocationFinder
from nltk.metrics import BigramAssocMeasures
words = [w.lower() for w in webtext.words('grail.txt')]
bcf = BigramCollocationFinder.from_words(words)
bcf.nbest(BigramAssocMeasures.likelihood_ratio, 4)

我被困在:

bcf.nbest(BigramAssocMeasures.likelihood_ratio, 4)
likelihood_ratio, 4

这里指的是相似度,或者在这段代码中是什么意思。

我们将非常感谢您对此事的任何指导。

【问题讨论】:

    标签: python-3.x nltk cookbook


    【解决方案1】:

    我相信NLTK collocations for specific words 应该会回答您的问题。它首先计算 PMI,然后返回在您的语料库中出现频率最高的前 4 个单词。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    相关资源
    最近更新 更多