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.

  1. 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.

  2. 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.

  3. Window the whole piece stream β€” BOS and EOS included β€” at window 144 with stride 104, run encoder.onnx on 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's with_spans strided-spans layer does, and skipping the average changes the entities on any text over 144 pieces.

  4. Mean-pool each word's pieces into one 768-d vector. A word with zero pieces pools to zeros.

  5. Run precompute.onnx once over all W word vectors β†’ cached of shape [W+1, 3, 74, 2]. Row 0 is the trained padding vector, so word w lives at row w + 1 β€” which is why the state features below are passed as -1-based indices and incremented in the graph.

  6. 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]. Run transition.onnx with cached and that context, take the highest-scoring valid action, apply it, and repeat until every word is consumed. Validity is the BILUO grammar:

    action valid when
    O no entity is open
    B-X no entity is open, this is not the last word, X non-empty
    U-X no entity is open, X non-empty
    I-X an entity of type X is open and this is not the last word
    L-X an entity of type X is open

    B/U open an entity at the current word; L/U close one, emitting the span from the opening word's start offset to the current word's end offset. Actions are indexed by their position in spacy_config.json's actions.

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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for DanKau/en_core_web_trf-3.8.0-onnx

Quantized
(1)
this model