Natural Language Processing with spaCy
Azadeh Mobasher
Principal data scientist
annotated_data = {
"sentence": "An antiviral drugs used against influenza is neuraminidase inhibitors.",
"entities": {
"label": "Medicine",
"value": "neuraminidase inhibitors",
}
}
annotated_data = {
"sentence": "Bill Gates visited the SFO Airport.",
"entities": [{"label": "PERSON", "value": "Bill Gates"},
{"label": "LOC", "value": "SFO Airport"}]
}
training_data = [
("I will visit you in Austin.", {"entities": [(20, 26, "GPE")]}),
("I'm going to Sam's house.", {"entities": [(13,18, "PERSON"), (19, 24, "GPE")]}),
("I will go.", {"entities": []})
]
Three example pairs:
We cannot feed the raw text directly to spaCy
We need to create an Example
object for each training example
import spacy from spacy.training import Example nlp = spacy.load("en_core_web_sm") doc = nlp("I will visit you in Austin.")
annotations = {"entities": [(20, 26, "GPE")]} example_sentence = Example.from_dict(doc, annotations)
print(example_sentence.to_dict())
Natural Language Processing with spaCy