2

I want Spyder to display the plot of dependencies using Displacy visualizer of Spacy.

Here is the code:

import spacy
nlp = spacy.load('en_core_web_sm')
from spacy import displacy

doc = nlp(u'This is a short text.')
displacy.render(doc, style='dep', options={'distance':110})

The program ends without displaying anything.

If I add jupyter=True, I get this:

<IPython.core.display.HTML object>
polm23
  • 14,456
  • 7
  • 35
  • 59
cagatay.e.sahin
  • 127
  • 1
  • 10

2 Answers2

3

In my case running your code in Spyder 5.1.2 returns me the string for the svg of the plot.

To visualize the plot while running the code from Spyder you will need to use displacy.serve method. That will run a web server serving the svg/plot. You should be able to access/view it at that point through your browser by going to http://localhost:5000/.

Daniel Althviz
  • 386
  • 1
  • 2
  • 10
0

By looking at the source code you will notice you may interact with the HTML yield using the renderer method set_render_wrapper. Read the following post that demonstrates how to essentially assign the render to an svg and save it. (serve is also a good solution actually but this will help save your results directly) Save SpaCy render file as SVG using DisplaCy

MediaVince
  • 479
  • 1
  • 8
  • 13