Nltk: Brill Tagger 演示坏了

创建于 2017-09-09  ·  6评论  ·  资料来源: nltk/nltk

我注意到在本书(第 6 节,示例 6.1)中,建议的代码是: nltk.tag.brill.demo()

当我运行它时,我收到以下错误: AttributeError: module 'nltk.tag.brill' has no attribute 'demo'

我错过了什么吗?

book resolved tests

最有用的评论

@campionfellin所做的工作。 谢谢!

也许这本书应该而不是nltk.tag.brill.demo()是:

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

所有6条评论

Brill 标记器模块的nltk代码库正在进行一些重组,请参阅https://github.com/nltk/nltk/commits/develop/nltk/tag/brill.py

目前 Brill 标注器演示位于https://github.com/nltk/nltk/blob/develop/nltk/tbl/demo.py中,因此在代码中:

import nltk
nltk.tbl.demo()

恐怕这也行不通。 我在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'

嘿,我没有收到这个错误,使用 python v2.7.10。 你用的是什么版本? 这是我的输出:

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

等等...

感谢@campionfellin验证。

@MrDupin您能否向我们提供您的版本详细信息以便我们为您提供帮助?

此外,我认为最好将此演示添加到nltk/test/unit中的unittest之一,以便可以在自动化 CI 测试中测试此演示的功能。 有人愿意吗?

@stevenbird我们也应该在https://github.com/nltk/nltk_book/edit/master/book/ch05.rst上更改在线图书的代码。

@campionfellin所做的工作。 谢谢!

也许这本书应该而不是nltk.tag.brill.demo()是:

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

在 #2099 的单元测试中添加了演示

书籍示例应由https://github.com/nltk/nltk_book/pull/204解决

此页面是否有帮助?
0 / 5 - 0 等级