Meaning

Computational Linguistics

Course 1 ยท Chapter 8 ยท Meaning

So far the course has dealt with forms: characters, tokens, stems, tags and trees. A program that only handles forms can say that lamp is a noun, but not that a lamp is more like a lantern than like a harbour. This chapter shows two ways a machine can represent meaning: by writing it down as a network of relations, and by measuring the company a word keeps.

The idea in a box
One approach states meaning (people build a database of senses and relations). The other measures it (a program counts which words appear near which). Each fails in a different place.

Meaning Written Down: WordNet

Wikipedia's WordNet article calls it "a lexical database of semantic relations between words", a combination of a dictionary and a thesaurus, created in 1985 at Princeton University's Cognitive Science Laboratory under the psychologist George Armitage Miller, and later directed by Christiane Fellbaum. Roughly synonymous words of the same part of speech are grouped into synsets, each with a short gloss and usage examples; a word with several senses appears in several synsets. The main relations:

RelationWhat the article says
Hypernym / hyponymthe "is a kind of" parent and its reverse (nouns and verbs)
Coordinate termssiblings sharing a parent
Holonym / meronymthe whole and its part (nouns)
Troponym, entailmentverb relations: doing something in a particular manner; one action implying another
Antonymsshown for adjectives, where central pairs such as hot and cold anchor "dumbbell" structures with satellite synonyms

The article lists uses in word-sense disambiguation (where it calls WordNet the most commonly used computational lexicon of English), information retrieval, text classification, summarization and machine translation, and says word similarity can be measured by distance in the graph. It also notes that other resources build on it: ImageNet is organised by WordNet's noun hierarchy.

Watch out: the article gives two sets of counts
The infobox (2024 Edition, released 1 November 2024) says 161,705 words in 120,630 synsets, while the "database contents" section says 155,327 words in 175,979 synsets (version not stated). The article does not reconcile them, so I quote neither as the size of WordNet. It also says that as of 2026 the project is no longer being developed and the online version is unavailable, with community projects such as Open English WordNet continuing the data.

A hypernym tree you can run

I have not used WordNet's data in this course (Python's nltk is not installed here, and I have not read its interface). Instead, the tree below is a tiny made-up hypernym network of my own, and the distance is the number of steps up to the nearest shared ancestor, added for both words. The "steps through the graph" idea is the article's; this particular measure is just the simplest one I could write. I ran it and copied the output.

hyper = {"lamp": "light_source", "lantern": "lamp", "candle": "light_source", "light_source": "artifact", "boat": "vessel", "ship": "vessel", "vessel": "artifact", "keeper": "person", "sailor": "person", "person": "entity", "artifact": "entity"} def path_up(w): out = [w] while hyper.get(w): w = hyper[w]; out.append(w) return out def dist(a, b): pa, pb = path_up(a), path_up(b) common = next(x for x in pa if x in pb) return pa.index(common) + pb.index(common) for a, b in [("lantern", "lamp"), ("lantern", "candle"), ("boat", "ship"), ("lantern", "boat"), ("lantern", "keeper")]: print(a, b, dist(a, b)) print(path_up("lantern"))
lantern lamp 1 lantern candle 3 boat ship 2 lantern boat 5 lantern keeper 6 ['lantern', 'lamp', 'light_source', 'artifact', 'entity']

Closer in the tree means more alike: a lantern is one step from a lamp, three from a candle, six from a keeper. Everything this tells us was put there by whoever drew the tree, which is both the strength (it is deliberate and inspectable) and the cost (someone must build it, word by word).

Choosing a Sense: Word-Sense Disambiguation

