Dependency Parsing in NLP

SpaCy :

def tok_format(tok):
return "_".join([tok.orth_, tok.tag_, tok.dep_])

def to_nltk_tree(node):
if node.n_lefts + node.n_rights > 0:
return Tree(tok_format(node), [to_nltk_tree(child) for child in node.children])
return tok_format(node)

command = "Submit debug logs to project lead today at 9:00 AM"
en_doc = en_nlp(u'' + command)

[to_nltk_tree(sent.root).pretty_print() for sent in en_doc.sents]
head_word = "null"
question = "What films featured the character Popeye Doyle ?"
en_doc = en_nlp(u'' + question)
for sent in en_doc.sents:
for token in sent:
if token.dep == nsubj and (token.pos == NOUN or token.pos == PROPN):
head_word = token.text
elif token.dep == attr and (token.pos == NOUN or token.pos == PROPN):
head_word = token.text
print(question+" ("+head_word+")")




Product Management | Productivity | Stoicism

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Linear Regression Explanation with Example

Evolution of Graph Neural Networks for Recommender Systems

Artificial Intelligence competitions. Kaggle Problem - House Prices: Advanced Regression Techniques

Memory Hygiene With Tensorflow During Model Training and Deployment for Inference

Methods and algorithms for 3D/4D change analysis and virtual laser scanning

3 Probabilistic Frameworks You should know | The Bayesian Toolkit

Deep Learning on Structured Data: part 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shirish Kadam

Shirish Kadam

Product Management | Productivity | Stoicism

More from Medium

Term Frequency — Inverse Document Frequency

An image displaying a few sentences

Chinese Word Segmentation with code

JANSY: Just Another Natural language processing attacker on Sentimental analYsis

Performance Analysis of Text-Summary Generation Models Using ROUGE Score