반응형
단어 중의성 해소 알고리즘 중 하나
해당하는 단어에 대한 사전(워드넷)의 설명과 주어진 문장 내에 등장한 단어의 사전에서 설명 사이의 유사도를 구한다
이때 유사도는 겹치는 단어의 개수를 구하는 방법을 사용하고, 가장 유사도가 높은 의미 선택
In [ ]:
import nltk
from nltk.corpus import wordnet as wn
for ss in wn.synsets('bass'):
print(ss, ss.definition())
Synset('bass.n.01') the lowest part of the musical range
Synset('bass.n.02') the lowest part in polyphonic music
Synset('bass.n.03') an adult male singer with the lowest voice
Synset('sea_bass.n.01') the lean flesh of a saltwater fish of the family Serranidae
Synset('freshwater_bass.n.01') any of various North American freshwater fish with lean flesh (especially of the genus Micropterus)
Synset('bass.n.06') the lowest adult male singing voice
Synset('bass.n.07') the member with the lowest range of a family of musical instruments
Synset('bass.n.08') nontechnical name for any of numerous edible marine and freshwater spiny-finned fishes
Synset('bass.s.01') having or denoting a low vocal or instrumental range
In [ ]:
def lesk(sentence,word):
from nltk.wsd import lesk
best_synset = lesk(sentence.split(),word)
print(best_synset,best_synset.definition())
sentence = 'I went fishing last weekend and I got a bass and cooked it'
word = 'bass'
lesk(sentence, word)
Synset('sea_bass.n.01') the lean flesh of a saltwater fish of the family Serranidae
레스크 알고리즘은 워드넷처럼 잘 분류된 사전이 있다면 쉽고 빠르게 중의성을 해결할 수 있지만, 사전의 정확도에 크게 의존한다는 점이 단점이다.(사전의 정확도가 떨어지면 중의성 해소 능력이 크게 떨어진다
반응형
댓글