ai-labs.org blog

Visualize parsing result

This is just a primitive “setup and use” snippet.

It is very easy to use the Jupyter Notebook with nbextensions for visualazing the tests of spaCy model. The displaCy Jupyter extension is a simple extension for Jupyter Notebook that lets you visualize a JSON-formatted dependency parse using the displaCy visualizer.

excerpt_separator:

  1. Install Jupyter Notebook.

  2. Install Jupyter nbextension.
     pip install jupyter_contrib_nbextensions
    
  3. Install displaCy Jupyter extension.
     jupyter nbextension install --user https://github.com/explosion/spacy-dev-resources/tree/master/jupyter-displacy
    
  4. Enable the extension.
     jupyter nbextension enable displacy
    
  5. Process whole sentence and visualize the results.
     doc1 = nlp('Dependency tree parsing results can be visualized easily in a notebook.')
     for token in doc1:
         print(token.text, token.lemma_, token.pos_, token.tag_)
     displacy.render(doc1, style='dep', jupyter=True)
    

See: SpaCy Visualizers

See: Possible visualizer options