DEV Community

Alpha Quantum
Alpha Quantum

Posted on

Dependency parsers in Natural Language Processing (NLP)

Dependency parsers are a type of tools that help you analyze sentences for their grammatical structure.

They let us break down a sentence into its components and find any words or phrases that are related.

Dependency parsers are looking for "head" words. They analyze how those headwords depend on other words and in particular, when one word modifies or changes another.

The open-source library spacy is a great tool for many different kinds of natural language processing tasks like dependency parsing. It includes an excellent dependency parser, and you may want to check out Stanford CoreNLP too.

If we apply dependency parsing on the sentence “They are driving fast”, we get the following nice diagram:

Image description

The arrows indicate that the word “fast” modifies the word "driving" with the nature of their relation described by special tags. In this specific case it is advmod.

Here are some other possible modifiers:

acl: clausal modifier of noun (adjectival clause)
advcl: adverbial clause modifier
amod: adjectival modifier
appos: appositional modifier
Enter fullscreen mode Exit fullscreen mode

The above diagram was generated with this code:

`import spacy
from spacy import displacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("They are driving fast.")
displacy.serve(doc, style="dep")
`

If you could would like to play with dependency parsing without having to spin up your own jupyter notebook or other code, you can use this online tool:

https://explosion.ai/demos/displacy?text=They%20are%20driving%20fast&model=en_core_web_sm&cpu=1&cph=1

Here is an example of diagram created with this online tool:
Image description

Where do we use dependency parsing

Dependency parsing is used in many fields of NLP, some of them are:

grammar checking
information extraction
website categorization
aspect based sentiment analysis
named entity recognition
product categorization
question answering
trending products analysis
document summarization
Enter fullscreen mode Exit fullscreen mode

Top comments (0)