Nltk: La fonction de colocations renvoie une erreur

Créé le 15 mai 2019  ·  10Commentaires  ·  Source: nltk/nltk

J'étais en train de parcourir le chapitre 1 du livre et la fonction de collocations renvoie une erreur. Il semble que la ligne 440 de text.py soit redondante, puisque la fonction collocation_list a été introduite. J'ai résolu le problème en réécrivant la ligne 440 et la ligne 441 actuelles dans text.py.

ancien code:
collocation_strings = [w1 + '' + w2 pour w1, w2 dans self.collocation_list (num, window_size)] *
print (tokenwrap (collocation_strings, separator = ";"))

nouveau code:
print (tokenwrap (self.collocation_list (), separator = ";"))

bug goodfirstbug resolved text

Commentaire le plus utile

Également toujours des problèmes avec .collocations() , mais .collocation_list() fonctionne.

Tous les 10 commentaires

Merci @martinevanschouwenburg pour avoir soulevé le bogue!

Oui, il semble que la liste de colocalisation soit nécessaire. Pour reproduire le bogue:

$ 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)

Je vois encore cette erreur en parcourant le chapitre 1 du livre.

* Exemples d'introduction pour le livre NLTK *
Chargement de text1, ..., text9 et sent1, ..., sent9
Tapez le nom du texte ou de la phrase pour l'afficher.
Tapez: 'textes ()' ou 'sents ()' pour lister les matériaux.
texte1: Moby Dick par Herman Melville 1851
text2: Sens et sensibilité par Jane Austen 1811
text3: Le livre de la Genèse
text4: Corpus d'adresses inaugurales
text5: Chat Corpus
text6: Monty Python et le Saint Graal
texte7: Wall Street Journal
text8: Corpus de Rencontres
text9: L'homme qui était jeudi par G. K. Chesterton 1908
Traceback (dernier appel le plus récent):
Fichier "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ ptvsd_launcher.py", ligne 43, dans
main (ptvsdArgs)
Fichier "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", ligne 434, dans main
courir()
Fichier "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", ligne 312, dans run_file
runpy.run_path (cible, run_name = '__ main__')
Fichier "c: \ users \ adam \ appdata \ local \ programs \ python \ python37-32 \ Lib \ runpy.py", ligne 263, dans run_path
pkg_name = pkg_name, script_name = fname)
Fichier "c: \ users \ adam \ appdata \ local \ programs \ python \ python37-32 \ Lib \ runpy.py", ligne 96, dans _run_module_code
mod_name, mod_spec, pkg_name, script_name)
Fichier "c: \ users \ adam \ appdata \ local \ programs \ python \ python37-32 \ Lib \ runpy.py", ligne 85, dans _run_code
exec (code, run_globals)
Fichier "c: \ Users \ Adam \ Documents \ code \ python \ natlang \ natlang.py", ligne 4, dans
text4.collocations ()
Fichier "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", ligne 444, dans les colocations
w1 + "" + w2 pour w1, w2 dans self.collocation_list (num, window_size)
Fichier "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", ligne 444, dans
w1 + "" + w2 pour w1, w2 dans self.collocation_list (num, window_size)
ValueError: trop de valeurs à décompresser (attendu 2)

@networkjr Je peux également le confirmer. Peut-être que le correctif de # 2227 n'a pas encore été poussé vers PyPi?

@networkjr c'est la même chose avec le package Anaconda

Je travaille sur le livre NLTK, je suis complètement nouveau sur NLTK et assez nouveau sur Python - et j'obtiens la même erreur.

$ python
Python 3.7.2 (default, Feb 14 2019, 11:13:53) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> 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 "/Users/george/code/nltk/py3env/lib/python3.7/site-packages/nltk/text.py", line 444, in collocations
    w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
  File "/Users/george/code/nltk/py3env/lib/python3.7/site-packages/nltk/text.py", line 444, in <listcomp>
    w1 + " " + w2 for w1, w2 in self.collocation_list(num, window_size)
ValueError: too many values to unpack (expected 2)

D'après mon Pipfile.lock j'utilise NLTK 3.4.5 qui, je crois, est la version la plus récente.

Existe-t-il une solution à ce problème?

Ce problème a été corrigé sur # 2377, devrait être corrigé dans la prochaine version de NLTK bientôt.

Sinon, si vous ne pouvez pas attendre =)

pip install -U https://github.com/nltk/nltk/archive/develop.zip

J'ai toujours la même erreur après la mise à jour de cntk avec
pip install -U https://github.com/nltk/nltk/archive/develop.zip

Version actuelle de CNKT '3.4.5'

Comment puis-je y remédier?

Merci beaucoup.

Également toujours des problèmes avec .collocations() , mais .collocation_list() fonctionne.

Remplacez à la ligne 444 dans /nltk/text.py:
collocation_strings = [w1 + "" + w2 pour w1, w2 dans text.collocation_list (num, window_size)]

avec ce qui suit:
collocation_strings = [w pour w dans text.collocation_list (num, window_size)]

Pareil ici. Travailler dans le livre nltk donne une erreur pour collocations () alors que collocation_list () fonctionne.

Cette page vous a été utile?
0 / 5 - 0 notes

Questions connexes

terencen picture terencen  ·  27Commentaires

rain1024 picture rain1024  ·  22Commentaires

oxymor0n picture oxymor0n  ·  22Commentaires

53X picture 53X  ·  19Commentaires

pombredanne picture pombredanne  ·  14Commentaires