호환 가능한 학습 데이터
원시 텍스트를 그대로 spaCy에 넣을 수는 없다는 점을 기억하세요. 대신 각 학습 예시에 대해 Example 객체를 만들어야 해요. 이 연습에서는 단일 문장이 주석된 training_data를 Example 객체 리스트로 변환하는 과정을 연습해 봅니다.
en_core_web_sm 모델은 이미 가져와 nlp로 사용할 수 있어요. Example 클래스도 이미 불러와 제공됩니다.
이 연습은 강의의 일부입니다
spaCy로 배우는 자연어 처리
연습 안내
training_data의 텍스트와 주석을 순회하면서 텍스트를Doc컨테이너로 변환해doc에 저장하세요.- 각 학습 데이터 포인트의 주석과
doc객체를 사용해Example객체를 만들고example_sentence에 저장하세요. example_sentence를all_examples리스트에 추가하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
example_text = 'A patient with chest pain had hyperthyroidism.'
training_data = [(example_text, {'entities': [(15, 25, 'SYMPTOM'), (30, 45, 'DISEASE')]})]
all_examples = []
# Iterate through text and annotations and convert text to a Doc container
for text, annotations in training_data:
doc = nlp(____)
# Create an Example object from the doc contianer and annotations
example_sentence = ____.____(doc, ____)
print(example_sentence.to_dict(), "\n")
# Append the Example object to the list of all examples
all_examples.append(____)
print("Number of formatted training data: ", len(____))