การเตรียมข้อมูลสำหรับฝึกโมเดล

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

Azadeh Mobasher

Principal data scientist

ขั้นตอนการฝึกโมเดล

 

  1. ระบุป้ายกำกับและเตรียมข้อมูล input
  2. กำหนดค่าน้ำหนักเริ่มต้นของโมเดล
  3. ทำนายตัวอย่างด้วยน้ำหนักปัจจุบัน
  4. เปรียบเทียบผลทำนายกับคำตอบที่ถูกต้อง
  5. ใช้ optimizer คำนวณน้ำหนักที่ช่วยพัฒนาประสิทธิภาพโมเดล
  6. ปรับน้ำหนักเล็กน้อย
  7. กลับไปที่ขั้นตอนที่ 3
การประมวลผลภาษาธรรมชาติด้วย spaCy

การ Annotate และเตรียมข้อมูล

  • ขั้นแรกคือเตรียมข้อมูลฝึกให้อยู่ในรูปแบบที่กำหนด
  • หลังเก็บข้อมูลแล้ว ต้องทำ annotation
  • Annotation คือการติดป้ายกำกับ intent, entities เป็นต้น
  • ตัวอย่างข้อมูลที่ผ่านการ annotate แล้ว:
annotated_data = {
"sentence": "An antiviral drugs used against influenza is neuraminidase inhibitors.",
"entities": {
             "label": "Medicine",
             "value": "neuraminidase inhibitors",
    }
}
การประมวลผลภาษาธรรมชาติด้วย spaCy

การ Annotate และเตรียมข้อมูล

  • ตัวอย่างข้อมูลที่ผ่านการ annotate แล้วอีกหนึ่งตัวอย่าง:

 

annotated_data = {
"sentence": "Bill Gates visited the SFO Airport.",
"entities": [{"label": "PERSON", "value": "Bill Gates"}, 
             {"label": "LOC", "value": "SFO Airport"}]
}
การประมวลผลภาษาธรรมชาติด้วย spaCy

รูปแบบข้อมูลฝึกของ spaCy

  • การ annotate ข้อมูลช่วยเตรียมชุดข้อมูลฝึกให้โมเดลเรียนรู้ได้ถูกต้อง
  • ชุดข้อมูลฝึกต้องจัดเก็บในรูปแบบ dictionary:
training_data = [
("I will visit you in Austin.", {"entities": [(20, 26, "GPE")]}),
("I'm going to Sam's house.", {"entities": [(13,18, "PERSON"), (19, 24, "GPE")]}),
("I will go.", {"entities": []})
]

ตัวอย่างสามคู่:

  • แต่ละคู่มีประโยคเป็น element แรก
  • element ที่สองคือรายการ entities ที่ annotate แล้ว พร้อมตำแหน่งอักขระเริ่มต้นและสิ้นสุด
การประมวลผลภาษาธรรมชาติด้วย spaCy

ออบเจกต์ Example สำหรับการฝึกโมเดล

  • ไม่สามารถส่งข้อความดิบให้ spaCy โดยตรงได้

  • ต้องสร้างออบเจกต์ Example สำหรับแต่ละตัวอย่างที่ใช้ฝึก

import spacy
from spacy.training import Example

nlp = spacy.load("en_core_web_sm")

doc = nlp("I will visit you in Austin.")

annotations = {"entities": [(20, 26, "GPE")]} example_sentence = Example.from_dict(doc, annotations)
print(example_sentence.to_dict())
การประมวลผลภาษาธรรมชาติด้วย spaCy

มาฝึกกันเถอะ!

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

Preparing Video For Download...