Skip to content

displaCy: Separating Punctuations in Dependency Visualization #13305

@zar-zar-hlaing

Description

@zar-zar-hlaing

Firstly, I am very grateful for your open-source tool for dependency visualization.

When I tested the input with separate punctuations, the generated output figure from the displacy.serve or displacy.render functions attached the punctuations to the tokens.

How can I separate punctuations in dependency visualization?

The scripts that I tested and the generated output figure are also attached:

import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("The curious cat, with a fluffy tail, explored the garden.")

# Dependency Info of the input sentence.
"""
1       The     the     DET     DT      _       3       det     _       _
2       curious curious ADJ     JJ      _       3       amod    _       _
3       cat     cat     NOUN    NN      _       10      nsubj   _       SpaceAfter=No
4       ,       ,       PUNCT   ,       _       3       punct   _       _
5       with    with    ADP     IN      _       3       prep    _       _
6       a       a       DET     DT      _       8       det     _       _
7       fluffy  fluffy  ADJ     JJ      _       8       amod    _       _
8       tail    tail    NOUN    NN      _       5       pobj    _       SpaceAfter=No
9       ,       ,       PUNCT   ,       _       3       punct   _       _
10      explored        explore VERB    VBD     _       0       ROOT    _       _
11      the     the     DET     DT      _       12      det     _       _
12      garden  garden  NOUN    NN      _       10      dobj    _       SpaceAfter=No
13      .       .       PUNCT   .       _       10      punct   _       SpaceAfter=No
"""

spacy.displacy.serve(doc, style="dep")

The output is: 

![sample-dependency-visualization](https://github.com/explosion/spaCy/assets/18095355/ae876697-b2b2-436d-824d-9342d4b53a29)

Metadata

Metadata

Assignees

No one assigned

    Labels

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