2010-09-13 27 views
21

मैं NLTK अजगर करने के लिए नया हूँ और मैं कुछ नमूना आवेदन जो शब्द अर्थ में कोई संदिग्धता कर सकते हैं के लिए देख रहा हूँ। मुझे खोज परिणामों में बहुत सारे एल्गोरिदम मिल गए हैं लेकिन नमूना आवेदन नहीं है। मैं बस एक वाक्य पारित करना चाहता हूं और वर्डनेट लाइब्रेरी का जिक्र करके प्रत्येक शब्द की भावना जानना चाहता हूं। धन्यवादवर्ड अर्थ में कोई संदिग्धता

मुझे PERL में एक समान मॉड्यूल मिला है। http://marimba.d.umn.edu/allwords/allwords.html क्या एनएलटीके पायथन में ऐसा मॉड्यूल मौजूद है?

+1

यहां एक पायथन कार्यान्वयन है: https: // github .com/alvations/pywsd – alvas

उत्तर

-1

हाँ, यह NLTK में Wordnet मॉड्यूल के साथ संभव है। समानता mesures जो उपकरण है जो आपके पोस्ट में उल्लेख भी NLTK Wordnet मॉड्यूल में मौजूद है में इस्तेमाल किया।

0

NLTK शब्दतंत्र का उपयोग करने की apis है। Wordnet शब्दों को synsets के रूप में रखता है। यह आपको शब्द, इसके हाइपरनेम, हाइपोनिम्स, रूट वर्ड इत्यादि पर कुछ जानकारी देगा।

"एनएलटीके 2.0 कुकबुक के साथ पायथन टेक्स्ट प्रोसेसिंग" एनएलटीके की विभिन्न विशेषताओं पर शुरू करने के लिए एक अच्छी किताब है। इसे पढ़ना, समझना और कार्यान्वित करना आसान है।

इसके अलावा, आप अन्य कागजात पर जो शब्द अर्थ में कोई संदिग्धता के लिए विकिपीडिया का उपयोग कर के बारे में बात (NLTK के दायरे के बाहर) देख सकते हैं।

7

हां, वास्तव में, a book है कि एनएलटीके टीम ने लिखा है कि वर्गीकरण पर एकाधिक अध्याय हैं और वे स्पष्ट रूप से how to use WordNet को कवर करते हैं। आप सफारी से पुस्तक का भौतिक संस्करण भी खरीद सकते हैं।

FYI करें: NLTK उनके परिचयात्मक प्रोग्रामिंग पाठ्यक्रमों में उपयोग के लिए प्राकृतिक भाषा प्रोग्रामिंग शिक्षाविदों द्वारा लिखा जाता है।

+4

जहां तक ​​मैं समझता हूं, वह अध्याय वर्गीकरण के लिए समर्पित है लेकिन यह शब्द समझ में असंबद्धता में बहुत कुछ नहीं है। – geekazoid

3

ओपी के अनुरोध के लिए एक व्यावहारिक जवाब के रूप में, यहाँ कई WSD तरीकों में से एक अजगर कार्यान्वयन कि NLTK के synset (रों) के रूप में होश देता है, https://github.com/alvations/pywsd

यह

  • Lesk एल्गोरिदम शामिल है (शामिल मूल Lesk, Lesk और सरल Lesk अनुकूलित)
  • आधारभूत एल्गोरिदम (यादृच्छिक भावना, पहली भावना, सबसे लगातार नब्ज)

यह इस तरह के रूप में इस्तेमाल किया जा सकता है:

#!/usr/bin/env python -*- coding: utf-8 -*- 

bank_sents = ['I went to the bank to deposit my money', 
'The river bank was full of dead fishes'] 

plant_sents = ['The workers at the industrial plant were overworked', 
'The plant was no longer bearing flowers'] 

print "======== TESTING simple_lesk ===========\n" 
from lesk import simple_lesk 
print "#TESTING simple_lesk() ..." 
print "Context:", bank_sents[0] 
answer = simple_lesk(bank_sents[0],'bank') 
print "Sense:", answer 
print "Definition:",answer.definition 
print 

print "#TESTING simple_lesk() with POS ..." 
print "Context:", bank_sents[1] 
answer = simple_lesk(bank_sents[1],'bank','n') 
print "Sense:", answer 
print "Definition:",answer.definition 
print 

print "#TESTING simple_lesk() with POS and stems ..." 
print "Context:", plant_sents[0] 
answer = simple_lesk(plant_sents[0],'plant','n', True) 
print "Sense:", answer 
print "Definition:",answer.definition 
print 

print "======== TESTING baseline ===========\n" 
from baseline import random_sense, first_sense 
from baseline import max_lemma_count as most_frequent_sense 

