0Pricing
NLP Academy · Lesson

Extracting Entities With spaCy

List entities and their labels.

Extracting Entities With spaCy is a free NLP Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. ✅

Frequently asked questions

Is the “Extracting Entities With spaCy” lesson free?

Yes — the full text of “Extracting Entities With spaCy” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Extracting Entities With spaCy”?

List entities and their labels. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start NLP Academy?

No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Extracting Entities With spaCy” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this NLP Academy lesson?

Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Counts as an Entity?
  2. Extracting Entities With spaCy
  3. Visualizing Entities With displaCy
  4. Adding Custom Entity Rules
← Back to NLP Academy