spaCy Named Entity Recognizer

What is spaCy(v2):

Features

  • Non-destructive tokenization
  • Named entity recognition
  • Support for 49+ languages
  • 16 statistical models for 9 languages
  • Pre-trained word vectors
  • Easy deep learning integration
  • Part-of-speech tagging
  • Labelled dependency parsing
  • Syntax-driven sentence segmentation
  • Built in visualizers for syntax and NER
  • Convenient string-to-hash mapping
  • Export to numpy data arrays
  • Efficient binary serialization
  • Easy model packaging and deployment
  • State-of-the-art speed
  • Robust, rigorously evaluated accuracy

Installation Steps:

$ pip install -U spacy

Download the Model:

$ python -m spacy download en_core_web_sm
or
$ python -m spacy download en

How to Use:

>>> import spacy
>>> nlp = spacy.load("en_core_web_sm")
or
>>> nlp = spacy.load("en")

What is Named-entity recognition:

Example:

$ python
>>> import spacy
>>> nlp = spacy.load("en")
>>> text = "But Google is starting from behind. The company made a late push\ninto hardware, and Apple’s Siri, available on iPhones, and Amazon’s Alexa\nsoftware, which runs on its Echo and Dot devices, have clear leads in\nconsumer adoption."
>>> doc = nlp(text)
>>> for ent in doc.ents:
... print(ent.text, ent.start_char, ent.end_char, ent.label_)
...
Google 4 10 ORG
Apple’s Siri 84 96 ORG
iPhones 111 118 ORG
Amazon 124 130 ORG
Echo and Dot 167 179 ORG
>>>
output

Visualizing named entities:

import spacy 
from spacy import displacy
text = """But Google is starting from behind. The company made a late push into hardware, and Apple’s Siri, available on iPhones, and Amazon’s Alexa software, which runs on its Echo and Dot devices, have clear leads in consumer adoption."""
nlp = spacy.load("en")
doc = nlp(text)
displacy.serve(doc, style="ent")
another output

--

--

Artificial Intelligence and Data Science

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store