POS tagging
Spanish language
NLTK
natural language processing
computational linguistics

POS tagging in spanish with NLTK?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

NLTK does not have the same polished out-of-the-box Spanish POS tagging experience that it has for English, but you can still do Spanish tagging with it. The usual approach is to train an NLTK tagger on a Spanish-tagged corpus such as cess_esp.

That is good enough for experiments, teaching, and lightweight NLP tasks. For production-grade Spanish tagging, many teams eventually move to spaCy or Stanza, but NLTK is still useful when you want to understand the tagging pipeline directly.

Use the Spanish CESS Corpus

NLTK ships access to the cess_esp corpus, which contains tagged Spanish sentences. You can use it to train a unigram or bigram tagger.

python
1import nltk
2from nltk.corpus import cess_esp
3from nltk.tag import UnigramTagger, BigramTagger
4
5nltk.download("cess_esp")
6nltk.download("universal_tagset")
7
8tagged_sents = cess_esp.tagged_sents(tagset="universal")
9split = int(len(tagged_sents) * 0.9)
10
11train_sents = tagged_sents[:split]
12test_sents = tagged_sents[split:]
13
14unigram = UnigramTagger(train_sents)
15bigram = BigramTagger(train_sents, backoff=unigram)
16
17print("accuracy:", bigram.evaluate(test_sents))

Using the universal tagset keeps the output easier to read because it maps language-specific labels to a smaller shared tag inventory.

Tag a Spanish Sentence

Once the tagger is trained, tagging is straightforward:

python
tokens = "El perro negro corre rápidamente".split()
print(bigram.tag(tokens))

A typical result looks like a list of token-tag pairs:

text
[('El', 'DET'), ('perro', 'NOUN'), ('negro', 'ADJ'), ('corre', 'VERB'), ('rápidamente', 'ADV')]

This is a simple whitespace-tokenized example. In real text, tokenization quality matters because punctuation and contractions affect tagging accuracy.

Why Spanish Tagging Is Harder Than It Looks

Spanish has richer morphology than English. Verb forms, gender agreement, number agreement, and clitics create more ambiguity, so a tagger trained on a limited corpus can make mistakes even when the code is correct.

For example, a word such as canto can be a noun or a verb form depending on context. A unigram tagger may struggle when it has not seen enough examples of both uses.

That is why adding a backoff chain or moving to stronger sequence models often helps.

NLTK Is a Framework, Not a Magic Spanish Model

One common misunderstanding is expecting nltk.pos_tag(...) to work for Spanish the same way it does for English. The standard English tagger is not a Spanish tagger.

With NLTK, the realistic Spanish workflow is:

  • choose a Spanish-tagged corpus
  • train a tagger on that corpus
  • evaluate it on held-out data

That gives you control, but it also means you are responsible for the quality of the training data and the model choice.

When to Use Another Library

If you need stronger Spanish linguistic support, including lemmatization, dependency parsing, and modern pretrained pipelines, spaCy or Stanza are often better tools.

Still, NLTK remains useful when:

  • you want to teach or learn tagging mechanics
  • you need a lightweight baseline
  • you want to prototype with classic tagger types

It is also useful when you want full visibility into how the tagger was trained instead of relying on a large pretrained black box.

Common Pitfalls

  • Calling the default English POS tagger and expecting correct Spanish output.
  • Forgetting to download cess_esp or the universal tagset resources before training.
  • Using naive tokenization on messy real-world Spanish text.
  • Judging the tagger on a few hand-picked sentences instead of evaluating it on held-out corpus data.
  • Expecting an NLTK unigram or bigram tagger to match modern neural taggers on complex Spanish text.

Summary

  • Spanish POS tagging with NLTK is possible, but it usually means training on cess_esp rather than using the default English tagger.
  • A unigram or bigram tagger with backoff is a practical NLTK baseline.
  • Use the universal tagset if you want cleaner, easier-to-read labels.
  • Tokenization and corpus quality strongly affect tagging accuracy.
  • For production-quality Spanish NLP, consider spaCy or Stanza after establishing an NLTK baseline.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.