首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nltk中的TaggedCorpusReader和UnigramTagger (python)

问nltk中的TaggedCorpusReader和UnigramTagger (python)
EN

Stack Overflow用户
提问于 2011-12-29 02:00:01
回答 1查看 1.4K关注 0票数 0

我正在尝试使用nltk以一种非常低保真的方式对新闻文章进行自动分类。我已经创建了一个与我的类别相关的词/标签对的自定义语料库(即,教师/教育、计算机/技术等)我一直在到处阅读,this question让我非常接近,但我仍然被卡住了。

根据我到目前为止的代码,我如何使用标记器来标记我的句子?

代码语言:javascript
复制
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'

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-29 03:05:46

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8659490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档