Skip to content
This repository was archived by the owner on Mar 12, 2019. It is now read-only.

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

displaCy Jupyter extension

by @ines

Simple extension for Jupyter (formerly iPython) Notebook that lets you visualize a JSON-formatted dependency parse using the displaCy visualizer.

displaCy Jupyter extension

Example parse:

{
    "arcs": [
        {"dir": "left", "end": 1, "label": "nsubj", "start": 0},
        {"dir": "right", "end": 2, "label": "acomp", "start": 1}
    ],

    "words": [
        {"tag": "NNP", "text": "Jupyter"},
        {"tag": "VBZ", "text": "is"},
        {"tag": "JJ", "text": "cool"}
    ]
}

To render the visualization, select the cell containing the parse and click the magic wand button in your toolbar.

Installation

The extension can be installed straight from GitHub:

jupyter nbextension install https://github.com/explosion/spacy-dev-resources/tree/master/jupyter-displacy

In some cases, the above command was causing problems. If that's the case for you, try installing the JavaScript file directly:

jupyter nbextension install https://raw.githubusercontent.com/explosion/spacy-dev-resources/master/jupyter-displacy/displacy.js

You can now enable the extension and run the notebook server:

jupyter nbextension enable displacy

# run notebook server
jupyter notebook

Configuration

You can override the following settings in your notebook meta data:

{
    "displacy": {
        "distance": 200,
        "offsetX": 50,
        "arrowSpacing": 20,
        "arrowWidth": 10,
        "arrowStroke": 2,
        "wordSpacing": 75,
        "font": "inherit",
        "color": "#000000",
        "bg": "#ffffff"
    }
}
Setting Description Default
distance distance between words in px 200
offsetX spacing on left side of the SVG in px 50
arrowSpacing spacing between arrows in px to avoid overlaps 20
arrowWidth width of arrow head in px 10
arrowStroke width of arc in px 2
wordSpacing spacing between words and arcs in px 75
font font face for all text 'inherit'
color text color, HEX, RGB or color names '#000000'
bg background color, HEX, RGB or color names '#ffffff'

For example:

{
    "displacy": {
        "arrowStroke": 3,
        "font": "Georgia",
        "color": "blue"
    }
}

Todo / Ideas

There's still a lot to be done to make this extension actually useful and make sure it integrates well with people's workflows. I'm pretty new to Jupyter and Jupyter extensions, so feedback and pull requests are appreciated.

  • add option to render parses on load (?)
  • use parameters / different method for configuration (?)
  • make sure visualizations can be exported
  • add keyboard shortcuts
  • integrate with displaCy service to parse text via spaCy from within the notebook