🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Word Sense Disambiguation: Context and Ambiguity

Natural Language ProcessingWord Sense Disambiguation: Context and AmbiguityđŸŸĸ Free Lesson

Word Sense Disambiguation: Context and Ambiguity

Module: Natural Language Processing | Difficulty: Advanced

What You'll Learn

  • 1Formalize WSD as argmax sense selection over a WordNet synset inventory
  • 2Implement extended Lesk overlap and a supervised baseline in Python
  • 3Compare MFS, graph-based, and gloss-enriched BERT systems with F1
  • 4Explain why sense granularity sets the accuracy ceiling

Word sense disambiguation picks the correct meaning of an ambiguous word from its context, and it matters because a single lemma can carry dozens of distinct meanings: WordNet 3.0 lists 117,659 synsets and 206,941 word-sense pairs, so choosing "bank" as the financial institution instead of the river edge propagates a wrong meaning into translation, search, and question answering. This lesson formalizes the task, implements two disambiguation algorithms, and reads the benchmark numbers that bound what is achievable.

The WSD Task

WordNet (Miller, 1995) groups synonymous surface forms into synsets, each with a gloss and relations such as hypernymy. All-words WSD annotates every ambiguous token in running text, lexical-sample WSD restricts attention to fixed targets, and cross-lingual WSD repeats the protocol on translated corpora.

SystemYearMethodEnglish all-words F1
Most Frequent Sense1995SemCor frequency prior66.5
Extended Lesk2003Gloss word overlap72.9
UKB2009Personalized PageRank76.3
BERT fine-tuned2019Contextual classifier78.1
GlossBERT2019Gloss plus context pairs82.1

Why the most frequent sense is a hard baseline

MFS assigns the sense most common in SemCor and reaches about 66.5 F1 at zero inference cost, so every learned system must clear 66.5 before it is worth deploying.

Supervised WSD as Classification

Given a target token, a supervised model represents its context and scores every candidate sense. The standard formulation is a softmax over the candidate synset set, trained with cross-entropy on sense-annotated corpora such as SemCor, which tags roughly 183,000 word instances drawn from 351,169 words of running text.

Knowledge-Based and Graph Methods

Knowledge-based systems avoid labeled training data entirely. The original Lesk algorithm scores a sense by counting words shared between its gloss and the surrounding context; extended Lesk adds the glosses of related words, at the cost of a larger overlap window. Graph methods instead run PageRank over the WordNet relation graph with the context words as personalization seeds, iterating the stochastic matrix until the scores converge.

Cost of each family

The power iteration behind personalized PageRank costs for iterations over the WordNet edge set, while a gloss-enriched BERT model scores one candidate pair per sense, so a 10-sense word costs 10 forward passes of a 110M-parameter encoder.

Where systems fail, and how to measure it

Errors concentrate on rare senses, because the frequency prior dominates when context is thin. Keep the model score and the MFS prior side by side rather than letting the classifier emit an unknown label.

Worked Code

python
from collections import Counter

SENSES = {
    "bank#1": {"depository", "financial", "institution", "money", "credit"},
    "bank#2": {"slope", "river", "edge", "shore", "embankment"},
    "rate#1": {"interest", "charge", "fee", "price"},
    "rate#2": {"speed", "velocity", "pace", "frequency"},
}
RELATED = {"bank#1": {"rate#1"}, "bank#2": set(), "rate#1": {"bank#1"}, "rate#2": set()}


def lesk(word, context, expand=True):
    """Extended Lesk: overlap of gloss words, optionally expanded by related senses."""
    best, best_score = None, -1
    cands = [s for s in SENSES if s.split("#")[0] == word]
    for sense in cands:
        gloss = set(SENSES[sense])
        if expand:
            for rel in RELATED[sense]:
                gloss |= SENSES[rel]
        score = len(gloss & set(context))
        if score > best_score:
            best, best_score = sense, score
    return best, best_score


for sentence in (
    ("bank", "the bank raised interest rates and approved new credit".split()),
    ("bank", "the river bank had a steep slope near the shore".split()),
):
    sense, sc = lesk(*sentence)
    print(sentence[0], "->", sense, "overlap", sc)


def mfs_baseline(word, counts):
    cands = [(s, n) for s, n in counts.items() if s.split("#")[0] == word]
    return max(cands, key=lambda kv: kv[1])[0]


print("MFS:", mfs_baseline("bank", {"bank#1": 87, "bank#2": 34}))
python
import math
from collections import Counter


def micro_f1(gold, pred):
    c = sum(1 for g, p in zip(gold, pred) if g == p)
    p = c / max(1, len(pred))
    r = c / max(1, len(gold))
    return p, r, (0.0 if p + r == 0 else 2 * p * r / (p + r))


def feat(toks, i):
    # Left and right lemma window, the classic WSD feature template.
    left = toks[i - 1] if i else "<s>"
    right = toks[i + 1] if i + 1 < len(toks) else "</s>"
    return [f"L={left}", f"R={right}"]


class NaiveBayesWSD:
    def __init__(self, alpha=1.0):
        self.alpha = alpha

    def fit(self, X, y):
        self.classes = sorted(set(y))
        self.prior = {c: (y.count(c) + 1) / (len(y) + len(self.classes))
                      for c in self.classes}
        self.cnt = {c: Counter() for c in self.classes}
        for row, c in zip(X, y):
            self.cnt[c].update(row)
        self.tot = {c: sum(self.cnt[c].values()) + self.alpha * 20
                    for c in self.classes}
        return self

    def predict(self, X):
        out = []
        for row in X:
            best, top = None, -math.inf
            for c in self.classes:
                lp = math.log(self.prior[c])
                for f in row:
                    lp += math.log((self.cnt[c][f] + self.alpha) / self.tot[c])
                if lp > top:
                    best, top = c, lp
            out.append(best)
        return out


TRAIN = [("the bank approved credit", "bank#1"),
         ("interest rates at the bank", "bank#1"),
         ("the river bank slope", "bank#2"),
         ("steep shore of the bank", "bank#2"),
         ("a fast rate of growth", "rate#2"),
         ("the interest rate fee", "rate#1")]
gold = [s for _, s in TRAIN]
X = [feat(t.split(), t.split().index(s.split("#")[0])) for t, s in TRAIN]
pred = NaiveBayesWSD().fit(X, gold).predict(X)
print("P/R/F1:", micro_f1(gold, pred))
print(list(zip(gold, pred)))

Real-World Applications

  • WordNet 3.0 ships 117,659 synsets and 206,941 word-sense pairs, the inventory that every English WSD score here is measured against.
  • The SemEval-2013 Task 12 English test set holds 8,266 word instances across 3,002 documents, the usual reporting set for gloss-enriched models.
  • Synonym expansion guided by WSD raises retrieval recall in lexical search, while a wrong MFS choice silently injects an unrelated term into the query.

💡Granularity sets the ceiling

Mapping fine-grained WordNet senses onto the 45 coarse OntoNotes categories typically lifts reported accuracy by 3 to 5 points without changing a single model weight.

Common Mistakes

Reporting accuracy against an MFS-free baseline

Fix: Always publish the MFS number, which sits near 66.5 F1, so readers can see whether learning actually helped

Training on SemCor and testing on the same lemmas

Fix: Use the sense-split or lemma-disjoint splits, since random token splits leak the same synset exemplars into test

Letting the classifier emit an unknown label

Fix: Fall back to the MFS prior for low-confidence tokens, because abstention cuts recall harder than it helps precision

Best Practices

  • Normalize every system onto a single sense inventory before comparing scores
  • Report micro-F1 over evaluated tokens plus the MFS baseline in the same table
  • Add gloss text to the input, since gloss-enriched models gain about 4 F1 over context-only BERT

Key Takeaways

  • WSD is argmax over S(w): P(s given c) with normalization restricted to the candidate synsets
  • MFS reaches 66.5 F1 for free, so any model below that number should not be shipped
  • GlossBERT reaches about 82.1 F1 on English all-words, roughly 16 points above MFS
  • Coverage and risk move together: trading 2 points of coverage for 1 point of risk is rarely worth it

Frequently Asked Questions

How many senses does a typical word have?

WordNet 3.0 gives the average polysemous noun about 2 senses, but the tail is extreme: run has 64 verb senses and set has 83 noun senses across 206,941 word-sense pairs, so long-tail words drive most of the error.

What accuracy should I expect from a modern WSD system?

Context-only BERT lands near 78.1 F1 and gloss-enriched models that read the dictionary definition reach about 82.1 F1. Human agreement on the same task is around 90 F1, so roughly 8 points of headroom remain.

Is WSD still a separate task or is it solved inside language models?

Both. Deployed systems disambiguate implicitly through contextual embeddings, but evaluation still needs explicit labels, and SemEval-2022 Task 2 shows that explicit WSD over 10 languages remains open outside English.

Interview Questions

Q1: Why is the most frequent sense baseline so strong?

Sense choice follows a Zipfian prior learned from SemCor, and that prior alone yields about 66.5 F1 before any context is read

Q2: What does extended Lesk add over classic Lesk?

It expands the gloss with the glosses of related synsets, which typically adds 4 to 6 F1 points by turning zero-overlap ties into measurable scores

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Continue Learning

Suggested next tutorials based on this topic

Need Expert NLP Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement