เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ข้อมูลการฝึกในรูปแบบที่ถูกต้อง

โปรดทราบว่าไม่สามารถส่งข้อความดิบให้ spaCy โดยตรงได้ แต่ต้องสร้างออบเจ็กต์ Example สำหรับตัวอย่างการฝึกแต่ละรายการ ในแบบฝึกหัดนี้ จะได้ฝึกแปลง training_data ที่มีประโยคที่มี annotation อยู่หนึ่งประโยคให้เป็น list ของออบเจ็กต์ Example

โมเดล en_core_web_sm ถูก import ไว้แล้วและพร้อมใช้งานในชื่อ nlp และคลาส Example ก็ถูก import ไว้ให้แล้วเช่นกัน

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การประมวลผลภาษาธรรมชาติด้วย spaCy

ดูคอร์ส

คำแนะนำการฝึกหัด

  • วนซ้ำผ่านข้อความและ annotations ใน training_data จากนั้นแปลงข้อความให้เป็น Doc container และเก็บไว้ในตัวแปร doc
  • สร้างออบเจ็กต์ Example โดยใช้ออบเจ็กต์ doc และ annotations ของข้อมูลการฝึกแต่ละจุด แล้วเก็บไว้ในตัวแปร example_sentence
  • เพิ่ม example_sentence เข้าไปใน list ชื่อ 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(____))
แก้ไขและรันโค้ด