Encipher
Encipher

Reputation: 2946

Export displacy graphics as an image file shows an empty file

I want to export displacy graphics as an image file. I run the following code block in Jupyter Notebook and generate an svg file name sample.svg.

The code block is

import spacy

from spacy import displacy
from pathlib import Path

nlp = spacy.load('en_core_web_lg')

sentence_nlp = nlp("John go home to your family")
svg = displacy.render(sentence_nlp, style="ent", jupyter = False)

output_path = Path("D:\\sample.svg") 
output_path.open("w", encoding="utf-8").write(svg)

The above code gave me an output 393.

When I try to open the svg file by inserting in powerpoint it shows nothing.

I drag and drop the svg file in the Chrome browser.

The result of drag and drop is as follows

enter image description here

Can any one help me to export the correct svg file format?

Thank you.

Upvotes: 1

Views: 132

Answers (1)

Nauel
Nauel

Reputation: 504

Mine worked modifying the style parameter to dep, so:

svg = displacy.render(sentence_nlp, style="dep", jupyter=False)

Resulting in the following: Uploaded .svg in powerpoint

Hope it helps!

Upvotes: 0

Related Questions