You can download this code by clicking the button below.
This code is now available for download.
This function uses spaCy's EntityRuler to generate a set of random entity recognition patterns and returns an entity ruler object. The entity patterns include PERSON, ORGANIZATION, GPE, and DATE.
Technology Stack : spaCy
Code Type : Custom function
Code Difficulty : Intermediate
import random
import spacy
from spacy.pipeline import EntityRuler
def generate_random_entity_patterns():
nlp = spacy.load("en_core_web_sm")
entity_ruler = EntityRuler(nlp)
patterns = [
{"label": "PERSON", "pattern": "John Doe"},
{"label": "ORGANIZATION", "pattern": "Google Inc."},
{"label": "GPE", "pattern": "New York"},
{"label": "DATE", "pattern": "2021-12-01"}
]
entity_ruler.add_patterns(patterns)
return entity_ruler