เพิ่มกฎเอนทิตีแบบกำหนดเอง
ตรวจจับคำเฉพาะโดเมนที่โมเดลพลาด
เพิ่มกฎเอนทิตีแบบกำหนดเอง เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
When the Model Misses
Pre-trained NER never saw your product names or internal jargon. Custom rules let you catch the terms it always misses. 🎯
Meet the EntityRuler
spaCy's EntityRuler adds entities from patterns you define, no retraining required. It plugs straight into the pipeline.
Add It to the Pipe
Insert the ruler with add_pipe. Placing it before ner lets your rules take priority over the model's guesses.
ruler = nlp.add_pipe("entity_ruler", before="ner")Patterns Are Dicts
Each rule is a dict with a label and a pattern. The label is the entity type you want assigned to a match.
{"label": "PRODUCT", "pattern": "CoddyKit"}Add Your Patterns
Feed a list of pattern dicts to ruler.add_patterns. Now those exact phrases get tagged every time they appear.
ruler.add_patterns([{"label": "PRODUCT", "pattern": "CoddyKit"}])Token-Based Patterns
Beyond plain strings, patterns can be token lists that match on attributes like lowercase text, giving flexible rules.
{"label": "ORG", "pattern": [{"LOWER": "acme"}]}Match Multi-Word Terms
A token pattern with several entries catches phrases, so San Pedro Lab is tagged as one entity, not three words.
[{"LOWER": "san"}, {"LOWER": "pedro"}, {"LOWER": "lab"}]Rules Run First
Because the ruler sits before ner, your custom labels win on conflicts, while the model still handles everything else.
Test Your Rules
Run a sentence through the updated pipeline and loop doc.ents to confirm your new terms now show the right label.
doc = nlp("We shipped CoddyKit today.")
# CoddyKit -> PRODUCTSave the Patterns
Export rules to disk with to_disk so your whole team reuses the same custom entities instead of redefining them.
ruler.to_disk("patterns.jsonl")Rules Plus Learning
Custom rules are a fast first step. Later you can train the model on labeled examples for tricky, fuzzy cases. 🚀
Quick Check
How do you make custom rules override the model?
Recap
The EntityRuler adds entities from string or token patterns, runs before ner, and saves to disk for reuse. ✅
คำถามที่พบบ่อย
บทเรียน “เพิ่มกฎเอนทิตีแบบกำหนดเอง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “เพิ่มกฎเอนทิตีแบบกำหนดเอง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “เพิ่มกฎเอนทิตีแบบกำหนดเอง”
ตรวจจับคำเฉพาะโดเมนที่โมเดลพลาด คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “เพิ่มกฎเอนทิตีแบบกำหนดเอง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- อะไรนับเป็นเอนทิตี
- ดึงเอนทิตีด้วย spaCy
- แสดงภาพเอนทิตีด้วย displaCy
- เพิ่มกฎเอนทิตีแบบกำหนดเอง