0Pricing
NLP Academy · Lesson

Adding Custom Entity Rules

Catch domain terms the model misses.

Adding Custom Entity Rules is a free NLP Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

When the Model Misses

Pre-trained NER never saw your product names or internal jargon. Custom rules let you catch the terms it always misses. 🎯

Meet the EntityRuler

spaCy's EntityRuler adds entities from patterns you define, no retraining required. It plugs straight into the pipeline.

Add It to the Pipe

Insert the ruler with add_pipe. Placing it before ner lets your rules take priority over the model's guesses.

ruler = nlp.add_pipe("entity_ruler", before="ner")

Patterns Are Dicts

Each rule is a dict with a label and a pattern. The label is the entity type you want assigned to a match.

{"label": "PRODUCT", "pattern": "CoddyKit"}

Add Your Patterns

Feed a list of pattern dicts to ruler.add_patterns. Now those exact phrases get tagged every time they appear.

ruler.add_patterns([{"label": "PRODUCT", "pattern": "CoddyKit"}])

Token-Based Patterns

Beyond plain strings, patterns can be token lists that match on attributes like lowercase text, giving flexible rules.

{"label": "ORG", "pattern": [{"LOWER": "acme"}]}

Match Multi-Word Terms

A token pattern with several entries catches phrases, so San Pedro Lab is tagged as one entity, not three words.

[{"LOWER": "san"}, {"LOWER": "pedro"}, {"LOWER": "lab"}]

Rules Run First

Because the ruler sits before ner, your custom labels win on conflicts, while the model still handles everything else.

Test Your Rules

Run a sentence through the updated pipeline and loop doc.ents to confirm your new terms now show the right label.

doc = nlp("We shipped CoddyKit today.")
# CoddyKit -> PRODUCT

Save the Patterns

Export rules to disk with to_disk so your whole team reuses the same custom entities instead of redefining them.

ruler.to_disk("patterns.jsonl")

Rules Plus Learning

Custom rules are a fast first step. Later you can train the model on labeled examples for tricky, fuzzy cases. 🚀

Quick Check

How do you make custom rules override the model?

Recap

The EntityRuler adds entities from string or token patterns, runs before ner, and saves to disk for reuse. ✅

Frequently asked questions

Is the “Adding Custom Entity Rules” lesson free?

Yes — the full text of “Adding Custom Entity Rules” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Adding Custom Entity Rules”?

Catch domain terms the model misses. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start NLP Academy?

No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Adding Custom Entity Rules” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this NLP Academy lesson?

Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Counts as an Entity?
  2. Extracting Entities With spaCy
  3. Visualizing Entities With displaCy
  4. Adding Custom Entity Rules
← Back to NLP Academy