Hey folks! Today in this tutorial, we will be understanding what Dependency Parsing is and how to implement the same using the Python programming language.
What is Dependency Parsing?
The technique of assessing the grammatical structure of a sentence based on the dependencies between the words in a sentence is known as Dependency Parsing.
Various tags in dependency parsing describe the relationship between two words in a sentence. These are the dependencies tags.
Why is Dependency Parsing needed?
Dependency parsing allows us to construct a parsing tree using tags to determine the relationship between words in a sentence rather than using any Grammar rule as in syntactic parsing, which provides a lot of flexibility even when the order of words changes.
Implementing Dependency Parsing in Python
For implementing Dependency Parsing, we would make use of the
spaCy module in Python. So, first of all, we import the same into our program.
import spacy from spacy import displacy
Now let’s take some random sentences on which we want to perform Dependency Parsing.
text1 = 'It took me more than two hours to translate a few pages of English.' text2 = 'The old rusted farm equipment surrounded the house predicting its demise.' text3 = 'I am a great listener, really good with empathy vs sympathy and all that, but I hate people.' text4 = 'The ants enjoyed the barbecue more than the family.'
Next, we use
spacy.load function which will help to construct a language object and load in the model data and weights, and return it.
Finally, we will display the dependency parsing output for the texts mentioned in the previous code snippet.
Congratulations! You just learned how to build a Dependency Parsing chart for sentences using NLP. Hope you enjoyed it! 😇
Liked the tutorial? In any case, I would recommend you to have a look at the tutorials mentioned below:
- Stemming and Lemmatization in Python
- Creating Bag of Words Model from Scratch in python
- Word Cloud using Python
- Sentiment Analysis using Python
Thank you for taking your time out! Hope you learned something new!! 😄