How do I render Displacy on Spyder Notebook?

Viewed 447

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>
1 Answers

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/.

Related