Information Technology is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Word sense disambiguation

Word sense disambiguation (WSD) is the problem of choosing the correct meaning (sense) of an ambiguous word using its context; engineers use WSD in search, information extraction, machine translation and question answering.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

WSD (word sense disambiguation) is used when a system must choose the correct meaning of an ambiguous word from several possibilities. Engineers use WSD in search engines (to return relevant documents), machine translation (to choose correct target words), information extraction and question answering (to interpret entities and relations correctly).

Key ideas

  • Context is the surrounding text used to decide sense; usually a window of n words or the whole sentence/document.

  • Categories of WSD approaches (with assumptions):

    1. Supervised WSD — assume you have labelled training data (instances annotated with senses). Learn a classifier that maps features of context to senses. Assumption: training distribution ≈ test distribution. Common models: Naive Bayes, maximum entropy, SVM, neural nets.
    2. Knowledge-based WSD — assume access to dictionaries, lexical databases (WordNet) and no labelled examples. Use overlaps between glosses, graph structure, or semantic relations. Example: Lesk algorithm, graph-based PageRank-style methods.
    3. Unsupervised / clustering WSD — assume no labelled senses and no fixed inventory; cluster instances by context into sense groups. Good when labels are unavailable.
  • Supervised Naive Bayes derivation (standard exam derivation):

    • Task: pick sense s ∈ S maximizing P(s | C) where C = context words w1,...,wn.
    • Use Bayes rule: P(s | C) = P(C | s) P(s) / P(C). Since P(C) is same for all s, compare P(C | s) P(s).
    • Naive Bayes assumption: context words are conditionally independent given s, so P(C | s) = ∏_{i=1..n} P(wi | s).
    • So decision rule: choose s that maximizes P(s) ∏_{i} P(wi | s).
    • Estimate P(s) by relative frequency of sense s in training data. Estimate P(w | s) by frequency of word w occurring near target in examples of sense s (optionally Laplace smoothing).
  • Knowledge-based Lesk algorithm (exact statement):

    • For a target word instance, for each candidate sense s take the sense gloss (dictionary definition) and optionally example sentences and related synsets' glosses; compute the number of word overlaps between the gloss words and the context words. Choose sense with maximum overlap. This is the simplified Lesk (the original Lesk 1986 computes overlaps among the glosses of all words in the context).
    • Assumption: words that appear in a sense’s definition are likely to appear near that sense in real contexts.
  • Graph-based (e.g., knowledge graph) methods:

    • Build a graph where nodes are candidate senses, edges connect senses that are related (e.g., WordNet relations or co-occurrence). Run a ranking algorithm (PageRank or Personalized PageRank seeded by candidate senses of the surrounding context words) to choose senses with highest rank.
  • Evaluation and supervised vs. unsupervised trade-offs:

    • Supervised methods usually give higher accuracy but need labelled corpora for each target word and domain.
    • Knowledge-based methods need no labelled data but depend on quality and coverage of lexical resources. Common evaluation setups include all-words vs lexical-sample tasks (e.g., Senseval/SemEval corpora), accuracy/F1 metrics, and the most-frequent-sense (MFS) baseline that strong systems should beat.
  • Diagram descriptions to draw for exam answers:

    1. For Naive Bayes WSD: draw a box labelled "Training data (sentence, target word, sense)" → arrow to "Feature extraction (context words)" → arrow to "Model (Naive Bayes)" → arrow to "Predict sense". Label the Naive Bayes box with formula P(s) ∏ P(w|s).
    2. For Lesk: draw the target sentence with the ambiguous word circled, arrows to two gloss boxes (sense A and sense B). List overlapping words between gloss and sentence; show counts and highlight chosen sense with larger overlap.

Formulas

P(s | C) = P(C | s) · P(s) / P(C) — P(s|C) is posterior probability that sense is s given context C; unit: unitless; applies generally from Bayes' theorem.

decision = argmax_{s ∈ S} P(s) · ∏_{i=1..n} P(w_i | s) — choose sense maximizing prior times product of conditional probabilities; unitless; applies under Naive Bayes conditional-independence assumption.

P(w | s) = (count(w, s) + α) / (N_s + α·V) — smoothed likelihood estimate (Laplace when α=1); count(w,s) is number of times word w appears in contexts of sense s; N_s is total context-word tokens for sense s; V is vocabulary size; unitless; applies when using frequency-based estimates with smoothing.

overlap(s) = | { words(context) ∩ words(gloss(s) ∪ examples(s) ∪ related_glosses(s)) } | — Lesk overlap score; unitless; applies for simplified Lesk.

cosine(u, v) = (u · v) / (||u|| ||v||) — cosine similarity between context embedding vector u and sense embedding v; unitless; applies when using vector embeddings for WSD.

Worked examples