Wikipedia's Word-sense disambiguation article defines it as "the process of identifying which sense of a word is meant in a sentence or other segment of context", usually subconscious in people. Its examples include pen (writing instrument or enclosure) and bank, which a translator might render as French banque or rive. It names Lesk (1986) as "the seminal dictionary-based method": find "the pair of dictionary senses with the greatest word overlap" in their definitions. It groups approaches into knowledge-based (dictionaries and thesauri, "without using any corpus evidence"), supervised (classifiers trained on sense-tagged corpora, held back by a "knowledge acquisition bottleneck"), semi-supervised and unsupervised (clustering occurrences, "the greatest challenge"). Its figures:

  • Coarse-grained, homograph-level English WSD "routinely above 90%" (as of 2009); fine-grained top results "from 59.1% to 69.0%" in SemEval-2007 and Senseval-2.
  • In Senseval-2, with fine-grained senses, human annotators "agreed in only 85% of word occurrences", so human performance is treated as an upper bound.
  • Always choosing the most frequent sense scored 51.4% (SemEval-2007) and 57% (Senseval-2), showing how much comes from frequency alone.
  • History: Warren Weaver raised it as a computational problem in 1949; the 1990s statistical revolution made it a supervised-learning problem.

I read the article to 100,000 of 113,521 characters. Below is a very simplified overlap method in the spirit of Lesk's idea, with two glosses I wrote for light. It is my sketch, not Lesk's algorithm as published, which I have not read.

senses = { "light": { "lamp-light": "brightness from a lamp or the lighthouse that guides boats at night", "not-heavy": "of small weight easy to carry not heavy", } } stop = {"the", "a", "of", "or", "to", "at", "in", "is", "and", "from", "that"} def lesk(word, context): ctx = {w for w in context.split() if w not in stop} scores = {s: len(ctx & {w for w in g.split() if w not in stop}) for s, g in senses[word].items()} return scores, max(scores, key=scores.get) for c in ("the light guides the boats at night", "the bag is light and easy to carry", "she took the light"): print(c, "->", lesk("light", c))
the light guides the boats at night -> ({'lamp-light': 3, 'not-heavy': 0}, 'lamp-light') the bag is light and easy to carry -> ({'lamp-light': 0, 'not-heavy': 2}, 'not-heavy') she took the light -> ({'lamp-light': 0, 'not-heavy': 0}, 'lamp-light')

The first two work because their context words overlap a gloss. In the third there is no overlap at all, so max simply returns the first sense: the program has no evidence but still answers. A real system must be able to say "I can't tell", or fall back on a baseline such as the most frequent sense.

Meaning Measured: Distributional Semantics

The Distributional semantics article describes it as a research area that measures and classifies semantic similarity between linguistic items using their distributional properties in large corpora, built on the distributional hypothesis: "linguistic items with similar distributions have similar meanings." It attributes the phrase "a word is characterized by the company it keeps" to Firth, who popularised it in the 1950s, and cites Harris (1954) for the hypothesis. It gives no longer Firth quotation and no Harris wording, so I quote nothing more. Its other points:

  • Co-occurrence information is collected in high-dimensional vectors, and similarity is defined as vector similarity; when the context is other words the models are called "word space" or "vector space" models.
  • It lists cosine similarity and Minkowski distance as similarity measures, and dimension reduction (random indexing, singular value decomposition) as one parameter; it explains neither method.
  • Models differ in context type, window size, frequency weighting, dimension reduction and similarity measure; latent semantic analysis, Hyperspace Analogue to Language and topic models are named.
  • It says distributional semantics serves as an input to neurally inspired deep-learning models, and lists word embedding and Word2vec only in "See also". NLP 5 (Word Embeddings and Word2Vec) covers that route, and I have not re-read it.
  • Limits it admits: it calls it an open question whether similar meaning really tracks similar distribution; it mentions data sparsity; and it says word-level meaning is only part of a sentence's meaning, with Tigers love rabbits as its example.

Wikipedia's Cosine similarity article gives the measure: "the dot product of the vectors divided by the product of their lengths", from โˆ’1 to +1, and 0 to 1 when no component can be negative (as with counts). It says that for documents it works as a way of "normalizing document length". Below is my own tiny corpus (12 invented sentences) and a window of two words either side, ignoring the.

