Houve alguma reorganização da base de código nltk
para os módulos Brill tagger, veja https://github.com/nltk/nltk/commits/develop/nltk/tag/brill.py
Atualmente, a demonstração do tagger Brill reside em https://github.com/nltk/nltk/blob/develop/nltk/tbl/demo.py
, portanto, no código:
import nltk
nltk.tbl.demo()
Receio que também não funcione. Recebo um erro de importação em 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'
Ei, eu não estou recebendo este erro, usando python v2.7.10. Qual versão você está usando? Esta é a minha saída:
>>> 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]
e assim por diante...
Obrigado @campionfellin por verificar.
@MrDupin você poderia nos fornecer os detalhes da sua versão para que possamos ajudá-lo?
Além disso, acho que seria bom adicionar esta demonstração a um dos unittest
em nltk/test/unit
para que as funcionalidades desta demonstração possam ser testadas nos testes automatizados de CI. Alguém está disposto a isso?
@stevenbird Também devemos alterar o código do livro online em https://github.com/nltk/nltk_book/edit/master/book/ch05.rst também.
O que @campionfellin fez funcionou. Obrigado!
Talvez o livro devesse em vez de nltk.tag.brill.demo()
ser:
from nltk.tbl import demo as brill_tagger
brill_tagger.demo()
Adicionada a demo ao unittest em #2099
O exemplo do livro deve ser resolvido por https://github.com/nltk/nltk_book/pull/204
Comentários muito úteis
O que @campionfellin fez funcionou. Obrigado!
Talvez o livro devesse em vez de
nltk.tag.brill.demo()
ser: