Guide · spaCy
Custom NER in spaCy, without training data
Updated 26 November 2026, by Jungroo AI Labs, the makers of ReDefiNER
spaCy's trained pipelines find general types: people, organisations, places, dates. For your own types, such as product models, error codes or order numbers, the usual route is to label examples and train a NER model, or to write EntityRuler patterns. The spacy-redefiner component adds a third route: describe each type in a plain-English rulebook and a 0.8B model, ReDefiNER, finds them, with no training data. It runs on a CPU and is free under Apache 2.0. We make ReDefiNER and the plugin; every output on this page is real.
The short answer
- Train a spaCy NER model when you have hundreds of labelled examples for each type and need speed: a trained pipeline answers in milliseconds.
- Write EntityRuler patterns for fixed formats such as emails and ID numbers. Patterns and rulebooks compared.
- Use spacy-redefiner when you have no labelled data, when a type needs explaining, or when the definitions change often: edit the rulebook, and there is nothing to retrain.
What en_core_web_sm finds in your own types
Three support messages, run through spaCy's small English pipeline. It knows its general types, so it puts your terms into the nearest one:
import spacy
nlp = spacy.load("en_core_web_sm")
for doc in nlp.pipe(texts):
print([(ent.text, ent.label_) for ent in doc.ents])
| Text | en_core_web_sm |
|---|---|
| My Nimbus X200 router shows error E-4012 after updating to firmware 2.3.1. | Nimbus ORGX200 PRODUCTE-4012 ORG2.3.1 CARDINAL |
| Order #A-77120 arrived on 3 May, but the Nimbus X300 inside was the wrong colour. | A-77120 ORG3 May DATENimbus ORGX300 PRODUCT |
| Acme support said E-4012 means the fan has failed. | E-4012 ORG |
The error code and the order number come back as organisations, and each product name is split in two. That is expected: these types are not in its training data. Labelled examples and training would fix it.
The same texts with a rulebook
Three types, each with a one-line description and an example of a different value. One rule keeps the company name out of PRODUCT:
[TYPE] PRODUCT [DESCRIPTION] A product model name, such as Orbit Z5. PR1 A company name on its own, such as "Acme", is not a product. [TYPE] ERROR_CODE [DESCRIPTION] A device error code, such as E-1001. [TYPE] ORDER_ID [DESCRIPTION] A customer's order reference, such as #B-10234.
pip install spacy-redefiner
import spacy
# RULEBOOK is the rulebook above; texts are the three messages
nlp = spacy.blank("en")
nlp.add_pipe("redefiner", config={"rulebook": RULEBOOK})
for doc in nlp.pipe(texts):
print([(ent.text, ent.label_, ent._.redefiner_confidence)
for ent in doc.ents])
| Text | spacy-redefiner (confidence) |
|---|---|
| My Nimbus X200 router shows error E-4012 after updating to firmware 2.3.1. | Nimbus X200 PRODUCT (0.72)E-4012 ERROR_CODE (0.99) |
| Order #A-77120 arrived on 3 May, but the Nimbus X300 inside was the wrong colour. | #A-77120 ORDER_ID (0.49)Nimbus X300 PRODUCT (0.98) |
| Acme support said E-4012 means the fan has failed. | E-4012 ERROR_CODE (0.98) |
All three types were found with whole spans, and “Acme” was left out as the rule says. The order number's confidence, 0.49, is low: set a minimum confidence that suits your data after checking 20 to 50 of your own texts. Settings include min_confidence.
Add a type with one more paragraph
Append this to the rulebook and run the same three texts again:
[TYPE] FIRMWARE_VERSION [DESCRIPTION] A firmware or software version number, such as 1.0.4.
The first message now also returns 2.3.1 as FIRMWARE_VERSION (confidence 0.98), and the other spans are the same as before. No labelling and no training step.
With a trained spaCy pipeline
The component works after a pipeline such as en_core_web_sm. How it shares doc.ents decides what you get, and on these texts the choice matters:
| Setup | What you get | On the three texts |
|---|---|---|
exclude=["ner"] | spaCy's tagger, parser and lemmatizer, with entities from the rulebook | The rulebook's entities, as above |
spans_key="custom" | spaCy's entities in doc.ents, the rulebook's in doc.spans["custom"] | Both, side by side: E-4012 is ORG in one and ERROR_CODE in the other |
overwrite_ents=False | spaCy's entities, plus only rulebook spans that don't overlap them | Nothing added: spaCy's wrong labels covered every span the rulebook found |
# spaCy's tagger, parser and lemmatizer; entities from the rulebook
nlp = spacy.load("en_core_web_sm", exclude=["ner"])
nlp.add_pipe("redefiner", config={"rulebook": RULEBOOK})
# spaCy's entities stay in doc.ents; the rulebook's go to doc.spans
nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("redefiner",
config={"rulebook": RULEBOOK, "spans_key": "custom"})
In a spaCy config file:
[components.redefiner] factory = "redefiner" rulebook = "rules/support.txt" spans_key = "custom"
Speed and limits
- Speed. On the Apple M2 laptop that ran these examples, en_core_web_sm took about 2 milliseconds per text and the redefiner component about 0.2 seconds, once the rulebook was loaded: roughly 100 times slower. For millions of texts a day, a trained model costs far less to run.
- Memory. About 2 to 2.6 GB at peak on a CPU. It also runs on an NVIDIA GPU.
- English only, and spans of up to 16 model tokens by default; raise
max_span_tokensfor long IDs or URLs. - Rules that fight a strong prior are mostly ignored, such as labelling a person's name as something other than a person. When a type's condition isn't clearly met, it tends to label anyway.
- More on rules: How to write rules that work.