Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] ZShot Displacy doesn't return the markup #9

Closed
marmg opened this issue Oct 3, 2022 · 7 comments · Fixed by #10
Closed

[Bug] ZShot Displacy doesn't return the markup #9

marmg opened this issue Oct 3, 2022 · 7 comments · Fixed by #10
Labels
bug Something isn't working

Comments

@marmg
Copy link
Collaborator

marmg commented Oct 3, 2022

Summary

The displacy.render method should return the rendered HTML markup, but currently isn't returning anything

Describe the bug
The displacy.render method should return the rendered HTML markup when is not in Jupyter Notebook, but currently isn't returning anything.

To Reproduce

from zshot.utils.data_models import Entity
from zshot.linker import LinkerSMXM
from zshot import PipelineConfig
from zshot.utils.displacy import displacy

nlp = spacy.blank('en')
config = PipelineConfig(
    entities=[
        Entity(name="company", description="The name of a company"),
        Entity(name="location", description="A physical location"),
        Entity(name="chemical compound", description="any substance composed of identical molecules consisting of atoms of two or more chemical elements."),
        Entity(name="organic compound", description="Any of a large class of chemical compounds in which one or more atoms of carbon are covalently linked to atoms of other elements, most commonly hydrogen, oxygen, or nitrogen. The few carbon-containing compounds not classified as organic include carbides, carbonates, and cyanides. See chemical compound.")
    ], 
    linker=LinkerSMXM()
)
nlp.add_pipe("zshot", config=config, last=True)

text_acetamide = "CH2O2 is a chemical compound similar to Acetamide used in International Business " \
        "Machines Corporation (IBM) to create new materials that act like PAGs."

doc = nlp(text_acetamide)
res = displacy.render(doc, style="ent", jupyter=False)
print(res is None)
True

Expected behavior
It should return the HTML Markup of the visualization.

from spacy import displacy

nlp = spacy.blank('en')
config = PipelineConfig(
    entities=[
        Entity(name="company", description="The name of a company"),
        Entity(name="location", description="A physical location"),
        Entity(name="chemical compound", description="any substance composed of identical molecules consisting of atoms of two or more chemical elements."),
        Entity(name="organic compound", description="Any of a large class of chemical compounds in which one or more atoms of carbon are covalently linked to atoms of other elements, most commonly hydrogen, oxygen, or nitrogen. The few carbon-containing compounds not classified as organic include carbides, carbonates, and cyanides. See chemical compound.")
    ], 
    linker=LinkerSMXM()
)
nlp.add_pipe("zshot", config=config, last=True)

text_acetamide = "CH2O2 is a chemical compound similar to Acetamide used in International Business " \
        "Machines Corporation (IBM) to create new materials that act like PAGs."

doc = nlp(text_acetamide)
res = displacy.render(doc, style="ent", jupyter=False)
print(res is None)
False
@marmg marmg added the bug Something isn't working label Oct 3, 2022
@AkashKhamkar
Copy link

Hey @marmg change the code from res = displacy.render(doc, style="ent", jupyter=False) to res = displacy.serve(doc, style="ent") and it will work and show the renders in the browser tab. I would suggest only use displacy.render() when using in a jupyter notebook .

Below is the ouput image of the render.

image

@GabrielePicco
Copy link
Contributor

Thanks for the comment @AkashKhamkar , this bug should be fixed in #10

@AkashKhamkar
Copy link

you changed and pushed it already, that some fast bug fixing! :)

@marmg
Copy link
Collaborator Author

marmg commented Oct 4, 2022

Hello @AkashKhamkar. Thank you for your answer.

The displacy.serve function will indeed show the result in the browser, but it doesn't return anything. If the user wants to save the HTML of the visualization, the displacy.render function shall be used, and it should return the HTML like the original displacy.

@AkashKhamkar
Copy link

AkashKhamkar commented Oct 4, 2022

oh, I though you meant return as in doesn't render the graphic 😅. I see the only change done is to options right ? when calling the s_displacy.render(), hmm.. then the jupyter argument should get passed along and output the html markup..

@GabrielePicco
Copy link
Contributor

@AkashKhamkar indeed, all the arguments are passed to the original Spacy method, the only function of our wrapper is to automatically add colors to user defined entities.

1 similar comment
@GabrielePicco
Copy link
Contributor

@AkashKhamkar indeed, all the arguments are passed to the original Spacy method, the only function of our wrapper is to automatically add colors to user defined entities.

GabrielePicco pushed a commit that referenced this issue Oct 28, 2022
* Added compatibility with different flair version

* Updated init error message

* Removed compatibility with flair<0.11

* Fix Flair version to 0.11

Co-authored-by: Marcos Martinez Galindo <[email protected]>
Co-authored-by: Gabriele Picco <[email protected]>
GabrielePicco pushed a commit that referenced this issue Oct 28, 2022
* Added compatibility with different flair version

* Updated init error message

* Removed compatibility with flair<0.11

* Fix Flair version to 0.11

Co-authored-by: Marcos Martinez Galindo <[email protected]>
Co-authored-by: Gabriele Picco <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants