Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconArtificial Intelligencebreadcumb forward arrow iconDependency Parsing in NLP [Explained with Examples]

Dependency Parsing in NLP [Explained with Examples]

Last updated:
10th Mar, 2021
Read Time
7 Mins
share image icon
In this article
Chevron in toc
View All
Dependency Parsing in NLP [Explained with Examples]

Natural Language Processing is an interdisciplinary concept that takes the fundamentals of computational linguistics and Artificial Intelligence to understand how human languages interact with technology.

NLP requires an in-depth understanding of various terminologies and concepts to apply them tangibly to real-world scenarios. Some of these basic concepts include Part-of-Speech(POS) Tagging, Statistical Language Modeling, Syntactic, Semantic and Sentiment Analysis, Normalization, Tokenization, Dependency Parsing, and Constituency Parsing, among others. 

Best Machine Learning and AI Courses Online

In this article, we will look at the fundamentals of Dependency Parsing to gain perspective on how it is implemented in NLP. 

Ads of upGrad blog

Dependency Parsing

Dependency Parsing (DP) refers to examining the dependencies between the words of a sentence to analyze its grammatical structure. Based on this, a sentence is broken into several components. The mechanism is based on the concept that there is a direct link between every linguistic unit of a sentence. These links are termed dependencies. 

In-demand Machine Learning Skills

Get Machine Learning Certification from the World’s top Universities. Earn Masters, Executive PGP, or Advanced Certificate Programs to fast-track your career.

Let’s take for example the sentence I prefer the morning flight through Denver.”

The diagram below explains the dependency structure of the sentence: 


The relations between every linguistic unit, or word, of the sentence, is indicated using directed arcs in a typed dependency structure. As labelled in the diagram, the root of the tree “prefer” forms the head of the above sentence. 

The relationship between any two words is marked by a dependency tag. For instance, the word “flight” modifies the meaning of the noun “Denver.” Therefore, you can notice a dependency from flight -> Denver where the flight is the head and Denver is the child or dependent. It is denoted by nmod which represents a nominal modifier. 

This forms the case for dependency between every two words where one acts as the head and the other is the dependent. Currently, the Universal Dependency V2 taxonomy consists of 37 universal syntactic relations as specified in the table below:

Dependency TagDescription
aclclausal modifier of a noun (adnominal clause)
acl:relclrelative clause modifier
advcladverbial clause modifier
advmodadverbial modifier
advmod:emphemphasizing word, intensifier
advmod:lmodlocative adverbial modifier
amodadjectival modifier
apposappositional modifier
aux:passpassive auxiliary
cccoordinating conjunction
ccompclausal complement
compound:lvclight verb construction
compound:prtphrasal verb particle
compound:redupreduplicated compounds
compound:svcserial verb compounds
csubjclausal subject
csubj:passclausal passive subject
depunspecified dependency
det:numgovpronominal quantifier governing the case of the noun
det:nummodpronominal quantifier agreeing in case with the noun
det:posspossessive determiner
discoursediscourse element
dislocateddislocated elements
expl:impersimpersonal expletive
expl:passreflexive pronoun used in reflexive passive
expl:pvreflexive clitic with an inherently reflexive verb
fixedfixed multiword expression
flatflat multiword expression
flat:foreignforeign words
goeswithgoes with
iobjindirect object
nmodnominal modifier
nmod:posspossessive nominal modifier
nmod:tmodtemporal modifier
nsubjnominal subject
nsubj:passpassive nominal subject
nummodnumeric modifier
nummod:govnumeric modifier governing the case of the noun
obloblique nominal
obl:agentagent modifier
obl:argoblique argument
obl:lmodlocative modifier
obl:tmodtemporal modifier
reparandumoverridden disfluency
xcompopen clausal complement

Dependency Parsing using NLTK

Dependency Parsing can be carried out using the Natural Language Toolkit (NLTK) package which is a collection of libraries and codes used in the statistical Natural Language Processing (NLP) of human language. 

We can use NLTK to achieve dependency parsing through one of the following methods: 

  1. Probabilistic, projective dependency parser: These parsers use the knowledge of human language gleaned from hand-parsed sentences to predict new sentences. They are known to make mistakes and work with a restricted set of training data. 
  2. Stanford parser: This is a natural language parser implemented on Java. You need the Stanford CoreNLP parser to perform dependency parsing. The parser includes several languages including English, Chinese, German, and Arabic. 

FYI: Free Deep Learning Course!

Here’s how you can use the parser: 

from nltk.parse.stanford import StanfordDependencyParser

path_jar = ‘path_to/stanford-parser-full-2014-08-27/stanford-parser.jar’

path_models_jar = ‘path_to/stanford-parser-full-2014-08-27/stanford-parser-3.4.1-models.jar’

