4

有没有一种简单的方法可以在没有上下文的情况下使用 nltk确定给定单词最可能的词性标签。或者,如果不使用任何其他工具/数据集。

我尝试使用 wordnet,但似乎系统网不是按可能性排序的。

>>> wn.synsets('says')

[Synset('say.n.01'), Synset('state.v.01'), ...]
4

1 回答 1

6

如果您想尝试在没有上下文的情况下进行标记,那么您正在寻找某种 unigram 标记器,也就是looup tagger. 一元标记器仅根据给定单词的标记频率来标记单词。因此它避免了上下文启发式,但是对于任何标记任务,您都必须有数据。对于一元组,您需要带注释的数据来训练它。请参阅lookup taggernltk 教程http://nltk.googlecode.com/svn/trunk/doc/book/ch05.html

下面是另一种训练/测试 unigram 标记器的方法NLTK

>>> from nltk.corpus import brown
>>> from nltk import UnigramTagger as ut
>>> brown_sents = brown.tagged_sents()
# Split the data into train and test sets.
>>> train = int(len(brown_sents)*90/100) # use 90% for training
# Trains the tagger
>>> uni_tag = ut(brown_sents[:train]) # this will take some time, ~1-2 mins
# Tags a random sentence
>>> uni_tag.tag ("this is a foo bar sentence .".split())
[('this', 'DT'), ('is', 'BEZ'), ('a', 'AT'), ('foo', None), ('bar', 'NN'), ('sentence', 'NN'), ('.', '.')]
# Test the taggers accuracy.
>>> uni_tag.evaluate(brown_sents[train+1:]) # evaluate on 10%, will also take ~1-2 mins
0.8851469586629643

我不建议使用 WordNet 进行 pos 标记,因为在 wordnet 中仍然没有条目的单词太多了。但是您可以看看在 wordnet 中使用引理频率,请参阅How to get the wordnet sense frequency of a synset in NLTK? . 这些频率基于 SemCor 语料库 ( http://www.cse.unt.edu/~rada/downloads.html )

于 2013-09-25T09:03:56.930 回答