← all repositories
kamalkraj/BERT-NER

BERT NER: Python training, C++ inference, and a REST API

A PyTorch implementation of named entity recognition using BERT that ships with a C++ inference path and a lightweight REST API.

1.2k stars Python Language ModelsML Frameworks
BERT-NER
Velocity · 7d
+0.5
★ / day
Trend
steady
star history

What it does

This repo fine-tunes BERT (base and large) on the CoNLL-2003 NER dataset to label people, organizations, locations, and miscellaneous entities. It provides pretrained models, a Python inference wrapper, a C++ libtorch inference binary, and a small REST API served via api.py.

The interesting bit

The C++ inference path is the unusual part. The author traced the model with PyTorch JIT, but had to split it into two pieces—feature extractor and classifier—because jit.trace chokes on input-dependent loops and conditionals inside forward(). It’s a pragmatic hack that gets you a compiled binary without dragging Python into production.

Key highlights

  • Pretrained BERT-base and BERT-large models with reported F1 scores around 0.91–0.95 on CoNLL-2003 test/validation data
  • Python one-liner inference via bert.Ner.predict() with per-token confidence scores
  • C++ inference app using libtorch 1.2.0, with cmake build instructions and a split-model workaround
  • REST API at 0.0.0.0:8000/predict with cURL and Postman examples
  • Unicode support in C++ via the ufal/unilib library

Caveats

  • The README is sparse on architecture details; it’s basically a runnable script collection with results pasted in
  • C++ setup requires manual downloads of libtorch and a converted model from OneDrive links
  • No training code explanation beyond a single command-line invocation

Verdict

Worth a look if you need a quick BERT-NER baseline with a C++ deployment path. Skip it if you want a maintained, well-documented library—this is more of a working recipe than a framework.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.