标注与准备训练数据
收集数据后,您可以按 spaCy 模型所需的格式对数据进行标注。本练习将练习为医疗领域的 NER 任务构造正确的标注数据记录。
已为您提供一个 sentence,以及两个实体:entity_1 的文本为 chest pain、类型为 SYMPTOM;entity_2 的文本为 hyperthyroidism、类型为 DISEASE。
本练习是课程的一部分
使用 spaCy 的自然语言处理
练习说明
- 以正确格式完成
annotated_data记录。 - 提取每个实体的起始与结束字符位置,并存入相应变量。
- 将相同的输入句子及其实体按正确的训练格式保存为
training_data。
交互式实操练习
通过完成这段示例代码来试试这个练习。
text = "A patient with chest pain had hyperthyroidism."
entity_1 = "chest pain"
entity_2 = "hyperthyroidism"
# Store annotated data information in the correct format
annotated_data = {"sentence": ____, "entities": [{"label": "SYMPTOM", "value": ____}, {"label": "DISEASE", "value": ____}]}
# Extract start and end characters of each entity
entity_1_start_char = text.____(____)
entity_1_end_char = entity_1_start_char + len(____)
entity_2_start_char = text.____(____)
entity_2_end_char = entity_2_start_char + len(____)
# Store the same input information in the proper format for training
training_data = [(____, {"entities": [(____,____,"SYMPTOM"),
(____,____,"DISEASE")]})]
print(training_data)