0Pricing
NLP Academy · บทเรียน

ดึงเอนทิตีด้วย spaCy

แสดงรายการเอนทิตีและป้ายกำกับของเอนทิตี

ดึงเอนทิตีด้วย spaCy เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

spaCy Does the Work

spaCy ships a trained NER component that finds entities for you. You feed it text and read back labeled spans. 🐍

Load a Model

First load a pipeline that includes NER. The small English model en_core_web_sm is a quick, friendly starting point.

import spacy
nlp = spacy.load("en_core_web_sm")

Process Your Text

Pass a string into the pipeline to get a Doc object. The Doc holds tokens, sentences, and the entities spaCy found.

doc = nlp("Sundar Pichai leads Google in California.")

The ents Property

Every Doc exposes doc.ents, a tuple of detected entities. Loop over it to inspect each one individually.

for ent in doc.ents:
    print(ent)

Read the Text

Each entity has a .text attribute holding the exact words matched. This is the raw span lifted from your sentence.

print(ent.text)  # e.g. Sundar Pichai

Read the Label

Use .label_ (with the trailing underscore) to get a readable label string like PERSON, ORG, or GPE.

print(ent.label_)  # e.g. PERSON

Putting It Together

One small loop prints both the text and label of every entity, turning a sentence into clean structured data.

for ent in doc.ents:
    print(ent.text, ent.label_)

Character Positions

Entities also expose start_char and end_char, the offsets in the original string. Handy for highlighting matches later.

print(ent.start_char, ent.end_char)

Explain a Label

Forgot what GPE means? Call spacy.explain for a plain-English description of any entity label.

spacy.explain("GPE")  # 'Countries, cities, states'

Entities Are Spans

Each entity is a Span, a slice of the Doc. So it behaves like a mini-document you can further inspect token by token.

Collect Into a List

A quick comprehension gathers every entity into a list of tuples, ready to save, count, or feed into a report.

results = [(e.text, e.label_) for e in doc.ents]

Quick Check

Which attribute gives the readable entity label?

Recap

Load a model, run nlp() on text, then loop doc.ents reading .text and .label_. That is core NER in spaCy. ✅

คำถามที่พบบ่อย

บทเรียน “ดึงเอนทิตีด้วย spaCy” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ดึงเอนทิตีด้วย spaCy” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ดึงเอนทิตีด้วย spaCy”

แสดงรายการเอนทิตีและป้ายกำกับของเอนทิตี คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “ดึงเอนทิตีด้วย spaCy” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม

ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. อะไรนับเป็นเอนทิตี
  2. ดึงเอนทิตีด้วย spaCy
  3. แสดงภาพเอนทิตีด้วย displaCy
  4. เพิ่มกฎเอนทิตีแบบกำหนดเอง
← กลับไปที่ NLP Academy