我正在尝试使用nltk以一种非常低保真的方式对新闻文章进行自动分类。我已经创建了一个与我的类别相关的词/标签对的自定义语料库(即,教师/教育、计算机/技术等)我一直在到处阅读,this question让我非常接近,但我仍然被卡住了。
根据我到目前为止的代码,我如何使用标记器来标记我的句子?
import nltk
# Loads my custom word/tag corpus
from nltk.corpus.reader import TaggedCorpusReader
reader = TaggedCorpusReader('taggers','.*')
#Sets up the UnigramTagger
default_tagger = nltk.data.load(nltk.tag._POS_TAGGER)
tagger = nltk.tag.UnigramTagger(model=reader.tagged_words(), backoff=default_tagger)
#Sample content
sent = 'The students went to school to ask their teacher what the homework for the day was but she told them to check their email.'
tokens = nltk.tokenize.word_tokenize(sent)
# Sad Panda
tagged = tagger.tag(tokens)
# ^ produces AttributeError: 'ConcatenatedCorpusView' object has no attribute 'get'这也很可能是一种糟糕的方式来做我想要做的事情,但对于第一次运行它似乎足够好了。提前谢谢。
发布于 2011-12-29 03:05:46
标记器用于词性标记,而不是文本分类。看看路透社的语料库-它使用一个类别文件将新闻文章分类为多个类别。然后查看nltk.classify模块并阅读有关如何训练文本分类器的信息。
https://stackoverflow.com/questions/8659490
复制相似问题