New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
collocations function returns error #2299
Comments
Thanks @martinevanschouwenburg for raising the bug! Yes it looks like the collocation list is needed. To replicate the bug: $ python3
Python 3.6.4rc1 (v3.6.4rc1:3398dcb14f, Dec 5 2017, 00:58:30)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>> text4.collocations()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/text.py", line 440, in collocations
collocation_strings = [w1 + ' ' + w2 for w1, w2 in self.collocation_list(num, window_size)]
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk/text.py", line 440, in <listcomp>
collocation_strings = [w1 + ' ' + w2 for w1, w2 in self.collocation_list(num, window_size)]
ValueError: too many values to unpack (expected 2) |
I am still seeing this error as well when going through chapter 1 of the book. *** Introductory Examples for the NLTK Book *** |
@networkjr I can confirm that too. Maybe the fix in #2227 hasn't been pushed to PyPi yet? |
@networkjr it's the same with the Anaconda package |
I'm working through the NLTK book, am completely new to NLTK and fairly new to Python - and I'm getting this same error.
According to my Is there a fix for this issue? |
This has been fixed on #2377 , should be fixed in the next NLTK release soon. Otherwise, if you can't wait =)
|
I still have the same error after updating cntk with Current cnkt version '3.4.5' How can I fix it? Many thanks. |
Also still having issues with |
Replace at line 444 in /nltk/text.py : with the following: |
Same here. Working through the nltk book gives error for collocations() whereas collocation_list() works. |
I am unable to reproduce this error on the develop branch: $ python
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk.book import *
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
>>> text4.collocations()
United States; fellow citizens; four years; years ago; Federal
Government; General Government; American people; Vice President; God
bless; Chief Justice; Old World; Almighty God; Fellow citizens; Chief
Magistrate; every citizen; one another; fellow Americans; Indian
tribes; public debt; foreign nations
>>> I believe this has been resolved, and this issue ought to be closed accordingly. |
Thanks @tomaarsen |
I was going through chapter 1 of the book and the collocations function returns an error. It seems like line 440 in text.py is redundant, since the collocation_list function has been introduced. I fixed the issue by rewriting the current line 440 and line 441 in text.py.
old code:
collocation_strings = [w1 + ' ' + w2 for w1, w2 in self.collocation_list(num, window_size)]*
print(tokenwrap(collocation_strings, separator="; "))
new code:
print(tokenwrap(self.collocation_list(), separator="; "))
The text was updated successfully, but these errors were encountered: