我正在尝试将自己的简单自定义标记器与nltk默认标记器(在这种情况下是感知器标记器)结合起来。
我的代码如下(基于this answer):
然而,这会出现以下错误:
但是我遇到了以下错误:
我的代码如下(基于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)
然而,这会出现以下错误:
File "nltk_test.py", line 24, in <module>
default_tagger = nltk.data.load(nltk.tag._POS_TAGGER)
AttributeError: 'module' object has no attribute '_POS_TAGGER'
我尝试通过将默认标记器更改为以下内容来解决此问题:
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'
在查看文档时,似乎_POS_TAGGER
已经不存在了。然而将其改为_pos_tag
或pos_tag
也没有起作用。
'example_three'
时,tag
函数会出现错误:site-packages/nltk/tag/sequential.py", line 61, in tag tags.append(self.tag_one(tokens, i, tags)) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/tag/sequential.py", line 81, in tag_one tag = tagger.choose_tag(tokens, index, history) AttributeError: 'PerceptronTagger' object has no attribute 'choose_tag'
- freefall