使用 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": []})
]
三个示例对:
原始文本不能直接输入到 spaCy
需为每个训练样本创建一个 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())
使用 spaCy 的自然语言处理