moxley01 / spacysee

Use this to visualize dependency parse output from Spacy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update 23/5/2023: this project is now an official part of spaCy universe !

SpacySee

A project that helps you visualize your spaCy docs in Jupyter notebooks

Installation

pip install spacysee

Usage

import spacy
from spacysee import render

nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a neat way to visualize your Spacy docs")

render(doc, width="500", height="500")

Example

Example

Notes

Each of the dependency tags, POS tags and morphological features are clickable. Clicking on a tag will bring up the relevant documentation for that tag.

What did I learn whilst building this?

  • The srcdoc attribute of an iframe (prevents the need for a server, and allows concatenation of arbitrary script tags for passing data to the application)
  • The HtmlInlineScriptPlugin for bundling CRA output into a single HTML file
  • The <base/> tag (for setting the base URL for relative links)
  • Using setuptools to build and deploy a Python package (including package_data)

Development

To contribute to this project, clone the repo and run the following commands:

cd src/spacysee/client && npm start

This will run the CRA development server on port 3000. Then you can use SpacySee in dev mode by passing the dev argument to the render function:

import spacy
from spacysee import render

nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a neat way to visualize your Spacy docs")

render(doc, dev=True)

To deploy your changes, first build the CRA app:

cd src/spacysee/client && npm run build

If you have PyPi permissions for the package, run the following command to build and deploy:

python setup.py sdist bdist_wheel && twine upload dist/*

About

Use this to visualize dependency parse output from Spacy


Languages

Language:HTML 76.8%Language:JavaScript 11.1%Language:TypeScript 11.0%Language:Python 0.9%Language:CSS 0.1%