標註與準備訓練資料
蒐集資料後,你可以依照 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)