Skip to content

Displacy render: Spans are overlapped when rendered. #13056

@mchlsam

Description

@mchlsam

Hello,

I'm trying to display spans with displacy render where I built the span manually.

Several spans can be overlapped.

Sometimes when there are more than 3 spans overlapping, the rendering fails to render properly.

In the following image spans on the second line have 1 token in common so the render should have done 3 lines, instead it overlapped them.
image

How to reproduce the behaviour

doc_rendering = {
    "text": "Welcome to the Bank of China.",
    "spans": [
        {"start_token": 2, "end_token": 5, "label": "SkillNC"},
        {"start_token": 0, "end_token": 2, "label": "Skill"},
        {"start_token": 1, "end_token": 3, "label": "Skill"},
    ],
    "tokens": ["Welcome", "to", "the", "Bank", "of", "China", "."],
}
from spacy import displacy

html = displacy.render(
        doc_rendering,
        style="span",
        manual=True,
        options={"colors": {"Skill": "#56B4E9", "SkillNC": "#FF5733"}},
    )

Your Environment

  • Operating System: linux
  • Python Version Used: 3.10
  • spaCy Version Used: 3.6.1
  • Environment Information: conda 23.5.2

Thanks for your help :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and behaviour differing from documentationfeat / visualizersFeature: Built-in displaCy and other visualizers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions