我尝试将我自己的简单自定义标记器与nltk默认标记器相结合,在本例中是感知器标记器。在
我的代码如下(基于this answer):
import nltk.tag, nltk.data
default_tagger = nltk.data.load(nltk.tag._POS_TAGGER)
model = {'example_one': 'VB' 'example_two': 'NN'}
tagger = nltk.tag.UnigramTagger(model=model, backoff=default_tagger)
但是,这会产生以下错误:
^{pr2}$我试图通过将默认标记符更改为:
from nltk.tag.perceptron import PerceptronTagger
default_tagger = PerceptronTagger()
但是我得到了以下错误:
File "nltk_test.py", line 26, in <module>
tagger = nltk.tag.UnigramTagger(model=model, backoff=default_tagger)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/tag/sequential.py", line 340, in __init__
backoff, cutoff, verbose)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/tag/sequential.py", line 284, in __init__
ContextTagger.__init__(self, model, backoff)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/tag/sequential.py", line 125, in __init__
SequentialBackoffTagger.__init__(self, backoff)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/tag/sequential.py", line 50, in __init__
self._taggers = [self] + backoff._taggers
AttributeError: 'PerceptronTagger' object has no attribute '_taggers'
纵观nltk.tag
documentation,似乎{_pos_tag
或{
快速回答:现在使用nltk3.0.1
pip install nltk==3.0.1
更好的答案是:他们去年9月改变了treebank标签,它有很多其他的影响(我们目前固定在3.0.1上,因为新标签至少对我们的需求更差)。在
这似乎有效,但我不确定代码的正确性:
尝试以下自定义标记:
使用自定义标记定义模型:
^{pr2}$输出:
相关问题 更多 >
编程相关推荐