Skip to content
SDB
Natural Language Processing

Chapter 03 · beginner · 25 min

Morphology & Lexical Analysis

Word structure, morphemes, POS tagging, chunking, and lexical resources

Subhendu Datta BhowmikAI Tutorials

Morphology: The Structure of Words

Morphology is the study of the internal structure of words — how words are built from smaller meaningful units called morphemes.

Morphemes

A morpheme is the smallest unit of language that carries meaning:

TypeExampleBreakdown
Free morpheme"cat", "run"Can stand alone as a word
Bound morpheme"-ing", "un-", "-ness"Must attach to another morpheme
Root"happi" in "happiness"Core meaning carrier
Prefix"un-" in "unhappy"Attaches before root
Suffix"-ness" in "happiness"Attaches after root
Infix"-bloody-" (informal)Inserted within a word

Inflectional vs Derivational Morphology

InflectionalDerivational
PurposeGrammatical variation of same wordCreates new words with new meaning
Changes word class?NoOften yes
Exampleswalk → walks, walked, walkinghappy → happiness (N), unhappy (Adj)
Number of affixesLimited (8 in English)Hundreds

English inflectional suffixes (all 8):

  • Noun: -s (plural), -'s (possessive)
  • Verb: -s (3rd person), -ed (past), -ing (progressive), -en (past participle)
  • Adjective: -er (comparative), -est (superlative)

Why Morphology Matters for NLP

  • Reduces vocabulary size: "run", "runs", "running", "ran" → same root
  • Handles out-of-vocabulary words: decompose into known morphemes
  • Language generation: inflect correctly based on number/tense/gender
  • Cross-lingual NLP: morphologically rich languages (Finnish, Turkish, Arabic) have thousands of word forms per lemma

Part-of-Speech (POS) Tagging

POS Tag Sets

The Penn Treebank tagset (45 tags) is the most common for English:

TagMeaningExample
NNNoun, singular"dog"
NNSNoun, plural"dogs"
VBVerb, base form"run"
VBDVerb, past tense"ran"
VBGVerb, gerund"running"
JJAdjective"fast"
RBAdverb"quickly"
DTDeterminer"the", "a"
INPreposition"in", "on"
PRPPersonal pronoun"he", "she"
CCCoordinating conjunction"and", "but"

Universal POS tags (17 tags) — language-agnostic, used by spaCy and Universal Dependencies: NOUN, VERB, ADJ, ADV, PRON, DET, ADP (prepositions), CONJ, NUM, PUNCT, ...

POS Tagging Approaches

1. Rule-based: handcrafted rules ("if ends in -ing after auxiliary verb → VBG"). Fast but brittle.

2. Hidden Markov Model (HMM):

P(t1...tnw1...wn)i=1nP(witi)P(titi1)P(t_1...t_n | w_1...w_n) \propto \prod_{i=1}^{n} P(w_i | t_i) \cdot P(t_i | t_{i-1})

  • Emission probability P(wt)P(w|t): likelihood of word given tag
  • Transition probability P(titi1)P(t_i|t_{i-1}): how likely one tag follows another
  • Decoded with Viterbi algorithm in O(nT2)O(n \cdot |T|^2)

3. Maximum Entropy / CRF: discriminative models that use richer features (prefix, suffix, capitalization)

4. Neural (BiLSTM-CRF / Transformer): BERT-based POS taggers achieve >98% accuracy on standard benchmarks

Chunking (Shallow Parsing)

Chunking groups tokens into non-overlapping phrases (chunks) — a step beyond POS tagging, short of full parsing:

[NP The quick brown fox] [VP jumped over] [NP the lazy dog]

Common chunk types: NP (noun phrase), VP (verb phrase), PP (prepositional phrase).

Chunking uses IOB (Inside-Outside-Beginning) tags:

  • B-NP: Beginning of noun phrase
  • I-NP: Inside noun phrase
  • O: Outside any chunk

Lexical Analysis and Lexical Resources

WordNet

WordNet is a large lexical database grouping English words into sets of cognitive synonyms called synsets, linked by semantic relations:

RelationDirectionExample
Synonyms (same synset)"car" ↔ "automobile"
Hypernym (is-a, more general)Up"car" → "vehicle" → "artifact"
Hyponym (is-a, more specific)Down"vehicle" → "car", "truck", "bus"
Holonym (part-of)Up"wheel" → "car"
Meronym (has-part)Down"car" → "wheel", "engine"
AntonymOpposite"good" ↔ "bad"

WordNet is the basis for Wu-Palmer Similarity, Path Similarity, and Lin Similarity between word meanings.

Named Entity Classes (Preview)

