Nltk: Brill Tagger Demo defekt

Erstellt am 9. Sept. 2017  ·  6Kommentare  ·  Quelle: nltk/nltk

Mir ist aufgefallen, dass im Buch (Abschnitt 6, Beispiel 6.1) der vorgeschlagene Code lautet: nltk.tag.brill.demo()

Wenn ich dies ausführe, erhalte ich die folgende Fehlermeldung: AttributeError: module 'nltk.tag.brill' has no attribute 'demo'

Übersehe ich etwas?

book resolved tests

Hilfreichster Kommentar

Was @campionfellin getan hat, hat funktioniert. Danke!

Vielleicht sollte das Buch statt nltk.tag.brill.demo() lauten:

from nltk.tbl import demo as brill_tagger
brill_tagger.demo()

Alle 6 Kommentare

Es gab eine gewisse Reorganisation der nltk -Codebasis für die Brill-Tagger-Module, siehe https://github.com/nltk/nltk/commits/develop/nltk/tag/brill.py

Derzeit befindet sich die Brill-Tagger-Demo in https://github.com/nltk/nltk/blob/develop/nltk/tbl/demo.py , also im Code:

import nltk
nltk.tbl.demo()

Ich fürchte, das geht auch nicht. Ich erhalte einen Importfehler bei map_tag :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Compilers\Python\lib\site-packages\nltk\__init__.py", line 128, in <module>
    from nltk.chunk import *
  File "C:\Compilers\Python\lib\site-packages\nltk\chunk\__init__.py", line 157, in <module>
    from nltk.chunk.api import ChunkParserI
  File "C:\Compilers\Python\lib\site-packages\nltk\chunk\api.py", line 15, in <module>
    from nltk.chunk.util import ChunkScore
  File "C:\Compilers\Python\lib\site-packages\nltk\chunk\util.py", line 13, in <module>
    from nltk.tag.mapping import map_tag
  File "C:\Compilers\Python\lib\site-packages\nltk\tag\__init__.py", line 68, in <module>
    from nltk.tag.brill         import BrillTagger
  File "C:\Compilers\Python\lib\site-packages\nltk\tag\brill.py", line 16, in <module>
    from nltk.tbl import Feature, Template
  File "C:\Compilers\Python\lib\site-packages\nltk\tbl\__init__.py", line 29, in <module>
    from nltk.tbl.demo import demo
  File "C:\Compilers\Python\lib\site-packages\nltk\tbl\demo.py", line 18, in <module>
    from nltk.corpus import treebank
  File "C:\Compilers\Python\lib\site-packages\nltk\corpus\__init__.py", line 66, in <module>
    from nltk.corpus.reader import *
  File "C:\Compilers\Python\lib\site-packages\nltk\corpus\reader\__init__.py", line 59, in <module>
    from nltk.corpus.reader.tagged import *
  File "C:\Compilers\Python\lib\site-packages\nltk\corpus\reader\tagged.py", line 18, in <module>
    from nltk.tag import str2tuple, map_tag
ImportError: cannot import name 'map_tag'

Hey, ich bekomme diesen Fehler nicht, wenn ich Python v2.7.10 verwende. Welche Version verwenden Sie? Dies ist meine Ausgabe:

>>> import nltk
>>> from nltk.tbl import demo as issue1828
>>> issue1828.demo()
Loading tagged data from treebank...
Read testing data (200 sents/5251 wds)
Read training data (800 sents/19933 wds)
Read baseline data (800 sents/19933 wds) [reused the training set]
Trained baseline tagger
    Accuracy on test set: 0.8345
Training tbl tagger...
TBL train (fast) (seqs: 800; tokens: 19933; tpls: 24; min score: 3; min acc: None)
Finding initial useful rules...
    Found 12960 useful rules.

           B      |
   S   F   r   O  |        Score = Fixed - Broken
   c   i   o   t  |  R     Fixed = num tags changed incorrect -> correct
   o   x   k   h  |  u     Broken = num tags changed correct -> incorrect
   r   e   e   e  |  l     Other = num tags changed incorrect -> incorrect
   e   d   n   r  |  e
------------------+-------------------------------------------------------
  23  23   0   0  | POS->VBZ if Pos:PRP@[-2,-1]
  16  17   1   0  | NN->VB if Pos:-NONE-@[-2] & Pos:TO@[-1]
  15  16   1   0  | VBN->VBD if Pos:PRP@[-1]
  12  12   0   0  | VBP->VB if Pos:MD@[-2,-1]

und so weiter...

Danke @campionfellin für die Bestätigung.

@MrDupin könnten Sie uns Ihre Versionsdetails mitteilen, damit wir Ihnen helfen können?

Außerdem fände ich es gut, diese Demo zu einem der unittest in nltk/test/unit hinzuzufügen, damit die Funktionalitäten dieser Demo in den automatisierten CI-Tests getestet werden können. Jemand Bock darauf?

@stevenbird Wir sollten auch den Code für das Online-Buch auf https://github.com/nltk/nltk_book/edit/master/book/ch05.rst ändern.

Was @campionfellin getan hat, hat funktioniert. Danke!

Vielleicht sollte das Buch statt nltk.tag.brill.demo() lauten:

from nltk.tbl import demo as brill_tagger
brill_tagger.demo()

Demo zu Unittest auf #2099 hinzugefügt

Das Buchbeispiel sollte von https://github.com/nltk/nltk_book/pull/204 gelöst werden

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

chaseireland picture chaseireland  ·  3Kommentare

BLKSerene picture BLKSerene  ·  4Kommentare

alvations picture alvations  ·  4Kommentare

alvations picture alvations  ·  4Kommentare

alvations picture alvations  ·  4Kommentare