...

/

Introduction to Dependency Parsing

Introduction to Dependency Parsing

Let's learn about the dependency parser and and how we can use it to the fullest.

What is dependency parsing?

Previously, we focused on POS tags—syntactic categories of words. Though POS tags provide information about neighbor words' tags as well, they do not give away any relations between words that are not neighbors in the given sentence.

In this section, we'll focus on dependency parsing—a more structured way of exploring the sentence syntax. As the name suggests, dependency parsing is related to analyzing sentence structures via dependencies between the tokens. A dependency parser tags syntactic relations between tokens of the sentence and connects syntactically related pairs of tokens. A dependency or a dependency relation is a directed link between two tokens.

The result of the dependency parsing is always a tree, as illustrated in the following diagram:

Press + to interact
An example of a dependency tree
An example of a dependency tree

Dependency relations

What is the use of dependency relations, then? Quite a number of statistical methods in NLP revolve around vector representations of words and treat a sentence as a sequence of words. As you can see in the figure above, a sentence is more than a sequence of tokens—it has a structure; every word in a sentence has a well-defined role, such as verb, subject, object, and so on; hence, sentences definitely have a structure. This structure is used extensively in chatbots, question answering, and machine translation.

The most useful application that first comes to mind is determining the sentence object and subject. Again, let's go back to our travel agency application. Imagine a customer is complaining about the service. Compare the two sentences, "I forwarded you the email" and "You forwarded me the email;" if we eliminate the stopwords "I," "you," "me," and "the," this is what remains:

Press + to interact
I forwarded you the email. -> forwarded email
You forwarded me the email. -> forwarded email

Though the remaining parts of the sentences are identical, sentences have very different meanings and require different answers. In the first sentence, the sentence subject is "I" (then, the answer most probably will start with "you"), and the second sentence's subject is "you" (which will end up in an "I" answer).

Obviously, the dependency parser helps us to go deeper into the sentence syntax and semantics. Let's explore more, starting with dependency relations.

Syntactic relations

spaCy assigns each token a dependency label, just as with other linguistic features such as a lemma or a POS tag. spaCy shows dependency relations with directed arcs. The following illustration shows an example of a dependency relation between a noun and the adjective that qualifies the noun:

Press + to interact
Dependency relation between a noun and its adjective
Dependency relation between a noun and its adjective

A dependency label describes the type of syntactic relation between two tokens as follows: one of the ...