使用 nltk 没有上下文的词性标记

2024-03-12

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

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

>>> wn.synsets('says')

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

如果您想尝试在没有上下文的情况下进行标记,那么您正在寻找某种一元标记器,又名looup tagger. 一元标记器仅根据给定单词的标签的频率来标记单词。因此它避免了上下文启发法,但是对于任何标记任务,您都必须有数据。对于一元组,您需要带注释的数据来训练它。请参阅lookup tagger在 nltk 教程中http://nltk.googlecode.com/svn/trunk/doc/book/ch05.html 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 中使用引理频率,请参阅如何在 NLTK 中获取同义词集的词网语义频率? https://stackoverflow.com/questions/15551195/how-to-get-the-wordnet-sense-frequency-of-a-synset-in-nltk。这些频率基于 SemCor 语料库 (http://www.cse.unt.edu/~rada/downloads.html http://www.cse.unt.edu/~rada/downloads.html)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 nltk 没有上下文的词性标记 的相关文章

随机推荐