Blog_Banner_Asset
    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
Views
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: 

Source

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
auxauxiliary
aux:passpassive auxiliary
casecase-marking
cccoordinating conjunction
cc:preconjpreconjunct
ccompclausal complement
clfclassifier
compoundcompound
compound:lvclight verb construction
compound:prtphrasal verb particle
compound:redupreduplicated compounds
compound:svcserial verb compounds
conjconjunct
copcopula
csubjclausal subject
csubj:passclausal passive subject
depunspecified dependency
detdeterminer
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
explexpletive
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
flat:namenames
goeswithgoes with
iobjindirect object
listlist
markmarker
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
objobject
obloblique nominal
obl:agentagent modifier
obl:argoblique argument
obl:lmodlocative modifier
obl:tmodtemporal modifier
orphanorphan
parataxisparataxis
punctpunctuation
reparandumoverridden disfluency
rootroot
vocativevocative
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 = result.next()

list(dependency.triples())

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:

Source

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

Conclusion

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!

Profile

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

Artificial Intelligence course fees
5370
Artificial intelligence (AI) was one of the most used words in 2023, which emphasizes how important and widespread this technology has become. If you
Read More

by venkatesh Rajanala

29 Feb 2024

Artificial Intelligence in Banking 2024: Examples & Challenges
6096
Introduction Millennials and their changing preferences have led to a wide-scale disruption of daily processes in many industries and a simultaneous g
Read More

by Pavan Vadapalli

27 Feb 2024

Top 9 Python Libraries for Machine Learning in 2024
75561
Machine learning is the most algorithm-intense field in computer science. Gone are those days when people had to code all algorithms for machine learn
Read More

by upGrad

19 Feb 2024

Top 15 IoT Interview Questions & Answers 2024 – For Beginners & Experienced
64413
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

19 Feb 2024

Data Preprocessing in Machine Learning: 7 Easy Steps To Follow
152686
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

18 Feb 2024

Artificial Intelligence Salary in India [For Beginners & Experienced] in 2024
908637
Artificial Intelligence (AI) has been one of the hottest buzzwords in the tech sphere for quite some time now. As Data Science is advancing, both AI a
Read More

by upGrad

18 Feb 2024

24 Exciting IoT Project Ideas & Topics For Beginners 2024 [Latest]
759337
Summary: In this article, you will learn the 24 Exciting IoT Project Ideas & Topics. Take a glimpse at the project ideas listed below. Smart Agr
Read More

by Kechit Goyal

18 Feb 2024

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

by Pavan Vadapalli

17 Feb 2024

45+ Interesting Machine Learning Project Ideas For Beginners [2024]
328066
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

16 Feb 2024

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