【问题标题】:TaggedCorpusReader and UnigramTagger in nltk (python)nltk (python) 中的 TaggedCorpusReader 和 UnigramTagger
【发布时间】:2011-12-29 03:05:45
【问题描述】:

我正在尝试使用 nltk 以非常低保真的方式对新闻文章进行自动分类。我创建了一个与我的类别相关的单词/标签对的自定义语料库(即教师/EDU、计算机/技术等)我一直在阅读,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'

这也很可能是一种糟糕的方式来做我想做的事情,但对于第一次运行来说似乎已经足够了。提前致谢。

【问题讨论】:

    标签: python nltk


    【解决方案1】:

    标记器用于词性标记,而不是文本分类。查看 reuters 语料库 - 它使用类别文件将新闻文章分类为多个类别。然后查看 nltk.classify 模块并阅读如何训练文本分类器。

    【讨论】:

    • 感谢雅各布,您为我指明了正确的方向。术语是找到正确路径的关键。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多