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

Dependency graph labels appear upside down #3917

Closed
urigoren opened this issue Jul 7, 2019 · 2 comments
Closed

Dependency graph labels appear upside down #3917

urigoren opened this issue Jul 7, 2019 · 2 comments
Labels
feat / visualizers Feature: Built-in displaCy and other visualizers usage General spaCy usage

Comments

@urigoren
Copy link

urigoren commented Jul 7, 2019

How to reproduce the behaviour

The following code generates a dependecy graph visualisation, with some of the arc labels shown upside down.

See screenshot

from spacy import displacy

viz = {'words': [{'text': 'Balmer', 'tag': ''},
{'text': 'replaces', 'tag': ''},
{'text': 'Gates', 'tag': ''},
{'text': 'at', 'tag': ''},
{'text': 'Microsoft', 'tag': ''}],
'arcs': [{'start': 0, 'end': 1, 'dir': 'left', 'label': 'nsubj'},
{'start': 1, 'end': -1, 'dir': 'right', 'label': 'root'},
{'start': 2, 'end': 1, 'dir': 'right', 'label': 'obj'},
{'start': 3, 'end': 4, 'dir': 'left', 'label': 'case'},
{'start': 4, 'end': 1, 'dir': 'right', 'label': 'obl'}]}

html = displacy.render(viz,
jupyter=False,
style="dep",
manual=True,
options={"compact": True,"color": "blue",}
)
with open("bug.html", 'w') as f:
f.write(html)

Your Environment

  • Operating System: Win10
  • Python Version Used: 3.6.7
  • spaCy Version Used: spacy==2.1.4
  • Environment Information:
@ines ines added bug Bugs and behaviour differing from documentation feat / visualizers Feature: Built-in displaCy and other visualizers labels Jul 8, 2019
@ines ines added usage General spaCy usage and removed bug Bugs and behaviour differing from documentation labels Aug 20, 2019
@ines
Copy link
Member

ines commented Aug 20, 2019

Sorry for only getting to this now. I initially thought this was a bug, but I think it's actually related to how the data is formatted. In your arcs, you're using relative indices and things like 'end': -1. displaCy however expects absolute indices.

For instance, here's the result displaCy would internally produce for that parse:

import spacy
from spacy.displacy import parse_deps

nlp = spacy.load("en_core_web_sm")
doc = nlp("Balmer replaces Gates at Microsoft")
print(parse_deps(doc))
{'words': [{'text': 'Balmer', 'tag': 'PROPN'},
  {'text': 'replaces', 'tag': 'VERB'},
  {'text': 'Gates', 'tag': 'PROPN'},
  {'text': 'at', 'tag': 'ADP'},
  {'text': 'Microsoft', 'tag': 'PROPN'}],
 'arcs': [{'start': 0, 'end': 1, 'label': 'nsubj', 'dir': 'left'},
  {'start': 1, 'end': 2, 'label': 'dobj', 'dir': 'right'},
  {'start': 2, 'end': 3, 'label': 'prep', 'dir': 'right'},
  {'start': 3, 'end': 4, 'label': 'pobj', 'dir': 'right'}],
 'settings': {'lang': 'en', 'direction': 'ltr'}}

Screenshot 2019-08-20 at 15 39 51

@ines ines closed this as completed in cc76a26 Aug 20, 2019
@lock
Copy link

lock bot commented Sep 19, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat / visualizers Feature: Built-in displaCy and other visualizers usage General spaCy usage
Projects
None yet
Development

No branches or pull requests

2 participants