Notes / Natural Language Processing / Note 2 of 8
Leer en españolWords, lemmas and WordNet
What a word is made of, how stems and lemmas gather its forms, how the words of a sentence are tagged, and how WordNet relates their meanings.
The previous note ended on a gap: the Spanish original uses 22,605 different words where the translation uses 14,921, because a Spanish verb takes dozens of forms and a count takes each for a different word. To a reader, said, says and saying are one verb; to a count, three words. The opposite also happens, one spelling standing for several words. This note looks at what words are made of and what they mean, with the tools NLP uses for both:
-
Three words to a count, one verb to a reader
-
The same words: a place, or part of a name
-
One spelling, two words: brightness and not heavy
Sections 1 and 2 are about forms: what a word is made of, and two ways of gathering a word's forms, which bring the two books' vocabularies much closer. Section 3 labels each word of a sentence with its part of speech and finds the names in it. Sections 4 and 5 are about meanings: how WordNet relates them, and how one spelling can carry several.
1What a word is made of
Linguistics describes language at four levels, each with the unit it studies and the discipline that studies it:
| Level | Unit | Discipline |
|---|---|---|
| Morphological | the word | morphology |
| Syntactic | the sentence | syntax |
| Lexical-semantic | the meaning | lexicology and semantics |
| Textual | the text | text analytics |
An NLP system may need any of them; this note covers the first three, starting with the word. Its smallest piece with both a form and a meaning is the moneme, and there are two kinds. Speaking holds one of each: speak, the lexeme, carries the meaning and is shared with related words such as speaker; -ing, a morpheme, adds grammatical meaning, here an action in progress. Morphemes mark gender, number, person, tense and the like.
Words split into two groups by whether they take such morphemes. Variable words, such as nouns, adjectives, verbs and pronouns, change their form; invariable ones, such as prepositions, conjunctions and interjections, keep a single form. Variable words are what makes a vocabulary large. Pick a word with the buttons to see all its forms in the book, each split into its lexeme, in ink, and its ending, in carmine, with its count. Below are the forms of the same word in the Spanish original.
Pick a word with the buttons. A word's forms are those a list of forms and their lemmas gives for it.
Spanish puts person, number, tense and mood into its verbs' endings, where English uses separate words: diremos is we will say. A count takes the Spanish form for one more word, and the English words for three it already has; section 2 measures how much of the gap between the books that explains.
2Stems and lemmas
Two methods gather a word's forms. Stemming cuts endings off by rules, with no dictionary: the Snowball stemmers, which grew out of Martin Porter's 1980 stemmer for English and now cover many languages, turn speaking and speaks into speak. What remains, the stem, need not be a word. Lemmatization returns each form's lemma, the form a dictionary lists it under: said and says both give say. A lemmatizer never invents a word, but it needs each form's part of speech, since saw is a form of see as a verb and a word of its own as a noun; without it, NLTK's lemmatizer takes every word for a noun.
Pick a word to see which of the book's words share its stem and which share its lemma; a word in only one of the two groups is outlined in carmine. Below, how far each method shrinks each book's vocabulary.
Pick a word with the buttons. The stems are Snowball's; the lemmas, those of the list of forms.
Each method fails in its own way, as the examples show, but lemmatizing brings the books close: the translation's 14,921 different words become 10,337 lemmas, and the original's 22,605 become 12,596. A word the list lacks counts as its own lemma. That is right for most of them, since the list leaves out the words that are lemmas already, such as with, but the Spanish list also lacks verbs with a pronoun attached, such as decirle (to tell him), and the old spellings of a book from 1605, such as agora for ahora (now), so the original's true count is lower still.
4Meanings in a network
Meanings are related too, and two relations matter most. A knight-errant is a kind of knight: knight-errant is a hyponym of knight, and knight a hypernym of knight-errant. A helmet is a piece of a suit of armor: helmet is a meronym of suit of armor, and suit of armor a holonym of helmet. The first relation sorts things into classes; the second takes them apart.
WordNet records both for English, and it is organized by meanings rather than by words: each synset is a set of synonyms with one meaning, a definition, and links to other synsets. George Miller's team at Princeton began building it by hand in 1985; version 3.0 has 117,659 synsets and 147,306 different words and phrases. NLTK includes it, and its lemmatizer is built on it: an irregular form such as saw is looked up in a list of exceptions, and a regular one loses its ending only if what remains is in WordNet. BabelNet goes further: it merges WordNet with Wikipedia and other resources, so each of its entries gathers a concept's words in many languages, along with names of people and places that WordNet lacks.
The figure shows a small piece of WordNet, with the Spanish words that the Multilingual Central Repository gives each synset. In Kinds, the chain of hypernyms above knight runs up to entity, and picking a synset draws its chain in blue; in Parts, ten of the parts of a suit of armor run from head to foot. One of them, the thigh plate, is in Spanish a quijote.
Pick a synset, or move between them with the arrow keys. The definitions are the note's own, and so are the Spanish names of the five synsets the repository leaves without one.
5One spelling, several words
Synonymy is several forms for one meaning. The reverse, one form for several meanings, comes about in two ways. In polysemy, one word's senses grew apart from a shared origin, often by metaphor. In homonymy, two unrelated words share a spelling by chance. Dictionaries mark the difference: they give each homonym an entry of its own, and list the senses of a polysemous word inside its one entry. WordNet makes no such difference: it gives light 47 senses, 15 as a noun, 6 as a verb, 25 as an adjective and 1 as an adverb, with no mark of which ones share an origin.
The book's light shows both. Light as brightness comes from a root *leuk-, and light as not heavy from a different one, *legwh-: two words that look and sound alike by an accident of history. Each grew senses of its own. From brightness came a lamp, and the verb in to light a candle; from not heavy came to light upon something, which first meant to get down from a horse and so lighten its load, and to make light of it. The figure sorts the book's 98 uses of light by sense, labeled by hand; pick one to see its share and a line from the book.
Pick a sense, or move between them with the arrow keys.
Choosing a word's sense from its sentence is word-sense disambiguation, and a lemmatizer does not do it: light gets one lemma whatever it means. The word vectors of later notes share that blind spot, one vector per word, until encoders build each word's vector from its sentence.
6Summary
The note's ideas in NLTK, a Python library for working with text. tokens holds a sentence's words, and wn is nltk.corpus.wordnet, with the Open Multilingual Wordnet installed for Spanish.
SnowballStemmer("english")
.stem("speaking")wnl = WordNetLemmatizer()
wnl.lemmatize("saw", "v")nltk.pos_tag(tokens)nltk.ne_chunk(
nltk.pos_tag(tokens))wn.synset("knight.n.01")
.hypernyms()wn.synset(
"body_armor.n.01"
).part_meronyms()wn.synset("knight.n.01")
.lemma_names("spa")len(wn.synsets("light"))The note's data: the lemmas come from Michal Měchura's lemmatization lists (ODbL), the stems from the Snowball stemmers, the synsets and their relations from Princeton University's WordNet 3.0, and their Spanish words from the Multilingual Central Repository 3.0 (CC BY 3.0).