Skip to content
AI360Xpert

Part-of-Speech Tagging

Every word plays a grammatical role — noun, verb, adjective. A POS tagger assigns the most probable role to each word given its context, resolving ambiguities like whether "flies" is a verb or a noun.

Every word plays a grammatical role — noun, verb, adjective. A POS tagger assigns the most probable role to each word given its context, resolving ambiguities like whether 'flies' is a verb or a noun.
Every word plays a grammatical role — noun, verb, adjective. A POS tagger assigns the most probable role to each word given its context, resolving ambiguities like whether 'flies' is a verb or a noun.

Why Does This Exist?

Human language is intensely ambiguous at the surface level. Words are not statically mapped to a single meaning or a single grammatical function; instead, their role is dynamically determined by the company they keep. Consider a simple word like "bank." Without the surrounding context, it could be a noun referring to a financial institution, a noun referring to the side of a river, or a verb meaning to rely on something. Similarly, "light" can operate as a noun (the light in the room), a verb (light the fire), or an adjective (a light feather).

If a natural language processing system attempts to understand a sentence by merely looking up each word in a dictionary, it will quickly fail. Without knowing each word's specific grammatical role in the exact sentence it appears, downstream tasks — such as syntactic parsing, named entity recognition (NER), relation extraction, and semantic role labeling — are essentially operating on an ambiguous soup of text.

Part-of-speech (POS) tagging solves this foundational problem. It acts as an early stage in the NLP pipeline that assigns exactly one grammatical label (a tag) to every token in a sequence. By using the surrounding words as context, a POS tagger resolves the surface ambiguity. Once every word is confidently tagged as a noun, verb, adjective, preposition, and so on, the text becomes structurally predictable. This structured foundation enables all deeper semantic and syntactic analysis that follows.

Think of It Like This

A grammar teacher marking up a sentence

Imagine a grammar teacher analyzing a sentence on a whiteboard. They circle each word and label it: noun, verb, adjective. To do this correctly, they don't just look at a word in isolation; they look at the whole sentence. For example, in "The light switch," the presence of "The" and "switch" tells them that "light" must be an adjective describing the switch. In "Light the switch," the position at the start of a command makes "Light" a verb.

A POS tagger does exactly the same thing algorithmically. It does not just maintain a static dictionary of words and their possible parts of speech. Instead, it looks at the sequence and calculates which grammatical label makes the entire sentence structure most statistically probable, using the context of surrounding words to lock in the correct tag.

How It Actually Works

POS tagging is fundamentally a sequence labeling problem: given a sequence of nn words, the task is to output a sequence of nn tags.

The tag set

Before a model can assign tags, it needs a standardized vocabulary of tags. The most common standard for English is the Penn Treebank tag set, which contains 36 detailed tags. By splitting broad categories into specific sub-categories, models can capture finer grammatical nuances.

Key tags include:

  • NN — singular noun ("dog", "idea")
  • NNS — plural noun ("dogs", "ideas")
  • NNP — proper noun ("London", "Alice")
  • VB — verb base form ("run", "eat")
  • VBD — verb past tense ("ran", "ate")
  • VBZ — verb, 3rd person singular present ("runs", "eats")
  • JJ — adjective ("fast", "bright")
  • RB — adverb ("quickly", "well")
  • DT — determiner ("the", "a", "this")
  • IN — preposition or subordinating conjunction ("in", "because", "under")

Classic approach: Hidden Markov Models

For many years, the dominant algorithmic approach to POS tagging was the Hidden Markov Model (HMM). An HMM tagger is a generative model that mathematically formalizes the intuition of context using two distinct probabilities:

  1. Emission probability (P(witi)P(w_i | t_i)): Given a specific POS tag, how likely is it to emit the current word? For instance, P("dog"NN)P(\text{"dog"} | \text{NN}) is relatively high, while P("dog"VB)P(\text{"dog"} | \text{VB}) is much lower, though non-zero (as in "to dog someone's footsteps").
  2. Transition probability (P(titi1)P(t_i | t_{i-1})): Given the previous tag, what is the probability of transitioning to the current tag? For example, P(NNDT)P(\text{NN} | \text{DT}) is exceptionally high because a determiner (like "the") is almost always followed by a noun or an adjective, never by a verb.

To tag a new sentence, the model must find the sequence of tags T=(t1,t2,...,tn)T = (t_1, t_2, ..., t_n) that maximizes the joint probability of the words and the tags. Because testing every possible tag combination is computationally explosive, HMMs use the Viterbi algorithm. Viterbi is a dynamic programming algorithm that finds the optimal tag sequence in O(nT2)O(n \cdot |T|^2) time by discarding sub-optimal paths at each step.

