Skip to main content

πŸ“ 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 tokenPOS tagMeaning
    TheDeterminer (DET)Introduces the noun
    youngAdjective (ADJ)Describes the cat
    catNoun (NOUN)Names an animal
    sleepsVerb (VERB)Describes an action
    peacefullyAdverb (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 supports SPACE for whitespace tokens.

    POS tagCategoryExample
    DETDeterminerthe, a, this book
    PROPNProper nounAlice, London, Google
    NOUNCommon nouncat, book, city
    PRONPronounI, she, they
    VERBVerbrun, eat, write
    AUXAuxiliary verbShe is running
    ADJAdjectivea beautiful picture
    ADVAdverbruns quickly
    ADPAdposition, such as a prepositionin, on, under
    CCONJCoordinating conjunctionand, or, but
    SCONJSubordinating conjunctionbecause, although
    NUMNumeralthree, 42
    PARTParticleto in β€œto run”
    INTJInterjectionwow, oh
    PUNCTPunctuation., ,, !
    SYMSymbol$, +
    XOtherA 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.pos and token.tag return integer identifiers. See the spaCy Token documentation.

    AttributeMeaningExample for cats
    token.pos_Broad grammatical categoryNOUN
    token.tag_More detailed, language-specific tagNNS β€” plural noun
    token.lemma_Dictionary base form; a separate annotation, not a POS tagcat

< 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,” book is a verb. In β€œI read a book,” book is 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.

    TaskWhat it identifiesExample: β€œAlice works at Google”
    POS taggingGrammatical categories of wordsAlice and Google are proper nouns (PROPN); works is a verb (VERB)
    NERNamed entities and their typesAlice is a person; Google is an organization

Implementation​

< Read POS annotations with spaCy >​

  • Setup: install spaCy and its trained English pipeline.

    python -m pip install spacy
    python -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 spacy

    nlp = 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 the
    cats NOUN NNS cat
    were AUX VBD be
    running VERB VBG run
    . PUNCT . .

    For running, VERB is the broad category, VBG identifies a gerund or present participle in the English tag scheme, and run is 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.

Reference​