Nicolas Joseph Nicolas Joseph - 2 months ago 36
Python Question

How to get the dependency tree with SpaCy?

I have been trying to find how to get the dependency tree with spacy but I can't find anything on how to get the tree.

There is information on how to navigate the tree.



It turns out, the tree is available through the tokens in a document.

Would you want to find the root of the tree, you can just go though the document:

def find_root(docu):
    for token in docu:
        if token.head is token:
            return token

To then navigate the tree, the tokens have API to get through the children