Search⌘ K
AI Features

Solution: Linguistic Features

Explore how to apply spaCy for key linguistic features such as part-of-speech tagging, dependency parsing, and named entity recognition. Understand how tokens are processed and labeled, enabling you to analyze grammatical structures and entities within text using spaCy.

We'll cover the following...

Solution

In the code snippet below, we have given the solution to the previous problem.

Python 3.5
import spacy
nlp = spacy.load("en_core_web_md")
text = "Apple is looking at buying U.K. startup for $1 billion"
doc = nlp(text)
for token in doc:
print(f"{token.text} {token.pos_} {token.dep_}")
for ent in doc.ents:
print("{ent.text} {ent.label_}")

Solution explanation

  • Lines 1 and 2: We import the spacy library and load an English model using spacy.load. ...