Visualizing Dependency Trees with spaCy Displacy

  • Share this:

Code introduction


This function uses the displacy module from the spaCy library to visualize the dependency tree of the input Doc object. This helps understand the relationships between words in a sentence.


Technology Stack : spaCy, displacy

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
import spacy
from spacy import displacy
from spacy.tokens import Doc

def visualize_dependency_tree(doc: Doc):
    """
    This function takes a spaCy Doc object and visualizes its dependency tree.
    """
    displacy.render(doc, style='dep', jupyter=True)                
              
Tags: