संगत training डेटा
याद रखिए कि आप raw टेक्स्ट को सीधे spaCy में नहीं दे सकते. इसके बजाय, आपको हर training उदाहरण के लिए एक Example ऑब्जेक्ट बनाना होता है. इस अभ्यास में, आप एक single annotated वाक्य वाले training_data को Example ऑब्जेक्ट्स की सूची में बदलने का अभ्यास करेंगे.
en_core_web_sm मॉडल पहले से इम्पोर्ट है और nlp के रूप में उपयोग के लिए तैयार है. Example क्लास भी आपके उपयोग के लिए इम्पोर्ट की गई है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
spaCy के साथ Natural Language Processing
अभ्यास निर्देश
training_dataमें मौजूद टेक्स्ट और annotations पर iterate कीजिए, टेक्स्ट कोDocकंटेनर में कन्वर्ट कीजिए और उसेdocमें स्टोर कीजिए.- हर training डेटा पॉइंट के
docऑब्जेक्ट और उसके annotations का उपयोग करके एकExampleऑब्जेक्ट बनाइए और उसेexample_sentenceमें स्टोर कीजिए. example_sentenceकोall_examplesनामक सूची में append कीजिए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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(____))