Skip to content

How to Dynamically Assign Entities with no model training #13091

Discussion options

You must be logged in to vote
  1. ruler is not the same SpanRuler instance that you have in your pipeline.
  2. SpanRuler doesn't store its results in Token.ent_type_.

A fixed version:

import spacy
from spacy.pipeline import SpanRuler


def custom_ner_pipeline(text, terms):
    # Load spaCy's small English model
    nlp = spacy.load("en_core_web_sm")

    ### CHANGE: get ruler instance from .add_pipe(). ###
    # Add the SpanRuler to the pipeline, before the NER
    ruler = nlp.add_pipe('span_ruler', before="ner")

    # Add patterns to the SpanRuler
    for d in terms:
        patterns = [{"label": d['ent'], "pattern": pattern} for pattern in d['patterns']]
        ruler.add_patterns(patterns)

    # Process the text with s…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@grahamanderson
Comment options

@rmitsch
Comment options

@grahamanderson
Comment options

@rmitsch
Comment options

Answer selected by grahamanderson
@grahamanderson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / spanruler Feature: Entity and span ruler
2 participants