Word Sense Disambiguation (WSD)
Word Sense Disambiguation (WSD) is the task of determining which meaning (sense) of a word is intended, given the context it appears in — the classic example being the word "bank".
sentence1 = "I deposited cash at the bank." # financial institution
sentence2 = "We sat on the bank of the river." # sloped land beside water
sentence3 = "The pilot had to bank the aircraft." # to tilt/turn
WSD is where the lexical ambiguity problem from Unit 1's introduction is finally solved computationally.
WordNet — A Lexical Database of Word Senses
WordNet groups English words into sets of synonyms called synsets, each representing one distinct sense, linked by semantic relations (hypernym, hyponym, etc.).
from nltk.corpus import wordnet as wn
for syn in wn.synsets('bank'):
print(syn.name(), "-", syn.definition())
# bank.n.01 - sloping land beside a body of water
# depository_financial_institution.n.01 - a financial institution ...
# bank.n.03 - a long ridge or pile
# bank.n.04 - an arrangement of similar objects in a row
# ...
# bank.v.01 - tip laterally
# ...
The Lesk Algorithm — Classic Dictionary-Based WSD
The Lesk algorithm disambiguates a word by picking the sense whose dictionary definition (gloss) has the highest word overlap with the words in the surrounding context.
Context: "I deposited cash at the bank."
Context words: {deposited, cash}
Sense 1 gloss: "sloping land beside a body of water" -> overlap = 0
Sense 2 gloss: "a financial institution that accepts deposits" -> overlap = 1 (deposit)
Winner: Sense 2 (financial institution)
from nltk.wsd import lesk
from nltk.tokenize import word_tokenize
sentence = "I deposited cash at the bank."
tokens = word_tokenize(sentence)
sense = lesk(tokens, 'bank')
print(sense, "-", sense.definition())
# depository_financial_institution.n.01 - a financial institution that accepts deposits
# and channels the money into lending activities
sentence2 = "We sat on the bank of the river and watched the sunset."
tokens2 = word_tokenize(sentence2)
sense2 = lesk(tokens2, 'bank')
print(sense2, "-", sense2.definition())
# bank.n.01 - sloping land (especially the slope beside a body of water)
WSD Approaches
| Approach | Idea | Example |
|---|---|---|
| Knowledge-based | Uses a lexical resource like WordNet | Lesk algorithm |
| Supervised | Trains a classifier on manually sense-tagged data | Naïve Bayes / SVM with context features (Unit 3) |
| Unsupervised | Clusters word occurrences by similar context, without labeled data | Word-sense induction |
| Modern/contextual embeddings | A word's embedding already varies by context (e.g. BERT) | The "bank" vector differs across sentences automatically |
Why WSD Matters Downstream
| Application | Impact of unresolved ambiguity |
|---|---|
| Machine translation | "bank" mistranslated as riverbank when financial sense was meant |
| Information retrieval | Search for "python" returns snake articles instead of programming ones |
| Question answering | Wrong sense → wrong/irrelevant answer retrieved |
| Text-to-speech | Some ambiguous words are pronounced differently by sense ("bass" the fish vs "bass" the instrument) |
WSD connects directly back to the lexical and semantic levels of language processing introduced in Unit 1 — it is the concrete algorithmic solution to lexical ambiguity.