ดึงวลีตามรูปแบบแท็ก
ดึงกลุ่มคำนามและกริยาออกมา
ดึงวลีตามรูปแบบแท็ก เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
From Tags to Phrases
Single tags are useful, but meaning often lives in groups of words. Tag patterns let you pull out whole phrases instead of lone tokens. 🧩
What Is a Noun Chunk?
A noun chunk is a noun plus the words describing it, like the fluffy cat. These chunks usually name the key things a sentence is about.
Get Noun Chunks Free
spaCy finds noun chunks for you. Iterate over doc.noun_chunks to grab each one as a span without writing any rules.
for chunk in doc.noun_chunks:
print(chunk.text)Chunks Are Spans
Each noun chunk is a Span, a slice of the Doc. A span knows its text, start, and end, so you can reuse it like any other token group.
chunk = list(doc.noun_chunks)[0]
print(chunk.start, chunk.end)Pull Out Every Verb
To collect actions, keep tokens whose pos_ is VERB. A list comprehension gathers them all in a single readable line.
verbs = [t.text for t in doc if t.pos_ == "VERB"]Match Custom Patterns
For your own rules, use the Matcher. You describe a sequence of token attributes, and spaCy finds every place that sequence appears.
from spacy.matcher import Matcher
matcher = Matcher(nlp.vocab)Define a Tag Sequence
A pattern is a list of dictionaries, one per token. This one matches an adjective followed by a noun, like fluffy cat.
pattern = [{"POS": "ADJ"}, {"POS": "NOUN"}]Add the Pattern
Register your pattern under a name with matcher.add(). The name lets you group related rules and identify matches later.
matcher.add("ADJ_NOUN", [pattern])Run the Matcher
Call the matcher on a Doc to get matches. Each result is a tuple of a match id plus the start and end token positions.
matches = matcher(doc)Read Each Match
Slice the Doc with the start and end to turn a match into readable text. That slice is the phrase your pattern captured.
for mid, start, end in matches:
print(doc[start:end].text)Patterns Beat Regex Here
Tag patterns understand grammar, so they catch phrases regex would miss. Matching on POS is far cleaner than chasing exact letters.
Quick Check
Think about how to extract grouped nouns.
Recap
You extracted phrases two ways: built-in noun_chunks and custom tag patterns with the Matcher. Now you can mine grammar, not just words. 🎉
คำถามที่พบบ่อย
บทเรียน “ดึงวลีตามรูปแบบแท็ก” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ดึงวลีตามรูปแบบแท็ก” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ดึงวลีตามรูปแบบแท็ก”
ดึงกลุ่มคำนามและกริยาออกมา คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “ดึงวลีตามรูปแบบแท็ก” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- คำนาม กริยา และเหตุใดแท็กจึงสำคัญ
- ติดแท็กคำด้วย spaCy
- ดึงวลีตามรูปแบบแท็ก
- พื้นฐานการแยกวิเคราะห์ความสัมพันธ์