import math from collections import Counter, defaultdict text = """ the keeper lit the lamp the keeper lit the lantern the sailor watched the lamp the sailor watched the lantern the keeper climbed the stairs the sailor climbed the mast the sailor rowed the boat the sailor rowed the ship the keeper watched the boat the keeper watched the ship the boat reached the harbour the ship reached the harbour """ sents = [l.split() for l in text.strip().splitlines()] vec = defaultdict(Counter) for s in sents: for i, w in enumerate(s): for j in range(max(0, i-2), min(len(s), i+3)): if j != i and s[j] != "the": vec[w][s[j]] += 1 def cos(a, b): dot = sum(a[k] * b[k] for k in a) return dot / (math.sqrt(sum(v*v for v in a.values())) * math.sqrt(sum(v*v for v in b.values()))) print("lamp", dict(vec["lamp"])) print("lantern", dict(vec["lantern"])) for a, b in [("lamp", "lantern"), ("boat", "ship"), ("lamp", "boat"), ("keeper", "sailor"), ("lamp", "keeper")]: print(a, b, round(cos(vec[a], vec[b]), 3))
lamp {'lit': 1, 'watched': 1} lantern {'lit': 1, 'watched': 1} lamp lantern 1.0 boat ship 1.0 lamp boat 0.408 keeper sailor 0.556 lamp keeper 0.943

Lamp and lantern score 1.0 and boat and ship score 1.0, which is the pattern the hypothesis predicts: I wrote them to appear in identical contexts, so this is partly built in. The surprise is the last line: lamp and keeper score 0.943, higher than keeper and sailor (0.556), though a keeper is a person and a lamp is not. The reason is in the counts: both are only ever seen next to lit and watched in my twelve sentences. The measure is faithfully reporting a corpus that is too small and too repetitive, which echoes the article's data sparsity point. I did not test how the score changes with a larger corpus.

Written down (WordNet-style)Measured (distributional)
Sourcepeople build the networkcounts from a corpus
Strengthexplicit relations such as is-a; inspectableno hand-building; reflects usage in the corpus
Weakness hereevery word and sense must be entered; a gap means no answeronly as good as the corpus (lamp/keeper above); similarity is not a named relation

The table's two columns are my summary of the two sections, not a comparison made by the articles.

Note on sources
This chapter uses Wikipedia's WordNet and Cosine similarity (read in full), Word-sense disambiguation (read to 100,000 of 113,521 characters; the tail was not read) and Distributional semantics (read in full; it has no criticisms section and no formula for cosine). The Firth phrase is the only wording the page gives; I did not verify any longer quotation, and I did not read Firth or Harris. The WordNet counts conflict inside the article and are not used. The hypernym tree, glosses, corpus, window size, both algorithms and all outputs are mine and were run with py -X utf8; the Lesk-style code is not Lesk's published algorithm. NLP 5 was not re-read here.

Try It Yourself

Exercise 1

Add "torch": "light_source" to the hypernym tree. Predict, then compute, dist from torch to lamp, lantern and candle. Explain why torch is not closer to lantern than to lamp.

๐Ÿ“„ View solution
Exercise 2

Print the vectors for keeper and lamp and explain the 0.943 score. Then add the sentences the keeper slept and the lamp glowed twice each, rebuild the vectors and rerun the cosines. What changes, including for lamp and lantern?

๐Ÿ“„ View solution
Exercise 3

Change lesk so that when the two top scores are equal it returns "unsure". Test it on she took the light and the light guides the boats at night, then name one other fallback the WSD article's baseline suggests.

๐Ÿ“„ View solution

Chapter 8 Quick Reference

  • WordNet: synsets (near-synonyms) joined by relations such as hypernym/hyponym and meronym/holonym
  • Word-sense disambiguation: pick the sense that fits the context; Lesk compares context with dictionary definitions
  • Distributional hypothesis: similar distributions suggest similar meanings; Firth: "a word is characterized by the company it keeps"
  • Cosine similarity: dot product over lengths; 0 to 1 for counts
  • Small corpora give misleading similarities
Coming next
Computational Linguistics 9 asks how to tell whether any of these systems is actually good: precision, recall, baselines and agreement between human judges.