Guide · Rule-based NER

Rule-based NER, with the rules written in plain English

Updated 25 November 2026, by Jungroo AI Labs, the makers of ReDefiNER

Rule-based NER finds entities with rules that people write: regular expressions, token patterns and lists of names, in tools such as spaCy's EntityRuler, Stanford CoreNLP's RegexNER and Presidio's pattern recognizers. It is exact, fast and easy to audit, but every rule has to be a pattern. ReDefiNER keeps the rules and drops the patterns: it is a 0.8B model that reads rules written in plain English and applies them by meaning. It is not a pattern engine, and it can be wrong. Below, the same rules are written both ways and run on the same sentences. We make ReDefiNER; every output on this page is real.

The short answer

  • Use patterns when an entity has a fixed format (emails, ID numbers, card numbers with a checksum), when a list of names covers it, or when you need the same answer every time at almost no cost.
  • Use ReDefiNER when the rule depends on meaning, such as “patients, not doctors”, when people write the same thing in many ways, or when the people who own the rules don't write regex.
  • Use both: patterns for the formats, ReDefiNER for the rest, in one spaCy or Presidio pipeline.

The same rule, written both ways

Task: find customer order numbers such as #D-55102, but not invoice numbers. As spaCy EntityRuler patterns:

import spacy

nlp = spacy.blank("en")
ruler = nlp.add_pipe("entity_ruler")
ruler.add_patterns([
    # spaCy splits "#" off "D-55102", so the pattern needs both forms
    {"label": "ORDER_ID",
     "pattern": [{"TEXT": "#"}, {"TEXT": {"REGEX": r"^[A-Z]-\d{5}$"}}]},
    {"label": "ORDER_ID",
     "pattern": [{"TEXT": {"REGEX": r"^#[A-Z]-\d{5}$"}}]},
])

As a ReDefiNER rulebook, one type with a description and one rule:

[TYPE] ORDER_ID
[DESCRIPTION] A customer's order reference, such as #D-55102.
OR1 Invoice numbers, which start with INV-, are not order references.
from redefiner import Tagger

tagger = Tagger.from_pretrained("jungroo-ai/redefiner-0.8b")
tagger.extract(sentences, rulebook)   # one list of spans per sentence

Both on the same four sentences:

SentenceEntityRuler patternsReDefiNER rulebook (confidence)
Order #D-55102 shipped on 3 May.#D-55102#D-55102 (0.74)
Can you check order D55103? It hasn't arrived.nothingD55103 (0.98)
My order number is d-55104 and the box was damaged.nothingd-55104 (0.97)
Invoice INV-7731 covers both orders.nothingnothing

The patterns did exactly what they say and nothing more. Catching D55103 and d-55104 takes two more patterns, and the next customer will type it another way. The rulebook found all three from one example in the description, and its rule kept the invoice number out. The other side: 0.74 is a confidence, not a guarantee, and a model can also label something no pattern would.

A rule no pattern can express

Task: find patients' names, but not the names of staff. To a pattern, both are just names. A rule-based system needs a list of every patient, or context patterns such as “the name after examined”, written for each way a sentence can be phrased. As a rulebook:

[TYPE] PATIENT_NAME
[DESCRIPTION] The name of a patient.
PA1 Doctors, nurses and other staff are not patients. Never label their names.
SentenceLabelled PATIENT_NAME
Dr. Anita Rao examined Ravi Kumar on 3 May.Ravi Kumar
Nurse Joseph Mathew took Ravi's blood pressure before Dr. Rao arrived.Ravi
Priya Nair, 34, was referred by her GP, Dr. Samuel Lee.Priya Nair

Dr. Anita Rao, Nurse Joseph Mathew and Dr. Samuel Lee were left out, and so was “Dr. Rao”. To change the policy, edit the text: there is no training step.

Where patterns are the better tool

  • Checksums. A card-number pattern with a Luhn check, as Presidio's recognizers use, rejects numbers that only look right. ReDefiNER reads text; it cannot compute a checksum.
  • Guaranteed coverage. A pattern matches every string of its format, every time. ReDefiNER returns a confidence, can miss a span, and can label something a pattern would not.
  • Speed. On the Apple M2 laptop that ran these examples, the EntityRuler took about 0.02 milliseconds per sentence. ReDefiNER took about 0.2 seconds per sentence once the rulebook was loaded, roughly 10,000 times slower, and needs about 2 to 2.6 GB of memory.
  • Auditing. A pattern is its own explanation. With ReDefiNER you can read the rule it was given, but not prove that it followed it.
  • ReDefiNER's limits. English only. Rules that fight a strong prior, such as labelling a person's name as something other than a person, are mostly ignored. When a type's condition isn't clearly met, it tends to label anyway.

Use both in one pipeline

The spacy-redefiner component runs after spaCy's EntityRuler. With overwrite_ents set to false, the patterns keep their matches and ReDefiNER adds the entities they don't cover:

pip install spacy-redefiner
import spacy

nlp = spacy.blank("en")
ruler = nlp.add_pipe("entity_ruler")
ruler.add_patterns([
    {"label": "PAN",
     "pattern": [{"TEXT": {"REGEX": r"^[A-Z]{5}\d{4}[A-Z]$"}}]},
    {"label": "EMAIL", "pattern": [{"LIKE_EMAIL": True}]},
])
# PATIENT_RULES is the rulebook above
nlp.add_pipe("redefiner",
             config={"rulebook": PATIENT_RULES, "overwrite_ents": False})

doc = nlp("Ravi Kumar (PAN ABCDE1234F, ravi.k@example.com) "
          "was seen by Dr. Anita Rao.")
print([(ent.text, ent.label_) for ent in doc.ents])
# [('Ravi Kumar', 'PATIENT_NAME'), ('ABCDE1234F', 'PAN'),
#  ('ravi.k@example.com', 'EMAIL')]

The PAN and the email came from the patterns; the patient's name came from the rulebook, and Dr. Anita Rao was left out. For personal data, the presidio-redefiner recognizer does the same beside Presidio's own pattern recognizers. PII redaction with ReDefiNER.

Which plain-English rules work

  • Descriptions matter. With a one-line description per type, the model scores 7 points higher than with type names alone on our open-NER test sets. Always write one.
  • Boundary, exclusion and convention rules work. “The span includes the @ of a Twitter handle” took BroadTwitter from 45.5 to 70.6 F1. “Never label Houston, Texas or Harvey” cut those false positives from 389 to 5 on HarveyNER.
  • Rules that fight a strong prior don't. Asking it to label common nouns as entities, or a person's name as something else, mostly has no effect. Pronouns are the exception: listed under a type, they are labelled.
  • More: How to write rules that work, with templates to copy.

Questions

Frequently asked.

What is rule-based NER?

Named entity recognition with hand-written rules instead of a trained model: regular expressions, token patterns and lists of names. spaCy's EntityRuler, Stanford CoreNLP's RegexNER and Presidio's pattern recognizers work this way. It is exact and fast, but finds only what a rule describes.

Is ReDefiNER a rule-based NER system?

Not in the classic sense. It is a 0.8B model that reads rules written in plain English and applies them by meaning, so it handles wording no rule spelled out, but it gives a confidence rather than a guarantee. For fixed formats, use patterns alongside it.

Can I use ReDefiNER with spaCy's EntityRuler?

Yes. Add the entity_ruler first and the redefiner component from spacy-redefiner after it, with overwrite_ents set to false. The patterns keep their matches and ReDefiNER adds the entities they don't cover.

Do I need training data to add an entity type?

No. Write a [TYPE] line and a one-line [DESCRIPTION], plus numbered rules for the edge cases. There is no training step: edit the text to change what is found.

Is it free, and does it run on a CPU?

Yes to both. The code and the 0.8B weights are under Apache 2.0, including commercial use. It runs on an ordinary CPU with about 2 to 2.6 GB of memory, or on an NVIDIA GPU.

Try it on your own text

Test ReDefiNER on 20 of your sentences.

It runs on a laptop CPU. Install it with pip, edit a rule and see the output change, or write to us and we will test a rulebook on your data.

Contact

Tell us what you need.

We partner with a limited number of enterprises at a time, so every engagement gets senior attention. Tell us what you want to build, and our leadership will reply.

We use these details only to reply to you. What you type is saved as you go, so we can still reply if you leave before pressing Send. Privacy

General enquiries

Jungroo AI Labs

Partnerships, projects and products

Leadership

Sethuraman T A

Chief Executive Officer

Engineering

Cibe Hariharan

Chief Technology Officer