Nltk: Brill Tagger Demo Broken

Created on 9 Sep 2017  ·  6Comments  ·  Source: nltk/nltk

I noticed that in the book (section 6, example 6.1), the suggested code is: nltk.tag.brill.demo()

When I run this I get the following error: AttributeError: module 'nltk.tag.brill' has no attribute 'demo'

Am I missing something?

book resolved tests

Most helpful comment

What @campionfellin did worked. Thanks!

Maybe the book should instead of nltk.tag.brill.demo() be:

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

All 6 comments

There was some reorganization of the nltk code base going on for the Brill tagger modules, see https://github.com/nltk/nltk/commits/develop/nltk/tag/brill.py

Currently the Brill tagger demo resides in https://github.com/nltk/nltk/blob/develop/nltk/tbl/demo.py, so in code:

import nltk
nltk.tbl.demo()

I am afraid that doesn't work either. I get an import error on 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, I am not getting this error, using python v2.7.10. What version are you using? This is my output:

>>> 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]

and so on...

Thanks @campionfellin for verifying.

@MrDupin could you provide us with your version details so that we can help you?

Additionally, I think it would be good to add this demo to one of the unittest in nltk/test/unit so that the functionalities of this demo can be tested out in the automated CI tests. Anybody up for this?

@stevenbird We should also change the code for the online book too on https://github.com/nltk/nltk_book/edit/master/book/ch05.rst too.

What @campionfellin did worked. Thanks!

Maybe the book should instead of nltk.tag.brill.demo() be:

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

Added the demo to the unittest on #2099

Book example should be resolved by https://github.com/nltk/nltk_book/pull/204

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeryini picture jeryini  ·  5Comments

alvations picture alvations  ·  4Comments

talbaumel picture talbaumel  ·  4Comments

mwess picture mwess  ·  5Comments

chaseireland picture chaseireland  ·  3Comments