Lexical analysis also identifies named entities — real-world objects with proper names:

  • PERSON: Barack Obama, Marie Curie
  • ORG: Google, United Nations
  • GPE (Geo-Political Entity): France, New York
  • DATE: January 1, 2024
  • MONEY: $500 million

Full NER coverage is in Chapter 9.

Sense Inventory and Polysemy

Polysemy: a single word with multiple related meanings:

  • "bank" → financial institution / riverbank / to bank a turn

Homonymy: different words that happen to share the same form:

  • "bat" → flying mammal / cricket bat

Word Sense Disambiguation (WSD) selects the correct sense from context — covered in Chapter 5.

POS Tagging, Chunking, and WordNet with NLTK and spaCypython
import nltk
import spacy
from nltk.corpus import wordnet as wn
from nltk import pos_tag, word_tokenize, RegexpParser

nltk.download(['averaged_perceptron_tagger', 'wordnet', 'punkt', 'maxent_ne_chunker', 'words'], quiet=True)

# ─── 1. POS Tagging with NLTK ────────────────────────────────
sentence = "The quick brown fox jumps over the lazy dog"
tokens = word_tokenize(sentence)
pos_tags = pos_tag(tokens)
print("NLTK POS Tags:")
for word, tag in pos_tags:
    print(f"  {word:<12} {tag}")

# ─── 2. POS Tagging with spaCy (preferred) ───────────────────
nlp = spacy.load("en_core_web_sm")
doc = nlp("The quick brown fox jumps over the lazy dog near the river bank.")
print("\nspaCy POS Tags:")
print(f"{'Token':<15} {'POS':<8} {'Fine POS':<10} {'Dep':<10}")
print("-" * 45)
for token in doc:
    print(f"{token.text:<15} {token.pos_:<8} {token.tag_:<10} {token.dep_}")

# ─── 3. Chunking with NLTK RegexpParser ─────────────────────
# Define grammar rules for noun phrases
grammar = r"""
  NP: {<DT>?<JJ>*<NN>}   # Determiner + adjectives + noun
  VP: {<VB.*><NP|PP>*}   # Verb followed by NP or PP
  PP: {<IN><NP>}          # Preposition + NP
"""
parser = RegexpParser(grammar)
tree = parser.parse(pos_tags)
print("\nChunk Tree:")
for subtree in tree.subtrees():
    if subtree.label() in ['NP', 'VP', 'PP']:
        print(f"  [{subtree.label()}] {' '.join(word for word, tag in subtree.leaves())}")

# ─── 4. WordNet Exploration ──────────────────────────────────
print("\nWordNet for 'car':")
for ss in wn.synsets('car'):
    print(f"  {ss.name()}: {ss.definition()}")

car = wn.synset('car.n.01')
print(f"\nHypernyms (car is a...): {[h.name() for h in car.hypernyms()]}")
print(f"Hyponyms (types of car): {[h.name() for h in car.hyponyms()[:5]]}")
print(f"Meronyms (car has...): {[m.name() for m in car.part_meronyms()]}")

# Semantic similarity
dog = wn.synset('dog.n.01')
cat = wn.synset('cat.n.01')
wolf = wn.synset('wolf.n.01')
print(f"\nPath similarity:")
print(f"  dog ↔ cat:  {dog.path_similarity(cat):.3f}")
print(f"  dog ↔ wolf: {dog.path_similarity(wolf):.3f}")

# Wu-Palmer similarity
print(f"Wu-Palmer similarity:")
print(f"  dog ↔ cat:  {dog.wup_similarity(cat):.3f}")
print(f"  dog ↔ wolf: {dog.wup_similarity(wolf):.3f}")

# ─── 5. Morphological Analysis ───────────────────────────────
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()

words = [("studies", "v"), ("better", "a"), ("geese", "n"), ("running", "v")]
print("\nMorphological analysis:")
for word, pos in words:
    lemma = lemmatizer.lemmatize(word, pos=pos)
    synsets = wn.synsets(lemma)
    print(f"  {word} → lemma: {lemma}, synsets: {len(synsets)}")

Knowledge check

Which relationship correctly describes the WordNet link between "poodle" and "dog"?

Summary

  • Morphemes are the smallest meaningful units; free morphemes stand alone, bound morphemes attach to roots
  • Inflectional morphology: grammatical variation (tense, number) — English has 8 inflectional suffixes
  • Derivational morphology: creates new words with new meanings (happy → happiness)
  • POS tagging: assigns grammatical categories; neural models (BERT) achieve >98% accuracy
  • Chunking: groups POS-tagged tokens into shallow phrase structures (NP, VP, PP)
  • WordNet: lexical database with synsets linked by hypernymy, hyponymy, meronymy, antonymy

Next: Syntactic Analysis & Parsing — understanding sentence structure and grammar.

Natural Language Processing