What Is Word Sense Disambiguation? Choose Meaning from Context
How WSD maps an ambiguous word to a sense, with an NLTK and WordNet baseline and its limits.
Word sense disambiguation (WSD) selects which meaning of an ambiguous word is intended in context. “Bank” can mean a financial institution or a river’s edge. A WSD system maps that occurrence to a sense in an inventory such as WordNet. This example uses Lesk to choose among noun senses by overlap between context words and definitions.
import nltk
nltk.download("wordnet")
from nltk.corpus import wordnet as wn
from nltk.wsd import lesk
context = "I went to the bank to deposit money".split()
candidates = wn.synsets("bank", pos=wn.NOUN)
sense = lesk(context, "bank", pos="n", synsets=candidates)
if sense is not None:
print(sense.name(), sense.definition())Lesk selects the candidate with greatest word overlap between context and WordNet definition; it does not deeply understand sentence meaning. This illustrative code was not run. Install NLTK and WordNet data. Results depend on the sense inventory and granularity; evaluate against a most-frequent-sense baseline on a fixed split. WSD chooses predefined senses, not new ones.