0Pricing
NLP Academy · Lezione

Estrarre entità con spaCy

Elencare le entità e le relative etichette

Estrarre entità con spaCy è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NLP Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NLP Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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

Domande Frequenti

La lezione «Estrarre entità con spaCy» è gratuita?

Sì — il testo completo di «Estrarre entità con spaCy» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NLP Academy, passa a CoddyKit PRO. Il corso NLP Academy include 4 lezioni in totale.

Cosa imparerò in «Estrarre entità con spaCy»?

Elencare le entità e le relative etichette Eserciti NLP Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare NLP Academy?

Non è richiesta alcuna esperienza precedente. NLP Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.

Quanto tempo richiede la lezione «Estrarre entità con spaCy»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione NLP Academy?

Sì. Ogni lezione NLP Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Che cosa conta come entità?
  2. Estrarre entità con spaCy
  3. Visualizzare le entità con displaCy
  4. Aggiungere regole personalizzate per le entità
← Torna a NLP Academy