Nltk: la función de colocaciones devuelve un error

Creado en 15 may. 2019  ·  10Comentarios  ·  Fuente: nltk/nltk

Estaba revisando el capítulo 1 del libro y la función de colocaciones devuelve un error. Parece que la línea 440 en text.py es redundante, ya que se introdujo la función collocation_list. Solucioné el problema reescribiendo la línea actual 440 y la línea 441 en text.py.

código antiguo:
collocation_strings = [w1 + '' + w2 para w1, w2 en self.collocation_list (num, window_size)] *
print (tokenwrap (collocation_strings, separator = ";"))

nuevo código:
print (tokenwrap (self.collocation_list (), separator = ";"))

bug goodfirstbug resolved text

Comentario más útil

También sigo teniendo problemas con .collocations() , pero .collocation_list() funciona.

Todos 10 comentarios

¡Gracias @martinevanschouwenburg por

Sí, parece que se necesita la lista de colocación. Para replicar el error:

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

Sigo viendo este error también cuando reviso el capítulo 1 del libro.

* Ejemplos introductorios del libro NLTK *
Cargando texto1, ..., texto9 y enviado1, ..., enviado9
Escriba el nombre del texto u oración para verlo.
Escriba: 'textos ()' o 'sents ()' para enumerar los materiales.
texto1: Moby Dick por Herman Melville 1851
text2: Sentido y sensibilidad por Jane Austen 1811
text3: El libro del Génesis
text4: Corpus del discurso inaugural
text5: Chat Corpus
text6: Monty Python y el Santo Grial
text7: Wall Street Journal
text8: Corpus de contactos
text9: El hombre que fue jueves de G. K. Chesterton 1908
Rastreo (llamadas recientes más última):
Archivo "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ ptvsd_launcher.py", línea 43, en
principal (ptvsdArgs)
Archivo "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", línea 434, en main
correr()
Archivo "c: \ Users \ Adam.vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ lib \ python \ ptvsd__main __. Py", línea 312, en run_file
runpy.run_path (destino, run_name = '__ main__')
Archivo "c: \ users \ adam \ appdata \ local \ programmes \ python \ python37-32 \ Lib \ runpy.py", línea 263, en run_path
pkg_name = pkg_name, script_name = fname)
Archivo "c: \ usuarios \ adam \ appdata \ local \ programas \ python \ python37-32 \ Lib \ runpy.py", línea 96, en _run_module_code
mod_name, mod_spec, pkg_name, script_name)
Archivo "c: \ users \ adam \ appdata \ local \ programas \ python \ python37-32 \ Lib \ runpy.py", línea 85, en _run_code
exec (código, run_globals)
Archivo "c: \ Users \ Adam \ Documents \ code \ python \ natlang \ natlang.py", línea 4, en
text4.collocations ()
Archivo "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", línea 444, en colocaciones
w1 + "" + w2 para w1, w2 en self.collocation_list (num, window_size)
Archivo "C: \ Users \ Adam.virtualenvs \ natlang-9ek-vNym \ lib \ site-packages \ nltk \ text.py", línea 444, en
w1 + "" + w2 para w1, w2 en self.collocation_list (num, window_size)
ValueError: demasiados valores para descomprimir (esperado 2)

@networkjr Yo también puedo confirmarlo. ¿Quizás la solución en # 2227 aún no se ha enviado a PyPi?

@networkjr es lo mismo con el paquete Anaconda

Estoy trabajando en el libro NLTK, soy completamente nuevo en NLTK y bastante nuevo en Python, y recibo el mismo error.

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

Según mi Pipfile.lock , estoy usando NLTK 3.4.5, que creo que es la versión más reciente.

¿Hay alguna solución para este problema?

Esto se ha corregido en el n. ° 2377, debería corregirse pronto en la próxima versión de NLTK.

De lo contrario, si no puede esperar =)

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

Todavía tengo el mismo error después de actualizar cntk con
pip install -U https://github.com/nltk/nltk/archive/develop.zip

Versión actual de cnkt '3.4.5'

¿Cómo puedo arreglarlo?

Muchas gracias.

También sigo teniendo problemas con .collocations() , pero .collocation_list() funciona.

Reemplazar en la línea 444 en /nltk/text.py:
collocation_strings = [w1 + "" + w2 para w1, w2 en text.collocation_list (num, window_size)]

con lo siguiente:
collocation_strings = [w para w en text.collocation_list (num, window_size)]

Igual que aquí. Trabajar con el libro nltk da error para colocaciones () mientras que collocation_list () funciona.

¿Fue útil esta página
0 / 5 - 0 calificaciones

Temas relacionados

libingnan54321 picture libingnan54321  ·  3Comentarios

stevenbird picture stevenbird  ·  3Comentarios

vezeli picture vezeli  ·  3Comentarios

alvations picture alvations  ·  4Comentarios

alvations picture alvations  ·  4Comentarios