Live Webinar 5/27: Dive into ParseBench and learn what it takes to evaluate document OCR for AI Agents

Token Classification

Token classification is a foundational natural language processing task that enables machines to understand text at the most granular level—individual words, subwords, or characters. In document workflows powered by LlamaParse, this token-level labeling step helps transform raw OCR output into structured, machine-readable information.

For systems that process real-world documents, token classification often works alongside OCR document classification to determine both what a file is and what each extracted token means within it. Without the ability to label each token meaningfully, OCR output remains an unstructured string of characters with little semantic value. Understanding token classification is essential for anyone building or working with document intelligence, information extraction, or language-aware AI systems.

What Token Classification Does

At its core, token classification is an NLP task in which a label is assigned to each individual token in a sequence of text, rather than to the text as a whole. This granular approach allows models to identify and categorize specific words or subwords within a larger body of text.

A token is the basic unit of text produced during tokenization. It may represent a full word, a subword fragment, or a single character, depending on the tokenizer used.

Each token receives its own label drawn from a predefined set of categories. While each label is assigned at the token level, the token’s position in the sequence and the surrounding context strongly influence the prediction. This is the same core mechanism behind tasks like Named Entity Recognition, where models identify spans corresponding to people, organizations, locations, and dates.

This distinction matters in practice. When an OCR system extracts text from a scanned invoice, token classification is what allows a downstream model to identify which tokens represent a vendor name, which represent a dollar amount, and which are structural filler—turning raw OCR output into structured data.

Token Classification Tasks and Where They Are Used

Token classification powers several core NLP applications where identifying and labeling specific words or phrases within text is required. The table below summarizes the most widely applied token classification tasks, their outputs, and the industries where they are most commonly deployed.

Use Case / Task NameWhat It DoesExample Labels / OutputReal-World Industry Applications
**Named Entity Recognition (NER)**Identifies and categorizes named entities such as people, organizations, locations, and dates within textPERSON, ORG, LOC, DATEHealthcare (extracting diagnoses and medications), Legal (contract party identification), Finance (entity extraction from filings)
**Part-of-Speech (POS) Tagging**Labels each token with its grammatical role within a sentenceNOUN, VERB, ADJ, ADV, PREPSearch engines (query parsing), grammar checking tools, machine translation preprocessing
**Chunking**Groups consecutive tokens into meaningful syntactic phrases such as noun phrases or verb phrasesNP (noun phrase), VP (verb phrase), PP (prepositional phrase)Information retrieval, document summarization, semantic parsing pipelines

Each of these tasks shares the same underlying mechanism—assigning a label to each token—but differs in the label vocabulary and the linguistic or semantic objective being pursued. In document-heavy environments, these workflows are often improved by layout-aware models that use spatial context from the page in addition to the text itself. The outputs from token labeling can also contribute to richer document embeddings used for downstream search, clustering, and analysis.

The Token Classification Pipeline

Token classification follows a structured pipeline in which raw text is tokenized, encoded, processed by a model, and each token is mapped to a predicted label. For teams building document AI systems end to end, a shared developer glossary can be useful for keeping terms like tokenization, embeddings, and classification consistent across implementation and evaluation.

Tokenization

Raw input text is split into tokens using a tokenizer. Common tokenization strategies include:

  • WordPiece (used by BERT): splits words into subword units based on frequency in a training corpus
  • Byte-Pair Encoding (BPE) (used by GPT models): iteratively merges the most frequent character pairs to form subword tokens

Tokenization is a critical preprocessing step because the granularity and vocabulary of the tokenizer directly determine what the model receives as input.

Encoding and Model Inference

Tokens are converted into numerical representations such as token IDs and embeddings and then passed into a model. Transformer-based architectures such as BERT are commonly used for token classification because their attention mechanisms allow each token to incorporate contextual information from the broader sequence.

The model outputs a probability distribution over the label set for each token position, from which the highest-probability label is selected.

Label Decoding with IOB Format

Predicted label indices are decoded back into human-readable category strings. Most token classification systems use the IOB (Inside-Outside-Beginning) format to represent multi-token entities. The table below defines each IOB prefix and illustrates how labels are applied to individual tokens in a sequence.

The following example is drawn from the sentence: "Barack Obama visited Paris."

IOB Prefix / TagFull NameMeaning / FunctionExample TokenExample Full Label
**B-**BeginningMarks the first token of a named entity spanBarackB-PER
**I-**InsideMarks a token that continues a named entity span started by a B- tagObamaI-PER
**O**OutsideMarks a token that does not belong to any named entityvisitedO

This labeling convention allows models to distinguish between the start and continuation of a multi-token entity and tokens that carry no entity label.

Fine-Tuning for Specific Domains

Pre-trained transformer models can be fine-tuned on labeled datasets to adapt to domain-specific classification tasks. For example, a general-purpose NER model can be fine-tuned on clinical notes to recognize medical entities such as drug names and dosages. Similarly, a POS tagger trained on general text can be adapted for legal or financial corpora where domain-specific terminology is prevalent.

Fine-tuning requires a labeled dataset in which each token has been manually annotated with the correct label. It significantly reduces the amount of training data and compute required compared to training a model from scratch. In production settings, teams also need reliable ways to retrieve classifier job results once token-level inference has completed.

Final Thoughts

Token classification is a core NLP technique that enables machines to interpret text at the token level, assigning structured labels to individual words or subwords within a sequence. Its applications—spanning Named Entity Recognition, Part-of-Speech tagging, and chunking—are foundational to document intelligence, information extraction, and language-aware AI systems. Its value becomes even clearer in OCR-heavy pipelines, where extraction quality directly affects every downstream label; this deep dive into turning PDFs into text shows why accurate parsing is so important before token classification begins.

LlamaParse delivers VLM-powered agentic OCR that goes beyond simple text extraction, boasting industry-leading accuracy on complex documents without custom training. By leveraging advanced reasoning from large language and vision models, its agentic OCR engine intelligently understands layouts, interprets embedded charts, images, and tables, and enables self-correction loops for higher straight-through processing rates over legacy solutions. LlamaParse employs a team of specialized document understanding agents working together for unrivaled accuracy in real-world document intelligence, outputting structured Markdown, JSON, or HTML. It's free to try today and gives you 10,000 free credits upon signup.

Start building your first document agent today

PortableText [components.type] is missing "undefined"