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

EntityRuler กับโมเดล spaCy เปล่า

EntityRuler ช่วยให้เพิ่ม entity เข้าไปใน doc.ents ได้ สามารถใช้ร่วมกับ EntityRecognizer ซึ่งเป็นคอมโพเนนต์ใน spaCy pipeline สำหรับการจดจำ named entity เพื่อเพิ่มความแม่นยำ หรือจะใช้เพียงอย่างเดียวเพื่อสร้างระบบจดจำ entity แบบ rule-based ล้วนๆ ก็ได้

ในแบบฝึกหัดนี้ จะได้ฝึกเพิ่มคอมโพเนนต์ EntityRuler เข้าไปในโมเดล spaCy ภาษาอังกฤษแบบเปล่า และจำแนก named entity ของ text ที่กำหนดให้โดยใช้วิธี rule-based ล้วนๆ

ได้นำเข้าแพ็กเกจ spaCy ไว้แล้ว และโมเดล spaCy ภาษาอังกฤษแบบเปล่าพร้อมใช้งานในชื่อ nlp นอกจากนี้ยังมีรายการ patterns สำหรับจำแนก OpenAI และ Microsoft แบบตัวพิมพ์เล็กเป็น ORG เตรียมไว้ให้แล้ว

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

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

ดูคอร์ส

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

  • สร้างและเพิ่มคอมโพเนนต์ EntityRuler เข้าไปใน pipeline
  • เพิ่ม patterns ที่กำหนดให้เข้าไปในคอมโพเนนต์ EntityRuler
  • รันโมเดลบน text ที่กำหนดให้และสร้าง Doc container ที่สอดคล้องกัน
  • แสดง tuple ของ (ข้อความและประเภทของ entity) สำหรับ entity ทั้งหมดใน Doc container

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

nlp = spacy.blank("en")
patterns = [{"label": "ORG", "pattern": [{"LOWER": "openai"}]},
            {"label": "ORG", "pattern": [{"LOWER": "microsoft"}]}]
text = "OpenAI has joined forces with Microsoft."

# Add EntityRuler component to the model
entity_ruler = nlp.____("entity_ruler")

# Add given patterns to the EntityRuler component
entity_ruler.____(____)

# Run the model on a given text
doc = nlp(____)

# Print entities text and type for all entities in the Doc container
print([(ent.____, ent.____) for ent in doc.____])
แก้ไขและรันโค้ด