Last active
May 6, 2021 09:08
-
-
Save omri374/750a63b5d3efd53763088fd3aaf19c83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def names_recall(nlp: spacy.lang.en.English, names: List[str], template: str): | |
""" | |
Run the spaCy NLP model on the template + name, | |
calculate recall for detecting the "PERSON" entity | |
and return a detailed list of detection | |
:param nlp: spaCy nlp model | |
:param names: list of names to run model on | |
:param template: sentence with placeholder for name (e.g. "He calls himself {}") | |
""" | |
results = {} | |
for name in names: | |
doc = nlp(template.format(name)) | |
name_token = [token for token in doc if token.text == name][0] | |
results[name] = name_token.ent_type_ == "PERSON" | |
recall = sum(results.values()) / len(results) | |
print(f"Recall: {recall:.2f}\n") | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment