You can download this code by clicking the button below.
This code is now available for download.
This function uses the spaCy library to analyze text and randomly selects an entity and its label.
Technology Stack : spaCy
Code Type : Custom function
Code Difficulty : Intermediate
import random
import spacy
def random_entity_label(text):
nlp = spacy.load('en_core_web_sm')
doc = nlp(text)
entity = random.choice([ent for ent in doc.ents])
return entity.text, entity.label_