print "#TESTING random_sense() ..." 
print "Context:", bank_sents[0] 
answer = random_sense('bank') 
print "Sense:", answer 
print "Definition:",answer.definition 
print 

print "#TESTING first_sense() ..." 
print "Context:", bank_sents[0] 
answer = first_sense('bank') 
print "Sense:", answer 
print "Definition:",answer.definition 
print 

print "#TESTING most_frequent_sense() ..." 
print "Context:", bank_sents[0] 
answer = most_frequent_sense('bank') 
print "Sense:", answer 
print "Definition:",answer.definition 
print 

[बाहर]:

======== TESTING simple_lesk =========== 

#TESTING simple_lesk() ... 
Context: I went to the bank to deposit my money 
Sense: Synset('depository_financial_institution.n.01') 
Definition: a financial institution that accepts deposits and channels the money into lending activities 

#TESTING simple_lesk() with POS ... 
Context: The river bank was full of dead fishes 
Sense: Synset('bank.n.01') 
Definition: sloping land (especially the slope beside a body of water) 

#TESTING simple_lesk() with POS and stems ... 
Context: The workers at the industrial plant were overworked 
Sense: Synset('plant.n.01') 
Definition: buildings for carrying on industrial labor 

======== TESTING baseline =========== 
#TESTING random_sense() ... 
Context: I went to the bank to deposit my money 
Sense: Synset('deposit.v.02') 
Definition: put into a bank account 

#TESTING first_sense() ... 
Context: I went to the bank to deposit my money 
Sense: Synset('bank.n.01') 
Definition: sloping land (especially the slope beside a body of water) 

#TESTING most_frequent_sense() ... 
Context: I went to the bank to deposit my money 
Sense: Synset('bank.n.01') 
Definition: sloping land (especially the slope beside a body of water) 
11

हाल ही में , pywsd कोड का हिस्सामें NLTK के 'खून बह रहा किनारे संस्करण में स्थलांतरित कर दिया गया हैमॉड्यूल, कोशिश:

>>> 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' 

बेहतर WSD प्रदर्शन के लिए, NLTK मॉड्यूल के बजाय pywsd पुस्तकालय का उपयोग करें।आम तौर पर simple_lesk()pywsd से lesk से बेहतर है। मैं NLTK मॉड्यूल को जितना संभव हो सके अद्यतन करने की कोशिश करूंगा।


में क्रिस स्पेंसर्स टिप्पणी का जवाब है, Lesk एल्गोरिदम की सीमाओं कृपया ध्यान दें। मैं बस एल्गोरिदम का सटीक कार्यान्वयन कर रहा हूं। यह एक चांदी की गोली, http://en.wikipedia.org/wiki/Lesk_algorithm

इसके अलावा कृपया ध्यान दें कि नहीं है, हालांकि:

lesk("My cat likes to eat mice.", "cat", "n") 

आप सही जवाब है, तो आप max_similarity() की pywsd कार्यान्वयन का उपयोग कर सकते देना नहीं है:

>>> 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' 

@ क्रिस, अगर आप एक पायथन setup.py चाहते हैं, तो बस एक विनम्र अनुरोध करें, मैं इसे लिखूंगा ...

+1

दुर्भाग्य से, सटीकता बहुत ईश्वर भयानक है। 'lesk ("मेरी बिल्ली चूहों को खाना पसंद करती है।", "बिल्ली", "एन")' => 'सिंसेट (' computerized_tomography.n.01 ') '। और pywsd में एक स्थापित स्क्रिप्ट भी नहीं है ... – Cerin

+1

प्रिय क्रिस, क्या आपने lesk के अन्य रूपों की कोशिश की है? Esp। 'simple_lesk()' या 'adapted_lesk'? मूल lesk समस्याओं के लिए जाना जाता है, इसलिए पैकेज में उपलब्ध अन्य समाधान। http://en.wikipedia.org/wiki/Lesk_algorithm। इसके अलावा, मैं अपने खाली समय के दौरान बनाए रख रहा हूं और यह नहीं है कि मैं एक जीवित रहने के लिए क्या करता हूं ... – alvas

+1

हां, मैंने आपके पैकेज में लेस्क के हर संस्करण की कोशिश की, और मेरे नमूने कॉर्पस पर कोई भी काम नहीं किया। मुझे एक संस्करण बनाना था जो सकारात्मक परिणामों के मुट्ठी भरने के लिए शब्द से जुड़े सभी हाइपोनिम्स और शब्दकोषों से चमक का इस्तेमाल करता था, लेकिन फिर भी यह केवल 15% सटीक था। यह आपका कोड नहीं है, यह लेस्क है कि समस्या है। यह सिर्फ एक विश्वसनीय ह्युरिस्टिक नहीं है। – Cerin

संबंधित मुद्दे