Problem with NLTK, collocations: too many values to unpack (expected 2)

跟風遠走 提交于 2020-12-30 07:44:57

问题


i tried to retrieve collocations with NLTK, yet i get an error. I used built-in gutenberg corpus

I wrote:

alice = nltk.corpus.gutenberg.fileids()[7]
al = nltk.corpus.gutenberg.words(alice)
al_text = nltk.Text(al)
al_text.collocations(25)

i got:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-a6905d575410> in <module>
----> 1 al_text.collocations(25)

C:\ProgramData\Anaconda3\lib\site-packages\nltk\text.py in collocations(self, num, window_size)
    442 
    443         collocation_strings = [
--> 444             w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
    445         ]
    446         print(tokenwrap(collocation_strings, separator="; "))

C:\ProgramData\Anaconda3\lib\site-packages\nltk\text.py in <listcomp>(.0)
    442 
    443         collocation_strings = [
--> 444             w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
    445         ]
    446         print(tokenwrap(collocation_strings, separator="; "))

ValueError: too many values to unpack (expected 2)

However, when i use i.e other functions that uses nltk,tetx():

al_text.concordance('Beautiful', width=39, lines=50)

Everything works correctly.

Does anyone know where is a problem? I tried using different numbers, etc, yet I can't localize it

UPDATE

Found a solution:

al_text.collocation_list()

Apparently collocations is buggy: Github

来源:https://stackoverflow.com/questions/59266387/problem-with-nltk-collocations-too-many-values-to-unpack-expected-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!