在this documentation中,有使用nltk.collocations.BigramAssocMeasures()
、BigramCollocationFinder
、nltk.collocations.TrigramAssocMeasures()
和TrigramCollocationFinder
的示例。
对于bigram和trigram,有一个基于pmi的find-nbest示例方法。 示例:
finder = BigramCollocationFinder.from_words(
... nltk.corpus.genesis.words('english-web.txt'))
>>> finder.nbest(bigram_measures.pmi, 10)
我知道BigramCollocationFinder
和TrigramCollocationFinder
继承自AbstractCollocationFinder.
,而BigramAssocMeasures()
和TrigramAssocMeasures()
继承自NgramAssocMeasures.
如何使用AbstractCollocationFinder
中的方法(例如nbest()
)和NgramAssocMeasures
中的方法来处理4-gram、5-gram、6-gram、…、n-gram(比如容易使用bigram和trigram)?
我应该创建继承AbstractCollocationFinder
的类吗?
谢谢。
如果您想找到超过2或3克的克,可以使用scikit package和Freqdist函数来获取这些克的计数。我试着用nltk.collaborations做这个,但是我认为我们不能找到超过3克的分数。所以我决定用克数。我希望这能帮你一点忙。谢谢
这是密码
这将输出为
编辑
当前的NLTK有一个最多可用于^{} 的硬编码函数,但是为什么不能简单地创建
NgramCollocationFinder
的原因仍然存在,您必须从根本上更改from_words()
函数中用于不同顺序ngram的公式。简而言之,不,如果您想找到超过2和3克的搭配,就不能简单地创建一个
AbstractCollocationFinder
(ACF)来调用nbest()
函数。这是因为不同ngram的
from_words()
不同。您可以看到,只有ACF的子类(即BigramCF和TrigramCF)具有from_words()
函数。因此,在TrigramCF中给定这个
from_words()
:你可以通过某种方式破解它,并尝试对4克关联查找器进行硬编码,如下所示:
然后还必须更改代码中分别使用
from_words
返回的cls
的任何部分。所以你不得不问,找到搭配的最终目的是什么?
如果你想在更大的单词搭配中检索单词 超过2或3克的视窗,那么你会得到很多 在你的单词检索中有噪音。
如果你打算用2建立一个基于搭配模式的模型 或者3grams窗口,那么你也将面临稀疏性问题。
相关问题 更多 >
编程相关推荐