Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 2 — Word Sense Disambiguation (WSD)

Lesson 19 of 39 in the free Natural Language Processing notes on Siksha Sarovar, written by Rohit Jangra.

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

ApproachIdeaExample
Knowledge-basedUses a lexical resource like WordNetLesk algorithm
SupervisedTrains a classifier on manually sense-tagged dataNaïve Bayes / SVM with context features (Unit 3)
UnsupervisedClusters word occurrences by similar context, without labeled dataWord-sense induction
Modern/contextual embeddingsA word's embedding already varies by context (e.g. BERT)The "bank" vector differs across sentences automatically

Why WSD Matters Downstream

ApplicationImpact of unresolved ambiguity
Machine translation"bank" mistranslated as riverbank when financial sense was meant
Information retrievalSearch for "python" returns snake articles instead of programming ones
Question answeringWrong sense → wrong/irrelevant answer retrieved
Text-to-speechSome 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.