displaCy

As of v2.0, spaCy comes with a built-in visualization suite. For more info and examples, see the usage guide on visualizing spaCy.

displacy.serve

Serve a dependency parse tree or named entity visualization to view it in your browser. Will run a simple web server.

NameTypeDescriptionDefault
docslist or DocDocument(s) to visualize.
styleunicodeVisualization style, 'dep' or 'ent'.'dep'
pageboolRender markup as full HTML page.True
minifyboolMinify HTML markup.False
optionsdictVisualizer-specific options, e.g. colors.{}
manualbool Don't parse Doc and instead, expect a dict or list of dicts. See here for formats and examples.False
portintPort to serve visualization.5000

displacy.render

Render a dependency parse tree or named entity visualization.

NameTypeDescriptionDefault
docslist or DocDocument(s) to visualize.
styleunicodeVisualization style, 'dep' or 'ent'.'dep'
pageboolRender markup as full HTML page.False
minifyboolMinify HTML markup.False
jupyterbool Explicitly enable "Jupyter mode" to return markup ready to be rendered in a notebook.detected automatically
optionsdictVisualizer-specific options, e.g. colors.{}
manualbool Don't parse Doc and instead, expect a dict or list of dicts. See here for formats and examples.False
returnsunicodeRendered HTML markup.

Visualizer options

The options argument lets you specify additional settings for each visualizer. If a setting is not present in the options, the default value will be used.

Dependency Visualizer options

NameTypeDescriptionDefault
collapse_punctbool Attach punctuation to tokens. Can make the parse more readable, as it prevents long arcs to attach punctuation.True
compactbool"Compact mode" with square arrows that takes up less space.False
colorunicodeText color (HEX, RGB or color names).'#000000'
bgunicodeBackground color (HEX, RGB or color names).'#ffffff'
fontunicodeFont name or font family for all text.'Arial'
offset_xintSpacing on left side of the SVG in px.50
arrow_strokeintWidth of arrow path in px.2
arrow_widthintWidth of arrow head in px.10 / 8 (compact)
arrow_spacingintSpacing between arrows in px to avoid overlaps.20 / 12 (compact)
word_spacingintHorizontal spacing between words and arcs in px.45
distanceintDistance between words in px.175 / 85 (compact)

Named Entity Visualizer options

NameTypeDescriptionDefault
entslist Entity types to highlight (None for all types).None
colorsdict Color overrides. Entity types in uppercase should be mapped to color names or values.{}

By default, displaCy comes with colours for all entity types supported by spaCy. If you're using custom entity types, you can use the colors setting to add your own colours for them.