2017-05-14 17:31:23 +00:00
|
|
|
//- 💫 DOCS > API > DISPLACY
|
|
|
|
|
|
|
|
include ../../_includes/_mixins
|
|
|
|
|
|
|
|
p
|
2017-05-14 21:29:36 +00:00
|
|
|
| As of v2.0, spaCy comes with a built-in visualization suite. For more
|
2017-05-14 17:31:23 +00:00
|
|
|
| info and examples, see the usage workflow on
|
2017-05-14 21:29:36 +00:00
|
|
|
| #[+a("/docs/usage/visualizers") visualizing spaCy].
|
2017-05-14 17:31:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
+h(2, "serve") serve
|
|
|
|
+tag method
|
|
|
|
|
|
|
|
p
|
2017-05-14 21:29:36 +00:00
|
|
|
| Serve a dependency parse tree or named entity visualization to view it
|
2017-05-14 17:31:23 +00:00
|
|
|
| in your browser. Will run a simple web server.
|
|
|
|
|
|
|
|
+aside-code("Example").
|
|
|
|
import spacy
|
|
|
|
from spacy import displacy
|
|
|
|
nlp = spacy.load('en')
|
|
|
|
doc1 = nlp(u'This is a sentence.')
|
|
|
|
doc2 = nlp(u'This is another sentence.')
|
|
|
|
displacy.serve([doc1, doc2], style='dep')
|
|
|
|
|
|
|
|
+table(["Name", "Type", "Description", "Default"])
|
|
|
|
+row
|
|
|
|
+cell #[code docs]
|
|
|
|
+cell list or #[code Doc]
|
2017-05-14 21:29:36 +00:00
|
|
|
+cell Document(s) to visualize.
|
2017-05-14 17:31:23 +00:00
|
|
|
+cell
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code style]
|
|
|
|
+cell unicode
|
2017-05-14 21:29:36 +00:00
|
|
|
+cell Visualization style, #[code 'dep'] or #[code 'ent'].
|
2017-05-14 17:31:23 +00:00
|
|
|
+cell #[code 'dep']
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code page]
|
|
|
|
+cell bool
|
|
|
|
+cell Render markup as full HTML page.
|
|
|
|
+cell #[code True]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code minify]
|
|
|
|
+cell bool
|
|
|
|
+cell Minify HTML markup.
|
|
|
|
+cell #[code False]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code options]
|
|
|
|
+cell dict
|
2017-05-14 21:29:36 +00:00
|
|
|
+cell #[+a("#options") Visualizer-specific options], e.g. colors.
|
2017-05-14 17:31:23 +00:00
|
|
|
+cell #[code {}]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code port]
|
|
|
|
+cell int
|
2017-05-14 21:29:36 +00:00
|
|
|
+cell Port to serve visualization.
|
2017-05-14 17:31:23 +00:00
|
|
|
+cell #[code 5000]
|
|
|
|
|
|
|
|
+h(2, "render") render
|
|
|
|
+tag method
|
|
|
|
|
2017-05-14 21:29:36 +00:00
|
|
|
p Render a dependency parse tree or named entity visualization.
|
2017-05-14 17:31:23 +00:00
|
|
|
|
|
|
|
+aside-code("Example").
|
|
|
|
import spacy
|
|
|
|
from spacy import displacy
|
|
|
|
nlp = spacy.load('en')
|
|
|
|
doc = nlp(u'This is a sentence.')
|
|
|
|
html = displacy.render(doc, style='dep')
|
|
|
|
|
|
|
|
+table(["Name", "Type", "Description", "Default"])
|
|
|
|
+row
|
|
|
|
+cell #[code docs]
|
|
|
|
+cell list or #[code Doc]
|
2017-05-14 21:29:36 +00:00
|
|
|
+cell Document(s) to visualize.
|
2017-05-14 17:31:23 +00:00
|
|
|
+cell
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code style]
|
|
|
|
+cell unicode
|
2017-05-14 21:29:36 +00:00
|
|
|
+cell Visualization style, #[code 'dep'] or #[code 'ent'].
|
2017-05-14 17:31:23 +00:00
|
|
|
+cell #[code 'dep']
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code page]
|
|
|
|
+cell bool
|
|
|
|
+cell Render markup as full HTML page.
|
|
|
|
+cell #[code False]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code minify]
|
|
|
|
+cell bool
|
|
|
|
+cell Minify HTML markup.
|
|
|
|
+cell #[code False]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code jupyter]
|
|
|
|
+cell bool
|
|
|
|
+cell
|
|
|
|
| Returns markup using #[+a("http://jupyter.org/") Jupyter]'s
|
|
|
|
| internal methods, ready to be rendered in a notebook.
|
|
|
|
+cell #[code False]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code options]
|
|
|
|
+cell dict
|
2017-05-14 21:29:36 +00:00
|
|
|
+cell #[+a("#options") Visualizer-specific options], e.g. colors.
|
2017-05-14 17:31:23 +00:00
|
|
|
+cell #[code {}]
|
|
|
|
|
|
|
|
+footrow
|
|
|
|
+cell return
|
|
|
|
+cell unicode
|
|
|
|
+cell Rendered HTML markup.
|
|
|
|
+cell
|
|
|
|
|
2017-05-14 21:29:36 +00:00
|
|
|
+h(2, "options") Visualizer options
|
2017-05-14 17:31:23 +00:00
|
|
|
|
|
|
|
p
|
|
|
|
| The #[code options] argument lets you specify additional settings for
|
2017-05-14 21:29:36 +00:00
|
|
|
| each visualizer. If a setting is not present in the options, the default
|
2017-05-14 17:31:23 +00:00
|
|
|
| value will be used.
|
|
|
|
|
2017-05-14 21:29:36 +00:00
|
|
|
+h(3, "options-dep") Dependency Visualizer options
|
2017-05-14 17:31:23 +00:00
|
|
|
|
|
|
|
+aside-code("Example").
|
|
|
|
options = {'compact': True, 'color': 'blue'}
|
|
|
|
displacy.serve(doc, style='dep', options=options)
|
|
|
|
|
|
|
|
+table(["Name", "Type", "Description", "Default"])
|
|
|
|
+row
|
|
|
|
+cell #[code compact]
|
|
|
|
+cell bool
|
|
|
|
+cell "Compact mode" with square arrows that takes up less space.
|
|
|
|
+cell #[code False]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code color]
|
|
|
|
+cell unicode
|
|
|
|
+cell Text color (HEX, RGB or color names).
|
|
|
|
+cell #[code '#000000']
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code bg]
|
|
|
|
+cell unicode
|
|
|
|
+cell Background color (HEX, RGB or color names).
|
|
|
|
+cell #[code '#ffffff']
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code font]
|
|
|
|
+cell unicode
|
|
|
|
+cell Font name or font family for all text.
|
|
|
|
+cell #[code 'Arial']
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code offset_x]
|
|
|
|
+cell int
|
|
|
|
+cell Spacing on left side of the SVG in px.
|
|
|
|
+cell #[code 50]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code arrow_stroke]
|
|
|
|
+cell int
|
|
|
|
+cell Width of arrow path in px.
|
|
|
|
+cell #[code 2]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code arrow_width]
|
|
|
|
+cell int
|
|
|
|
+cell Width of arrow head in px.
|
|
|
|
+cell #[code 10] / #[code 8] (compact)
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code arrow_spacing]
|
|
|
|
+cell int
|
|
|
|
+cell Spacing between arrows in px to avoid overlaps.
|
|
|
|
+cell #[code 20]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code word_spacing]
|
|
|
|
+cell int
|
|
|
|
+cell Horizontal spacing between words and arcs in px.
|
|
|
|
+cell #[code 45]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code distance]
|
|
|
|
+cell int
|
|
|
|
+cell Distance between words in px.
|
|
|
|
+cell #[code 175] / #[code 85] (compact)
|
|
|
|
|
2017-05-14 21:29:36 +00:00
|
|
|
+h(3, "options-ent") Named Entity Visualizer options
|
2017-05-14 17:31:23 +00:00
|
|
|
|
|
|
|
+aside-code("Example").
|
|
|
|
options = {'ents': ['person', 'org', 'product'],
|
|
|
|
'colors': {'org': 'yellow'}}
|
|
|
|
displacy.serve(doc, style='ent', options=options)
|
|
|
|
|
|
|
|
+table(["Name", "Type", "Description", "Default"])
|
|
|
|
+row
|
|
|
|
+cell #[code ents]
|
|
|
|
+cell list
|
|
|
|
+cell
|
|
|
|
| Entity types to highlight (#[code None] for all types).
|
|
|
|
+cell #[code None]
|
|
|
|
|
|
|
|
+row
|
|
|
|
+cell #[code colors]
|
|
|
|
+cell dict
|
|
|
|
+cell
|
|
|
|
| Color overrides. Entity types in lowercase should be mapped to
|
|
|
|
| color names or values.
|
|
|
|
+cell #[code {}]
|
|
|
|
|
|
|
|
p
|
|
|
|
| By default, displaCy comes with colours for all
|
|
|
|
| #[+a("/docs/api/annotation#named-entities") entity types supported by spaCy].
|
2017-05-14 21:27:56 +00:00
|
|
|
| If you're using custom entity types, you can use the #[code colors]
|
2017-05-14 17:31:23 +00:00
|
|
|
| setting to add your own colours for them.
|