Example 1 — Supervised Naive Bayes (numerical, exam style) Problem: Disambiguate the word "bank" in sentence "I went to the bank to deposit money". Two senses: s1 = financial institution, s2 = river bank. Training counts (simplified):

  • Prior counts: count(s1) = 300, count(s2) = 200 (so P(s1)=0.6, P(s2)=0.4).
  • Context word counts (only showing relevant words):
    • For s1: count(deposit, s1)=30, count(money, s1)=25, total tokens N_s1 = 200.
    • For s2: count(deposit, s2)=1, count(money, s2)=0, total tokens N_s2 = 120.
  • Vocabulary size V = 50, use Laplace smoothing α = 1. Steps:
  1. Compute P(s1) = 300/(300+200) = 0.6. P(s2) = 0.4.
  2. Compute P(deposit | s1) = (30+1)/(200+50) = 31/250 = 0.124. P(money | s1) = (25+1)/250 = 26/250 = 0.104.
  3. Compute P(deposit | s2) = (1+1)/(120+50) = 2/170 ≈ 0.01176. P(money | s2) = (0+1)/170 ≈ 0.00588.
  4. Compute unnormalised posterior scores:
    • score(s1) = P(s1) · P(deposit|s1) · P(money|s1) = 0.6 · 0.124 · 0.104 ≈ 0.0077376.
    • score(s2) = 0.4 · 0.01176 · 0.00588 ≈ 0.00002767.
  5. Compare: score(s1) ≫ score(s2). Final decision: s1 = financial institution. (Show work and numeric steps in exams; state smoothing used and independence assumption.)

Example 2 — Programming: simplified Lesk algorithm in Python (self-contained) Code:

def simplified_lesk(context_sentence, target, sense_definitions):
    # context_sentence: string; target: string (unused in this simplified overlap implementation)
    # sense_definitions: dict sense -> definition string
    ctx = set(w.lower().strip('.,') for w in context_sentence.split())
    best = None
    best_score = -1
    for sense, gloss in sense_definitions.items():
        gloss_words = set(w.lower().strip('.,') for w in gloss.split())
        # overlap is the intersection size
        score = len(ctx & gloss_words)
        if score > best_score:
            best_score = score
            best = sense
    return best, best_score

# Example inventory for 'bank'
senses = {
    'financial_institution': 'a financial institution that accepts deposits and channels the money into lending activities',
    'river_bank': 'sloping land beside a body of water such as a river or stream'
}

sentence = 'I went to the bank to deposit money.'
res = simplified_lesk(sentence, 'bank', senses)
print('Predicted sense:', res[0], 'score:', res[1])

Sample input: (the code uses the sentence variable above) Exact output when run:

Predicted sense: financial_institution score: 2

Explain: with this simple token overlap, the matches are {'the', 'money'} between the sentence and the financial sense gloss; stemming or stopword removal is not applied here.

Example 3 — Model answer (theory long question) Question: Explain supervised vs knowledge-based WSD, compare strengths and weaknesses and give a short pipeline for each. Model answer (concise): Supervised WSD learns a classifier from labelled instances; features include bag-of-words in a window, POS tags, collocations, syntactic dependencies; common models: Naive Bayes, SVM, neural networks. Strength: high accuracy with good labelled data. Weakness: requires sense-annotated corpus per word/domain (expensive). Knowledge-based WSD uses dictionaries/WordNet and exploits gloss overlaps (Lesk), graph relations (PageRank), or sense embeddings constructed from definitions; needs no labelled data but depends on lexical resource coverage; often lower accuracy but domain-independent. Pipelines: supervised — annotate or use an available corpus → extract features → train classifier → apply to new sentences. Knowledge-based — select candidate senses from inventory → compute score for each sense (overlap, graph score) → pick highest-scoring sense.

Common mistakes

  • Confusing a sense inventory (fixed list) with unsupervised clustering output (which may define its own sense groups).
  • In Lesk, failing to expand glosses by examples or related synsets; real Lesk variants use enlarged glosses.
  • For programming answers: giving code that relies on external WordNet resources without stating installation assumptions.
  • Multiplying many small probabilities without using log-space in Naive Bayes, leading to numerical underflow; use sums of log-probabilities for stability.

For your exam

Types of questions:

  • Definitions and short notes: define WSD, sense inventory, supervised vs knowledge-based.
  • Derivations: show Bayes rule and derive Naive Bayes decision rule for WSD; show smoothing formula derivation.
  • Algorithms: explain Lesk step-by-step; draw diagrams of pipelines and gloss overlap counting.
  • Numericals: compute posterior probabilities for a Naive Bayes WSD example (show smoothing and priors).
  • Programs: write a simple Lesk implementation or pseudocode for Naive Bayes classification.
  • Diagrams: draw training→feature→model→predict flow, or sense graph with scores. What a full-marks answer includes:
  • Clear definition of terms used (e.g., sense inventory, context), explicit assumptions (independence, availability of labelled data), step-by-step derivations with formulae, and for applied questions, one worked numeric example or a runnable short program. For algorithms, describe complexity/limitations briefly.

Quick check

  1. What does the Lesk algorithm compare to choose a sense?
  2. State the Naive Bayes independence assumption used in WSD.
  3. Give one advantage and one disadvantage of supervised WSD. Answers: 1) overlaps between context words and sense gloss (definitions); 2) context words are conditionally independent given the sense; 3) advantage: high accuracy with labelled data; disadvantage: needs labelled corpora for each target and domain.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?