Skip to content
AI360XpertBeta

Part-of-Speech Tagging

Every word plays a grammatical role such as noun, verb or adjective. A tagger picks the most likely role for each word from its neighbours, so flies can be a verb in one sentence and a noun in the next.

The same word flies gets VBZ in Time flies and NNS in Fruit flies, because the neighbouring tags decide which label wins.
The same word flies gets VBZ in Time flies and NNS in Fruit flies, because the neighbouring tags decide which label wins.

Why Does This Exist?

Words refuse to sit still. Bank can be a financial house, a river edge or a verb meaning to rely. Light can be a noun, a verb or an adjective. Flies can be a verb or a plural noun. A dictionary lookup alone leaves every sentence as a pile of maybe-meanings.

Downstream steps need one decided structure. Parsing, name finding and relation extraction all read grammar roles, not raw words. Without decided tags they guess on soup.

This page covers the labelling step itself: the tag set, how context picks the tag, and how the best whole-sentence path is found. For the chain this sits in, see the NLP pipeline. For the name-span step that reads these tags, see named entity recognition. For the arrow links that need tags first, see dependency parsing.

The one idea you need first

Text must be split into tokens before any token can carry a label. A token is usually a word or subword. The full treatment is in tokenization in NLP.

Think of It Like This

A grammar teacher marking a whiteboard

A teacher circles each word on a whiteboard and writes noun, verb or adjective under it. They never decide from one word alone. In "The light switch", the neighbours "The" and "switch" force light to be an adjective. In "Light the switch", the command position forces light to be a verb.

The circles are tokens. The labels under them are tags. The glances at neighbours are context scores.

Where it stops: the teacher knows meaning and can explain a joke. The tagger knows only which label patterns were common in training, so a new domain or a broken sentence fools it while the teacher keeps going.

How It Actually Works

Tagging is sequence labelling. Given nn words w1,…,wnw_1, \ldots, w_n, output nn tags t1,…,tnt_1, \ldots, t_n, one per word. Tag tit_i names the grammatical role of word wiw_i in this sentence, not in a dictionary. The same spelling can take different tags in different sentences, and the job is to pick the sequence that fits the whole sentence best.

The tag set

English most often uses the Penn Treebank set with 36 tags. NNNN is a singular noun such as dog, NNSNNS a plural noun such as dogs, NNPNNP a proper noun such as London, VBVB a base verb such as run, VBDVBD a past verb such as ran, VBZVBZ a present verb with he or she such as runs, JJJJ an adjective such as fast, RBRB an adverb such as quickly, DTDT a determiner such as the, ININ a preposition such as in. Finer splits help the model catch small grammar habits.

How a hidden Markov tagger scores a sentence

A classic tagger uses two tables. Emission P(wi∣ti)P(w_i \mid t_i) is the chance of seeing this word given this tag, so P(dog∣NN)P(dog \mid NN) is high and P(dog∣VB)P(dog \mid VB) is tiny but not zero. Transition P(ti∣ti−1)P(t_i \mid t_{i-1}) is the chance of this tag after the last tag, so P(NN∣DT)P(NN \mid DT) is high because the almost always precedes a noun or adjective, never a verb. The score of a full tag path T=(t1,…,tn)T = (t_1, \ldots, t_n) is the product of those terms, and decoding picks the path with the top product.

Checking every path is hopeless. With ∣T∣=36|T| = 36 tags and n=5n = 5 words there are 365=60,466,17636^5 = 60,466,176 paths. The Viterbi algorithm keeps only the best partial path into each tag at each step, which costs O(n×∣T∣2)O(n \times |T|^2), here 5×36×36=6,4805 \times 36 \times 36 = 6,480 updates. Same best path, about nine thousand times less work.

Modern taggers swap the tables for a bidirectional encoder plus a transition layer, so each word vector sees left and right context at once. A conditional random field on top keeps the whole order valid. The search idea stays the same: score whole paths, keep the best.

Worked example

Take a toy tagger with two tags for flies. Emission P(flies∣VBZ)=0.06P(flies \mid VBZ) = 0.06 and P(flies∣NNS)=0.10P(flies \mid NNS) = 0.10. Transition from a subject noun NNNN: P(VBZ∣NN)=0.30P(VBZ \mid NN) = 0.30 and P(NNS∣NN)=0.05P(NNS \mid NN) = 0.05.

For "Time(NN) flies":

Score VBZ=0.30×0.06=0.0180VBZ = 0.30 \times 0.06 = 0.0180.

Score NNS=0.05×0.10=0.0050NNS = 0.05 \times 0.10 = 0.0050.

VBZVBZ wins by 0.01800.0180 to 0.00500.0050, about 3.6 times larger. That's why the top panel of the diagram tags flies as VBZVBZ. In "Fruit flies" the neighbour pattern flips the transition numbers toward NNSNNS, the same multiplication picks NNSNNS, and like must then be a verb to keep the path valid. Context decides, one multiplication at a time.

Code

This snippet repeats the toy decision and the Viterbi count, so you can check the arithmetic.

def score(trans: float, emit: float) -> float:    return trans * emit

vbz = score(0.30, 0.06)nns = score(0.05, 0.10)print(round(vbz, 4), round(nns, 4))  # -> 0.018 0.005print("VBZ" if vbz > nns else "NNS")  # -> VBZn, t = 5, 36print(n * t * t)  # -> 6480print(t**n)  # -> 60466176

Watch Out For

Running news models on chat or specialist text

A tagger trained on edited news expects capital letters and full sentences. Social posts, legal clauses and biomedical notes break those habits. The symptom is VBZ and NNS swapping on words you thought were easy, while news tests still look fine. The fix is to test on your own sample first, then fine-tune on labelled in-domain text rather than tuning a threshold.

Treating one tag as certain truth

The tagger outputs the most likely path, not a promise. Even strong models miss 2 to 3 tags per 100 on news, more off domain, and one wrong tag can flip a parse edge and a relation. The symptom is a clean pipeline that fails on a few sentences for no clear reason. The fix is to pass tag probabilities forward or keep the top two paths where the next step is sensitive, instead of freezing one hard label.

The Quick Version

  • Part-of-speech tagging writes one grammar label on each token, so flies can be VBZ in one sentence and NNS in the next.
  • The Penn set splits roles finely, with 36 tags such as NN, NNS, VBZ, JJ, RB, DT and IN.
  • Classic scoring multiplies emission by transition, and Viterbi finds the best path in 6480 steps instead of 60,466,176.
  • The toy check gives 0.018 for VBZ against 0.005 for NNS, so VBZ wins after a subject noun.
  • News models slip on chat and specialist text, so test in domain before trusting tags.
  • One wrong tag can mislead parsing, so keep probabilities where the next step is fragile.