Git Product home page Git Product logo

displacy's Introduction

conll displacy

displacy displaCy.py is a NLP visualizer. It's a Python port of displaCy.js. It can be used to visualize POS relationships detected using spaCy's syntactic parser.

The following settings are available:

Setting Description Default
wordDistance distance between words in px 200
arcDistance distance between arcs in px 60
offsetX spacing on left side of the SVG in px 50
arrowSpacing spacing between arrows in px to avoid overlaps 20
arrowWidth width of arrow head in px 10
arrowStroke width of arc in px 2
wordSpacing spacing between words and arcs in px 75
font font face for all text 'inherit'
color text color, HEX, RGB or color names '#000000'
bg background color, HEX, RGB or color names '#ffffff'

Changing the theme and colours

You can find the current theme settings in app/static/displacy.css. All elements contained in the SVG output come with tags and data attributes and can be styled flexibly using CSS. By default, the currentColor of the element is used for colouring,meaning only need to change the color property in CSS.

The following classes are available:

Class name Description
.displacy-word word text
.displacy-tag POS tag
.displacy-token container of word and POS tag
.displacy-arc arrow arc (without label or arrow head)
.displacy-label relation type (arrow label)
.displacy-arrowhead arrow head
.displacy-arrow container of arc, label and arrow head

Additionally, you can use these attributes as attribute selectors:

Attribute Value On Element
data-tag POS tag value .displacy-token, .displacy-word, .displacy-tag
data-label relation type value .displacy-arrow, .displacy-arc, .displacy-arrowhead, .displacy-label
data-dir direction of arrow .displacy-arrow, .displacy-arc, .displacy-arrowhead, .displacy-label

Using a combination of those selectors and some basic CSS logic, you can create pretty powerful templates to style the elements based on their role and function in the parse. Here are a few examples:

/* Format all words in 12px Helvetica and grey */

.displacy-word {
    font: 12px Helvetica, Arial, sans-serif;
    color: grey;
}


/* Make all noun phrases (tags that start with "NN") green */

.displacy-tag[data-tag^="NN"] {
    color: green;
}


/* Make all right arrows red and hide their labels */

.displacy-arc[data-dir="right"],
.displacy-arrowhead[data-dir="right"] {
    color: red;
}

.displacy-label[data-dir="right"] {
    display: none;
}


/* Hide all tags for verbs (tags that start with "VB") that are NOT the base form ("VB") */

.displacy-tag[data-tag^="VB"]:not([data-tag="VB"]) {
    display: none;
}


/* Only display tags if word is hovered (with smooth transition) */

.displacy-tag {
    opacity: 0;
    transition: opacity 0.25s ease;
}

.displacy-word:hover + .displacy-tag {
    opacity: 1;
}

Adding custom data attributes

displaCy lets you define custom attributes via the JSON representation of the parse on both words and arcs:

"words": [
    {
        "tag": "NNS",
        "text": "Robots",
        "data": [
            [ "custom", "your value here" ],
            [ "example", "example text here" ]
        ]
    }
]

Custom attributes are added as data attributes prefixed with data-, so their names shouldn't contain spaces or special characters. If added to words, the data attributes are attached to the token (.displacy-token), if added to arcs, they're attached to the arrow (.displacy-arrow):

<text class="displacy-token" data-custom="your value here" data-example="example text here">...</text>

displacy's People

Contributors

nineinchnick avatar rknaebel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.