For the complete documentation index, see llms.txt. This page is also available as Markdown.

Token Classification (NER)

This cookbook walks through building, deploying, and using a Named Entity Recognition (NER) model with Encoderfile. We'll use BERT fine-tuned for NER to identify people, organizations, and locations in text.

What You'll Learn

  • Export a token classification model to ONNX

  • Build a self-contained encoderfile binary

  • Deploy as a REST API server

  • Make predictions via HTTP

  • Use CLI for batch processing

Prerequisites

  • encoderfile CLI tool installed (Installation Guide)

  • Python with optimum[exporters] for ONNX export

  • curl for testing the API


Step 1: Export the Model

We'll use dslim/bert-base-NER, a BERT model fine-tuned for named entity recognition.

About the Model

This model recognizes 4 entity types:

  • PER - Person names

  • ORG - Organizations

  • LOC - Locations

  • MISC - Miscellaneous entities

Export to ONNX

What files are created?

The export creates:


Step 2: Create Configuration

Create a YAML configuration file for building the encoderfile.


Step 3: Build the Binary

Build your self-contained encoderfile binary:

The resulting binary is completely self-contained - it includes:

  • ONNX model weights

  • Tokenizer

  • Full inference runtime

  • REST and gRPC servers


Step 4: Start the Server

Launch the encoderfile server:

Server Startup

The server is now running with both HTTP and gRPC endpoints.


Step 5: Make Predictions

Now let's test the NER model with different types of text.

Example 1: Basic Entity Recognition

Example 2: Multiple Sentences

Step 6: CLI Inference

For batch processing or one-off predictions, use the CLI directly:

Single Input

Batch Processing

This saves all results to results.json for further processing.


Advanced Usage

Custom Ports

HTTP Only (Disable gRPC)

Production Deployment


Understanding the Output

Token Classification Labels

The model uses the IOB (Inside-Outside-Beginning) tagging scheme:

Prefix
Meaning
Example

B-

Beginning of entity

B-PER for "Barack" in "Barack Obama"

I-

Inside/continuation

I-PER for "Obama" in "Barack Obama"

O

Outside any entity

O for "is" or "the"

Entity Types

Label
Description
Examples

PER

Person names

"John Smith", "Marie Curie"

ORG

Organizations

"Apple Inc.", "United Nations"

LOC

Locations

"Paris", "California", "Mount Everest"

MISC

Miscellaneous

"iPhone", "Nobel Prize"

Response Format


Troubleshooting

Unexpected Entity Recognition

Solution: Fine-tune on domain-specific data or use a specialized model.

Performance Optimization

If inference is slow:

Server Connection Issues


Next Steps


Summary

You've learned to:

  • ✅ Export a token classification model to ONNX

  • ✅ Build a self-contained encoderfile binary

  • ✅ Deploy as a REST API server

  • ✅ Make predictions via HTTP and CLI

  • ✅ Understand NER output format

The encoderfile you built is production-ready and can be deployed anywhere without dependencies!

Last updated