首页 > 解决方案 > 如何使用“BigramCollocationFinder”查找“Bigrams”?

问题描述

我正在使用 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.xnltkcookbook

解决方案


我相信特定单词的 NLTK 搭配应该可以回答您的问题。它首先计算 PMI 并返回在您的语料库中出现频率最高的 4 个单词。


推荐阅读