Modern approach: Neural Sequence Labelers

While HMMs are fast and mathematically elegant, they only capture a limited window of context (usually just the immediate preceding tag). Current state-of-the-art POS taggers abandon the Markov assumption entirely, leveraging deep learning to look at the entire sentence simultaneously.

Modern architectures typically use a Bidirectional LSTM or a Transformer encoder. These models convert each token into a dense vector embedding, then process the sequence in both directions (left-to-right and right-to-left). This means the representation of the word "flies" in a specific sentence contains information from all words that come before it and all words that come after it.

Finally, a classification layer assigns a tag probability distribution at each position. In robust systems, this is often a Conditional Random Field (CRF) layer, which enforces global sequence validity (for instance, ensuring that a preposition IN cannot immediately follow another preposition IN without a valid grammatical reason). These neural approaches consistently achieve accuracy above 97% on standard English benchmarks like the Penn Treebank.

Why context is essential

Let us see how context explicitly resolves ambiguity in two classic test sentences:

  1. "Time flies like an arrow."
  2. "Fruit flies like a banana."

In the first sentence, the surrounding context forces "flies" to be tagged as VBZ (verb). In the second, "Fruit" acting as a noun modifier heavily biases "flies" to be tagged as NNS (plural noun), which subsequently forces "like" to be a verb (VBP) rather than a preposition (IN). Both the transition matrices in an HMM and the attention mechanism in a Transformer exploit exactly this structural dependency.

Code

import spacy
# Load the small English model, which includes a CNN-based taggernlp = spacy.load("en_core_web_sm")
sentences = [    "Time flies like an arrow.",    "Fruit flies like a banana.",]
for sent in sentences:    doc = nlp(sent)    print(f"\nSentence: {sent}")    # token.pos_ gives the coarse-grained tag, token.tag_ gives the fine-grained Penn Treebank tag    for token in doc:        print(f"  {token.text:<12} POS={token.pos_:<8} Tag={token.tag_:<6} Dep={token.dep_}")

Output:

Sentence: Time flies like an arrow.  Time         POS=NOUN     Tag=NN     Dep=nsubj  flies        POS=VERB     Tag=VBZ    Dep=ROOT  like         POS=ADP      Tag=IN     Dep=prep  an           POS=DET      Tag=DT     Dep=det  arrow        POS=NOUN     Tag=NN     Dep=pobj
Sentence: Fruit flies like a banana.  Fruit        POS=NOUN     Tag=NN     Dep=compound  flies        POS=NOUN     Tag=NNS    Dep=ROOT  like         POS=ADP      Tag=IN     Dep=prep  a            POS=DET      Tag=DT     Dep=det  banana       POS=NOUN     Tag=NN     Dep=pobj

Notice how "flies" is VBZ (verb) in the first sentence and NNS (plural noun) in the second. The tagger leverages the context perfectly to disambiguate the token.

Watch Out For

Domain shift breaking accuracy

POS taggers trained on structured, grammatically correct corpora like the Wall Street Journal (part of the Penn Treebank) perform exceptionally well on news text. However, they will experience a severe drop in accuracy if applied directly to social media posts, legal contracts, or biomedical literature. The vocabulary, capitalization rules, and grammatical patterns differ fundamentally. Always evaluate your tagger on in-domain samples, and fine-tune on annotated in-domain data if accuracy drops below acceptable levels.

Treating tags as absolute ground truth

A POS tagger outputs the mathematically most probable tag sequence, but it is not infallible. Even state-of-the-art models have error rates of 2–3% on standard text, and higher on out-of-domain text. Because POS tagging sits early in the NLP pipeline, an incorrect tag will propagate and cause errors in downstream tasks like dependency parsing or relation extraction. When designing complex pipelines, ensure downstream components are robust to occasional tagging errors, or pass forward the top-k tag probabilities rather than just a single hard label.

The Quick Version

  • POS tagging assigns a grammatical role (like noun, verb, adjective, preposition) to each token in a sentence.
  • Context is what resolves ambiguity: the exact same word can receive entirely different tags depending on its neighbors.
  • Classic approaches use Hidden Markov Models (HMMs) to calculate emission and transition probabilities, utilizing the Viterbi algorithm to decode the optimal sequence.
  • Modern neural taggers use Bidirectional LSTMs or Transformers paired with a CRF layer, regularly exceeding 97% accuracy on standard English datasets.
  • POS tags are foundational features that feed directly into downstream syntactic parsing, named entity recognition, and information extraction systems.