Instructions to use masahiroid/bert-base-ner-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use masahiroid/bert-base-ner-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download masahiroid/bert-base-ner-mlx --local-dir bert-base-ner-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
bert-base-ner-mlx
ζ₯ζ¬θͺηγ―γγ‘γ (README.ja.md)
Model Summary
This is an unofficial MLX conversion of dslim/bert-base-NER (a standard BERT-base with a named-entity-recognition head on top, trained on CoNLL-2003: PER/ORG/LOC/MISC). All credit for the original model goes to its author.
This cannot be loaded with mlx-embeddings
mlx-embeddings targets pooled embedding/reranker outputs and doesn't
support a per-token classification head. This model was reimplemented from
scratch for MLX and requires the bundled bert_ner_mlx.py. The
architecture itself is simple: a standard post-norm BERT encoder plus a
linear classification head.
Usage
import mlx.core as mx
from mlx.utils import tree_unflatten
from transformers import AutoTokenizer
from bert_ner_mlx import BertNerMLX
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
model = BertNerMLX()
weights = mx.load("model.safetensors")
model.update(tree_unflatten(list(weights.items())))
mx.eval(model.parameters())
text = "My name is Wolfgang and I live in Berlin, working at Hugging Face."
inputs = tokenizer(text, return_tensors="np")
input_ids = mx.array(inputs["input_ids"])
attention_mask = mx.array(inputs["attention_mask"])
logits = model(input_ids, attention_mask=attention_mask) # (1, seq_len, 9)
labels = logits.argmax(-1)[0].tolist()
tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
for tok, label_id in zip(tokens, labels):
print(tok, model.config.id2label[label_id] if hasattr(model, "config") else label_id)
Labels are the same as the original model: {0: "O", 1: "B-MISC", 2: "I-MISC", 3: "B-PER", 4: "I-PER", 5: "B-ORG", 6: "I-ORG", 7: "B-LOC", 8: "I-LOC"}.
Accuracy
Compared against the PyTorch fp32 reference on a real sentence containing person/location/organization entities:
| Precision | Logits cosine sim. | Label agreement |
|---|---|---|
| MLX fp32 | 1.0 | 100% |
| MLX fp16 (this release) | 0.99999994 | 100% |
During fp16 conversion, using an attention-mask value like -1e9 (which
doesn't fit in fp16) caused 0 * (-inf) = NaN at unmasked (mask=1)
positions. Fixed by switching to -1e4, which fits fp16's range (full
details are in the conversion-toolkit repo, not SECURITY.md).
Specs
| Item | Value |
|---|---|
| Base model | dslim/bert-base-NER (BERT-base, 108M params) |
| Precision | float16 |
| Framework | MLX (from-scratch bert_ner_mlx.py) |
Notes
- This is a community conversion, not an official release from the original author.
- Security audit uses model-audit-lite
(see
SECURITY.mdfor details).
Security
Audited against its upstream with model-audit-lite: weight format, bundled code, and a machine-readable lineage (ML-BOM). Details, checksums and how to reproduce: SECURITY.md.
Quantized
Model tree for masahiroid/bert-base-ner-mlx
Base model
dslim/bert-base-NER