我尝试在 nltk 中制作词性(或 POS)标记器,但我无法使用退避让它在一段时间内为多个 ngram 标记器工作。我读到你使用更多的标签来获得更高的分数,但这对我不起作用。我希望它首先使用更多的单词,然后使用更少的单词。我是这样试的
import nltk
from nltk.corpus import brown
#sentence = brown.sents(categories = "news")
trains = brown.tagged_sents(categories = "news")
from nltk import NgramTagger
fortest = ["hi", "how","are", "you"]
tagger = (nltk.NgramTagger (n, trains, backoff=n-1) for n in range (3))
print tagger.tag(fortest)
但它给了我错误 AttributeError: 'generator' object has no attribute 'tag'
所以我没有列出清单:
for n in range(3):
tagger = nltk.NgramTagger(n, trains, backoff=n-1)
但后来我得到:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/tag/sequential.py", line 271, in __init__
ContextTagger.__init__(self, model, backoff)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/tag/sequential.py", line 121, in __init__
SequentialBackoffTagger.__init__(self, backoff)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/tag/sequential.py", line 46, in __init__
self._taggers = [self] + backoff._taggers AttributeError: 'int' object has no attribute '_taggers'
请帮助我,因为我是新来做 python 的。