bert-base-NER-onnx

An ONNX export of dslim/bert-base-NER for named entity recognition (NER). It tags people, organisations, locations and other names (MISC) in text.

Base model dslim/bert-base-NER
Base revision (inferred) d1a3e8f13f8c3566299d95fcfc9a8d2382a9affc
ONNX files revision d98b0f83171d36e39b70a719a4cabb10dc8b888c
Licence MIT
Used by SqueakyCleanText

How it was exported

The export used SqueakyCleanText's scripts/export_onnx_models.py, first committed the same day, shortly after the upload (commit f9e4a42). That version runs python -m optimum.exporters.onnx --model dslim/bert-base-NER --task token-classification.

  • Uploaded on 2026-02-23.
  • The script does not pin a base revision, so it exported the base repo's main branch. The base revision above is inferred: it is the last base commit before the upload (2024-10-08), it is still main today, and the parity check below matches it.
  • ONNX opset 18, IR version 8. The graph's producer field says pytorch 2.10.0.
  • Weights are FP32. The script has no quantisation or optimisation step.
  • Device: no --device flag (the exporter default, CPU).
  • Extra export flags: none.
  • Files: model.onnx (431 MB), config.json, tokenizer.json, tokenizer_config.json, special_tokens_map.json.
  • Inputs: input_ids, attention_mask, token_type_ids. Output: logits, one row per token.

Parity check

On 2026-11-17 the ONNX model and the original PyTorch model (revision d1a3e8f13f8c) were run on the same fixed sample: 3 sentences, 52 tokens. Each side used its own tokenizer. CPU only, with Python 3.12.15, torch 2.15.0, transformers 4.57.6, onnxruntime 1.32.0 and tokenizers 0.22.2.

Check Result
Token IDs, ONNX tokenizer vs base tokenizer identical
id2label, ONNX config vs base config identical
Same top label for each token 52 / 52
Largest absolute logit difference 8.6e-06

This is a small sample. It shows that the ONNX model matches the original on these inputs. It does not prove a match on every input, and it is not an accuracy score.

How to use it

With SqueakyCleanText

SqueakyCleanText (SCT) does not load this model by default. To use it as SCT's English model, set ner_models. SCT does not pin a custom repo, so pass the revision too:

# pip install squeakycleantext
from sct import TextCleaner, TextCleanerConfig
from sct.config import DEFAULT_NER_MODELS

cfg = TextCleanerConfig(
    ner_models={**DEFAULT_NER_MODELS, "ENGLISH": "rhnfzl/bert-base-NER-onnx"},
    ner_model_revisions={"ENGLISH": "d98b0f83171d36e39b70a719a4cabb10dc8b888c"},
)
print(TextCleaner(cfg=cfg).process("John Smith works at Microsoft in Seattle.").lm_text)

The ENGLISH key is not only for English text. SCT also runs it inside the Dutch, German and Spanish ensembles and as the fallback for every other language, so this English-only model would run on that text too.

SCT's default config also loads the MULTILINGUAL model, rhnfzl/wikineural-multilingual-ner-onnx, which is CC BY-NC-SA 4.0 (non-commercial research only). The SCT docs (model licences) show how to run without it.

With onnxruntime

# pip install onnxruntime tokenizers huggingface_hub numpy
import json
import numpy as np
import onnxruntime as ort
from huggingface_hub import snapshot_download
from tokenizers import Tokenizer

path = snapshot_download("rhnfzl/bert-base-NER-onnx", revision="d98b0f83171d36e39b70a719a4cabb10dc8b888c")
tokenizer = Tokenizer.from_file(f"{path}/tokenizer.json")
id2label = json.load(open(f"{path}/config.json"))["id2label"]
session = ort.InferenceSession(f"{path}/model.onnx", providers=["CPUExecutionProvider"])

enc = tokenizer.encode("John Smith works at Microsoft in Seattle.")
inputs = {"input_ids": [enc.ids], "attention_mask": [enc.attention_mask], "token_type_ids": [enc.type_ids]}
feed = {i.name: np.array(inputs[i.name], dtype=np.int64) for i in session.get_inputs()}
logits = session.run(None, feed)[0][0]
for token, label_id in zip(enc.tokens, logits.argmax(-1)):
    print(token, id2label[str(label_id)])

This prints one label per sub-word token. Group the tokens into entities yourself, or use SqueakyCleanText. Input longer than 512 tokens must be split first.

Labels

From config.json (id2label, in index order): O, B-MISC, I-MISC, B-PER, I-PER, B-ORG, I-ORG, B-LOC, I-LOC.

SqueakyCleanText maps PER, ORG, LOC and MISC to <PERSON>, <ORGANISATION>, <LOCATION> and <MISC>.

Limits

  • No accuracy number for this model exists in the SqueakyCleanText benchmarks (checked: everything under benchmarks/results/, up to SCT 0.10.0). No SCT benchmark loads this model. For the base model's own scores, see the base model card.
  • This is a format conversion only. It has the same skills, gaps and biases as the base model, which was trained on CoNLL-2003 (English). Read the limits section of the base model card too.
  • It knows only the labels above. It does not find e-mail addresses, phone numbers, IDs or other PII types.

Licence

The base model card says license: mit. This export keeps that licence.

Credit for the model goes to the authors of dslim/bert-base-NER. This repo only changes the file format. If you use this model in your work, cite the base model as its card asks.

Downloads last month
34
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for rhnfzl/bert-base-NER-onnx

Quantized
(10)
this model

Dataset used to train rhnfzl/bert-base-NER-onnx