dep_parser = StanfordDependencyParser(

   path_to_jar = path_jar, path_to_models_jar = path_models_jar


result = dep_parser.raw_parse(‘I shot an elephant in my sleep’)

dependency =


The output of the above program is as follows: 


   ((u’shot’, u’VBD’), u’nsubj’, (u’I’, u’PRP’)),

   ((u’shot’, u’VBD’), u’dobj’, (u’elephant’, u’NN’)),

   ((u’elephant’, u’NN’), u’det’, (u’an’, u’DT’)),

   ((u’shot’, u’VBD’), u’prep’, (u’in’, u’IN’)),

   ((u’in’, u’IN’), u’pobj’, (u’sleep’, u’NN’)),

   ((u’sleep’, u’NN’), u’poss’, (u’my’, u’PRP$’))


Constituency Parsing

Constituency Parsing is based on context-free grammars. Here, the parse tree includes sentences broken into sub-phrases, each belonging to a grammar category. Every linguistic unit or word in a sentence acts as a terminal node, which has its parent node and a part-of-speech tag.

For example, the phrase “a cat” and “a box under the bed” are noun phrases, whereas “write a letter” and “drive a car” are verb phrases.

Let’s consider an example sentenceI shot an elephant in my pyjamas.” Here is a graphical representation of the constituency parse tree:


The parse tree on the left refers to shooting an elephant wearing pyjamas and the parse tree on the right indicates the subject shooting an elephant while in his pyjamas. 

The entire sentence is broken into sub-phases until we have terminal words remaining. VP denotes a verb phrase and NP denotes noun phrases. 

Checkout: NLP Project Ideas & Topics

Dependency Parsing vs Constituency Parsing

Constituency parsing can also be implemented using the Stanford parser. It essentially parses a given sentence as per the constituency parser and subsequently converts the constituency parse tree into a dependency tree. 

If your goal is to break a sentence into sub-phrases, you should implement constituency parsing. However, if you want to explore the dependencies between the words in a sentence, you should use dependency parsing. 

Ads of upGrad blog

Popular AI and ML Blogs & Free Courses


If you found this article helpful, you should check out upGrad’s 6-month PG Certification in Machine Learning and NLP that offers personalised mentorship from industry experts of Flipkart, Gramener, and Zee5. 

The program is designed for engineers, software/ IT, Data & other professionals looking to get a foothold in Data Science and Machine Learning. This Post Graduate Certification from IIIT BBangalorethe boasts a 58% average salary hike is all you need to land advanced positions of Data Analyst, Data Scientist, ML Engineer, and NLP Engineer in top companies. Block your seat today at just Rs. 3,034 per month!


Pavan Vadapalli

Blog Author
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology strategy.
Get Free Consultation

Select Coursecaret down icon
Selectcaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Popular Machine Learning Course

Frequently Asked Questions (FAQs)

1What is the use of dependency parsing in NLP?

In natural language processing, dependency parsing is a technique used to identify semantic relations between words in a sentence. Dependency parsers are used to map the words in a sentence to semantic roles, thereby identifying the syntactic relations between words. Dependency parsing is a well-known approach for syntactic analysis of natural language texts at the surface structure level. In this method, the syntactic structure of a sentence is recovered from a linear sequence of word tokens, by analyzing the syntactic dependencies between words and identifying the syntactic category of each word.

2What are the applications of dependency parsing?

Here is a list of several application areas where dependency parsing is used. One of the major uses of dependency parsing is in semantic role labeling (SRL) and information extraction, which are components of natural language processing. Dependency parsing is also used for syntactic chunking and constituency parsing outside of NLP tasks. Dependency parsing is fundamentally different from phrase structure parsing, which maps the words in a sentence to the corresponding phrase marker or tree structure.

3What is the basic difference between syntactic parsing and dependency parsing?

The difference between syntactic parser and dependency parser is that, a dependency parser builds a parse tree and a syntactic parser builds a syntax tree. Syntactic parsing involves using predefined rules to define syntax and a dependency parser, on the other hand, can understand all kinds of phrases and also can deal with ambiguous input. A dependency parser can be used for phrase recognition, chunking , dependency analysis, chunking and parsing.

Explore Free Courses

Suggested Blogs

Data Preprocessing in Machine Learning: 7 Easy Steps To Follow
Summary: In this article, you will learn about data preprocessing in Machine Learning: 7 easy steps to follow. Acquire the dataset Import all the cr
Read More

by Kechit Goyal

29 Oct 2023

Natural Language Processing (NLP) Projects & Topics For Beginners [2023]
What are Natural Language Processing Projects? NLP project ideas advanced encompass various applications and research areas that leverage computation
Read More

by Pavan Vadapalli

04 Oct 2023

15 Interesting MATLAB Project Ideas & Topics For Beginners [2023]
Learning about MATLAB can be tedious. It’s capable of performing many tasks and solving highly complex problems of different domains. If youR
Read More

by Pavan Vadapalli

03 Oct 2023

Top 16 Artificial Intelligence Project Ideas & Topics for Beginners [2023]
Summary: In this article, you will learn the 16 AI project ideas & Topics. Take a glimpse below. Predict Housing Price Enron Investigation Stock
Read More

by Pavan Vadapalli

27 Sep 2023

Top 15 Deep Learning Interview Questions & Answers
Although still evolving, Deep Learning has emerged as a breakthrough technology in the field of Data Science. From Google’s DeepMind to self-dri
Read More

by Prashant Kathuria

21 Sep 2023

Top 8 Exciting AWS Projects & Ideas For Beginners [2023]
AWS Projects & Topics Looking for AWS project ideas? Then you’ve come to the right place because, in this article, we’ve shared multiple AWS proj
Read More

by Pavan Vadapalli

19 Sep 2023

Top 15 IoT Interview Questions & Answers 2023 – For Beginners & Experienced
These days, the minute you indulge in any technology-oriented discussion, interview questions on cloud computing come up in some form or the other. Th
Read More

by Kechit Goyal

15 Sep 2023

45+ Interesting Machine Learning Project Ideas For Beginners [2023]
Summary: In this Article, you will learn Stock Prices Predictor Sports Predictor Develop A Sentiment Analyzer Enhance Healthcare Prepare ML Algorith
Read More

by Jaideep Khare

14 Sep 2023

Why GPUs for Machine Learning? Ultimate Guide
In the realm of modern technology, the convergence of data and algorithms has paved the way for groundbreaking advancements in artificial intelligence
Read More

by Pavan Vadapalli

14 Sep 2023

Schedule 1:1 free counsellingTalk to Career Expert
footer sticky close icon