π Part-of-Speech (POS) Tagging
Descriptionβ
< What is it? >β
-
Meaning: Part-of-Speech (POS) tagging assigns a grammatical category to each word in a sentence, such as noun, verb, adjective, or adverb. It is a token-labeling task.
-
Example: βThe young cat sleeps peacefully.β
Word or token POS tag Meaning The Determiner ( DET)Introduces the noun young Adjective ( ADJ)Describes the cat cat Noun ( NOUN)Names an animal sleeps Verb ( VERB)Describes an action peacefully Adverb ( ADV)Describes how it sleeps . Punctuation ( PUNCT)Ends the sentence These labels follow the Universal Dependencies POS tag set. Other tag sets may use different labels.
Key pointsβ
< POS annotations in spaCy >β
-
Meaning: POS annotations are grammatical labels attached to tokens. POS tagging is the process; POS annotations are the resulting labels.
-
Categories:
token.pos_provides broad categories such as determiner, proper noun, and verb. The table below lists the Universal POS categories; spaCy also supportsSPACEfor whitespace tokens.POS tag Category Example DETDeterminer the, a, this book PROPNProper noun Alice, London, Google NOUNCommon noun cat, book, city PRONPronoun I, she, they VERBVerb run, eat, write AUXAuxiliary verb She is running ADJAdjective a beautiful picture ADVAdverb runs quickly ADPAdposition, such as a preposition in, on, under CCONJCoordinating conjunction and, or, but SCONJSubordinating conjunction because, although NUMNumeral three, 42 PARTParticle to in βto runβ INTJInterjection wow, oh PUNCTPunctuation ., ,, ! SYMSymbol $, + XOther A token that cannot be assigned another category -
Example: βAlice reads a book.β
Alice β PROPN (proper noun)reads β VERB (verb)a β DET (determiner)book β NOUN (common noun). β PUNCT (punctuation) -
spaCy attributes: the trailing underscore gives the readable string. Without it,
token.posandtoken.tagreturn integer identifiers. See the spaCy Token documentation.Attribute Meaning Example for catstoken.pos_Broad grammatical category NOUNtoken.tag_More detailed, language-specific tag NNSβ plural nountoken.lemma_Dictionary base form; a separate annotation, not a POS tag cat
< Context determines the tag >β
-
Context: the same word can have different grammatical categories depending on its use in a sentence.
-
Example: in βI book a flight,β
bookis a verb. In βI read a book,βbookis a noun.
< What is POS tagging used for? >β
- Grammatical analysis: tags describe word categories. Finding relationships such as subject and object requires additional syntactic analysis.
- Information extraction: tags can help identify useful patterns, such as an adjective followed by a noun in βyoung cat.β
Comparisonβ
< POS tagging vs. Named Entity Recognition >β
-
Different labels: POS tagging identifies grammatical categories, while Named Entity Recognition (NER) identifies entity spans and types such as people, organizations, and locations.
Task What it identifies Example: βAlice works at Googleβ POS tagging Grammatical categories of words AliceandGoogleare proper nouns (PROPN);worksis a verb (VERB)NER Named entities and their types Aliceis a person;Googleis an organization
Implementationβ
< Read POS annotations with spaCy >β
-
Setup: install spaCy and its trained English pipeline.
python -m pip install spacypython -m spacy download en_core_web_sm -
Example: process the complete sentence, then inspect each token's text, broad POS, detailed tag, and lemma.
import spacynlp = spacy.load("en_core_web_sm")doc = nlp("The cats were running.")for token in doc:print(token.text, token.pos_, token.tag_, token.lemma_)Illustrative output (not executed here; predictions depend on the pipeline):
The DET DT thecats NOUN NNS catwere AUX VBD berunning VERB VBG run. PUNCT . .For
running,VERBis the broad category,VBGidentifies a gerund or present participle in the English tag scheme, andrunis the lemma. -
Pipeline requirement:
spacy.blank("en")alone tokenizes text but does not predict POS tags. A suitable trained pipeline supplies these annotations. POS information also supports rule-based lemmatization. See spaCy's linguistic features guide.
Related ideasβ
- Named Entity Recognition (NER) labels entity spans in text.
- Classification explains predicting category labels.
Referenceβ
- spaCy: Linguistic features
- spaCy: Token attributes
- Universal POS tags (Universal Dependencies)
- CoNLL-U format explains how POS tags and syntactic annotations are stored.