NLTK Python中的词义歧义消歧

the*_*ers 21 python nltk

我是NLTK Python的新手,我正在寻找一些可以进行词义消歧的示例应用程序.我在搜索结果中有很多算法,但没有示例应用程序.我只想传递一个句子,并希望通过引用wordnet库来了解每个单词的含义.谢谢

我在PERL中找到了一个类似的模块.http://marimba.d.umn.edu/allwords/allwords.html NLTK Python中是否有这样的模块?

alv*_*vas 12

最近,部分pywsd代码已被移植到NLTK' wsd.py模块中的最新版本中,请尝试:

>>> from nltk.wsd import lesk
>>> sent = 'I went to the bank to deposit my money'
>>> ambiguous = 'bank'
>>> lesk(sent, ambiguous)
Synset('bank.v.04')
>>> lesk(sent, ambiguous).definition()
u'act as the banker in a game or in gambling'
Run Code Online (Sandbox Code Playgroud)

为了获得更好的WSD性能,请使用pywsd库而不是NLTK模块.在一般情况下,simple_lesk()pywsd确实优于leskNLTK.NLTK当我有空时,我会尝试尽可能多地更新模块.


在回应Chris Spencer的评论时,请注意Lesk算法的局限性.我只是给出了算法的准确实现.它不是一个银弹,http://en.wikipedia.org/wiki/Lesk_algorithm

另请注意,尽管如此:

lesk("My cat likes to eat mice.", "cat", "n")
Run Code Online (Sandbox Code Playgroud)

不给你正确的答案,你可以使用pywsd实施max_similarity():

>>> from pywsd.similarity import max_similiarity
>>> max_similarity('my cat likes to eat mice', 'cat', 'wup', pos='n').definition 
'feline mammal usually having thick soft fur and no ability to roar: domestic cats; wildcats'
>>> max_similarity('my cat likes to eat mice', 'cat', 'lin', pos='n').definition 
'feline mammal usually having thick soft fur and no ability to roar: domestic cats; wildcats'
Run Code Online (Sandbox Code Playgroud)

@Chris,如果你想要一个python setup.py,只是做一个礼貌的请求,我会写它...


小智 7

请参阅http://jaganadhg.freeflux.net/blog/archive/2010/10/16/wordnet-sense-similarity-with-nltk-some-basics.html

  • 这个链接已经死了.你能提供一个工作吗? (2认同)

Ind*_*ing 7

是的,事实上,有一本书是NLTK团队编写的,其中有多章分类,并明确涵盖了如何使用WordNet.您还可以从Safari购买该书的实际版本.

仅供参考:NLTK由自然语言程序设计学者编写,用于他们的入门编程课程.

  • 据我所知,该章专门用于分类,但它并不是很有意义的消歧. (4认同)

小智 -1

是的,可以使用 NLTK 中的 wordnet 模块。您帖子中提到的工具中使用的相似性度量也存在于 NLTK wordnet 模块中。