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.
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 words , output tags , one per word. Tag names the grammatical role of word 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. is a singular noun such as dog, a plural noun such as dogs, a proper noun such as London, a base verb such as run, a past verb such as ran, a present verb with he or she such as runs, an adjective such as fast, an adverb such as quickly, a determiner such as the, 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 is the chance of seeing this word given this tag, so is high and is tiny but not zero. Transition is the chance of this tag after the last tag, so is high because the almost always precedes a noun or adjective, never a verb. The score of a full tag path is the product of those terms, and decoding picks the path with the top product.
Checking every path is hopeless. With tags and words there are paths. The Viterbi algorithm keeps only the best partial path into each tag at each step, which costs , here 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 and . Transition from a subject noun : and .
For "Time(NN) flies":
Score .
Score .
wins by to , about 3.6 times larger. That's why the top panel of the diagram tags flies as . In "Fruit flies" the neighbour pattern flips the transition numbers toward , the same multiplication picks , 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) # -> 60466176Watch 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.