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

标签 python nlp nltk

是否有一种简单的方法可以使用 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

中训练/测试 unigram 标注器的另一种方法
>>> 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/

相关文章:

python - 在图像上找到一个 3x3 的滑动窗口

artificial-intelligence - 多语言数据的特征选择和无监督学习+机器学习算法选择

machine-learning - NLP 中的字符 n 元语法与单词特征

python - "[w for w in word_tokens if..."在 Python 中是什么意思?

python - 如何在python pptx中更改标题颜色

python - 我无法在我的 tkinter 图像上显示文本

python - SQLAlchemy 一对一关系创建多行

python - 如何在 xml 文件中搜索单词并在 python 中打印它

nlp - 用 NLTK 检查英语语法

python - 为什么 CoreNLP ner tagger 和 ner tagger 将分开的数字连接在一起?