是否有一种简单的方法可以使用 nltk.没有上下文 来确定给定单词最可能的词性标记。或者如果不使用任何其他工具/数据集。
我尝试使用 wordnet,但似乎 sysnet 不是按可能性排序的。
>>> wn.synsets('says')
[Synset('say.n.01'), Synset('state.v.01'), ...]
最佳答案
如果您想尝试在没有上下文的情况下进行标记,您正在寻找某种 unigram 标记器,又名 loop 标记器
。 unigram 标记器仅根据给定单词的标记频率来标记单词。因此它避免了上下文启发式,但是对于任何标记任务,您都必须有数据。对于 unigrams,您需要带注释的数据来训练它。请参阅 nltk 教程中的 lookup tagger
http://nltk.googlecode.com/svn/trunk/doc/book/ch05.html .
下面是在 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 进行词性标记,因为太多的词在 wordnet 中仍然没有条目。但是您可以看一下在 wordnet 中使用引理频率,请参阅 How to get the wordnet sense frequency of a synset in NLTK? .这些频率基于 SemCor 语料库 ( http://www.cse.unt.edu/~rada/downloads.html )
关于python - 使用 nltk 的没有上下文的词性标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18999952/