Instructions to use DanKau/en_core_web_trf-3.8.0-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- spaCy
How to use DanKau/en_core_web_trf-3.8.0-onnx with spaCy:
!pip install https://huggingface.co/DanKau/en_core_web_trf-3.8.0-onnx/resolve/main/en_core_web_trf-3.8.0-onnx-any-py3-none-any.whl # Using spacy.load(). import spacy nlp = spacy.load("en_core_web_trf-3.8.0-onnx") # Importing as module. import en_core_web_trf-3.8.0-onnx nlp = en_core_web_trf-3.8.0-onnx.load() - Notebooks
- Google Colab
- Kaggle
spaCy en_core_web_trf 3.8.0 β NER (ONNX)
ONNX export of the transformer + NER components of
en_core_web_trf 3.8.0, the English
transformer pipeline trained by Explosion on OntoNotes 5. Exported with
spaCy 3.8.7. All weights and tokenizer rules come from the released checkpoint β nothing was
retrained, distilled, or substituted.
The pipeline's tagger, parser, attribute_ruler and lemmatizer are not included.
This export answers "which entities are in this text", not "what is the parse of this text",
and its output is therefore not comparable to the model card's full-pipeline benchmark.
spaCy's NER is a transition-based parser, not a token classifier: it walks a state machine one word at a time, and the next action depends on the action just taken. That data-dependent loop is what makes the pipeline resist a single-graph export. The split here leaves the loop to the host and puts everything with weights in it into ONNX β three graphs, one of which is re-run per word against a cache computed once per document.
Exported for SecuPi's unstructured AI service (SPAI), which runs it through ONNX Runtime from Java with no Python at inference time. Published so that service can fetch it without a spaCy or PyTorch dependency; anyone else is welcome to use it under the same licence as the base model.
Files
| file | what it is |
|---|---|
onnx/encoder.onnx |
the checkpoint's trained roberta-base (curated-transformers), sub-word piece ids to 768-d piece vectors. |
onnx/precompute.onnx |
the learned 768β64 token projection (tok2vec's final linear), then the NER head's lower affine transform pre-applied for all three state features, with the trained padding row prepended. Run once per document. |
onnx/transition.onnx |
gather the three state features out of that cache, sum, add the bias, maxout over the two pieces, and mask the actions never seen in training. Emits the 74 action scores. Run once per word. |
spacy_config.json |
window/stride, hidden size, BOS/EOS ids, and the ordered 74-action list β the decode contract. |
spacy_tokenizer.json |
the English rule tokenizer: prefix/suffix/infix/URL regexes and the 1,347 tokenizer exceptions, taken from the pinned pipeline. |
tokenizer.json |
the byte-level BPE in HuggingFace tokenizers form, rebuilt from the checkpoint's own vocab and merges so it can be loaded by any tokenizers binding. Verified piece-for-piece against spaCy's own piece encoder. |
There is no .onnx.data: the encoder stays under the 2 GB protobuf limit.
How to run it
The neural parts are here; the tokenization, windowing, pooling and state machine are yours.
Tokenize with spaCy's rules, from
spacy_tokenizer.jsonβ split on whitespace, then apply exceptions, prefixes, suffixes, URL match and infixes. Entity offsets are word offsets, so a tokenizer that disagrees with spaCy's shifts every span it produces. Note whitespace tokens are real tokens with no sub-words.Encode each word as
bpe(" " + word)when a space precedes it,bpe(word)otherwise, and record each word's piece count. Prepend BOS (0) and append EOS (2) to the stream.Window the whole piece stream β BOS and EOS included β at
window144 withstride104, runencoder.onnxon each window, and average the overlaps (a piece covered by two windows gets the mean of its two vectors, not the last one). This is what spaCy'swith_spansstrided-spans layer does, and skipping the average changes the entities on any text over 144 pieces.Mean-pool each word's pieces into one 768-d vector. A word with zero pieces pools to zeros.
Run
precompute.onnxonce over allWword vectors βcachedof shape[W+1, 3, 74, 2]. Row 0 is the trained padding vector, so wordwlives at roww + 1β which is why the state features below are passed as-1-based indices and incremented in the graph.Walk the state machine. State features are three word indices:
[current word, first word of the open entity or -1, last word of the open entity or -1]. Runtransition.onnxwithcachedand thatcontext, take the highest-scoring valid action, apply it, and repeat until every word is consumed. Validity is the BILUO grammar:action valid when Ono entity is open B-Xno entity is open, this is not the last word, Xnon-emptyU-Xno entity is open, Xnon-emptyI-Xan entity of type Xis open and this is not the last wordL-Xan entity of type Xis openB/Uopen an entity at the current word;L/Uclose one, emitting the span from the opening word's start offset to the current word's end offset. Actions are indexed by their position inspacy_config.json'sactions.
18 entity types: PERSON, ORG, GPE, LOC, FAC, NORP, PRODUCT, EVENT,
WORK_OF_ART, LAW, LANGUAGE, DATE, TIME, PERCENT, MONEY, QUANTITY, ORDINAL,
CARDINAL.
Scores
There are none, and this is not a limitation of the export. A greedy transition parser
commits to one action per word; the action score is an unnormalised maxout activation over a
state, not a probability of the entity being right, and it is not comparable across states or
across documents. spaCy's own Doc.ents carries no per-entity confidence either. Emit a
constant for a hard prediction rather than passing the activation off as one β a threshold over
these numbers filters nothing meaningful.
Parity
The exporter checks each graph against the PyTorch module it came from at export time, and then replays 13 texts end to end β including a 315-token document spanning four encoder windows, emoji, non-ASCII names, URLs, and text with no entities at all β asserting that the token offsets, piece ids, per-graph outputs and final entity spans equal what native spaCy 3.8.7 produces on the same input. The same 13 fixtures are replayed from the Java runtime.
Tolerances: 2e-4 on the encoder and precompute graphs, 2e-3 on transition scores, and
exact equality on the resulting entity spans and labels.
Licence and credit
MIT, following the base model. The weights are Explosion's, from
en_core_web_trf 3.8.0;
this repository only changes their serialisation format.
Model tree for DanKau/en_core_web_trf-3.8.0-onnx
Base model
spacy/en_core_web_trf