How to Use displaCy ENT for Named Entity Visualization

Nov 23, 2023 | Programming

If you’re diving into the exhilarating world of Natural Language Processing (NLP), named entity recognition (NER) is one of the prime skills you’ll want to master. Thanks to tools like displaCy ENT, visualizing entities identified by your models has never been easier! In this article, we’ll explore how to get started with displaCy ENT, troubleshoot common issues, and ensure your entity visualizations shine like jewels in a crown.

What is displaCy ENT?

displaCy ENT is a modern named entity visualizer embedded into the core of the renowned spaCy library. This tool can help you quickly identify and visualize named entities from text, allowing you to see not only what your model believes to be entities but also to explore any possible errors. There’s even a demo available for you to experience it hands-on!

Getting Started with displaCy ENT

  • First, ensure you have Node.js installed on your system as it will be essential for running the demo.
  • Create a local server to visualize the named entities.

Follow these steps to set up the demo:

sudo npm install --global harp
git clone https://github.com/explosion/displacy-ent
cd displacy-ent
harp server

Once this setup is complete, you’ll be able to access the local server at http://localhost:9000!

Using displaCy ENT in Your Project

To integrate displaCy ENT into your own projects, start by installing it via npm:

npm install displacy-ent

Here’s a quick analogy to help you grasp the initialization process: imagine displaCy ENT as a specialized artist ready to draw portraits. You must tell the artist three things: the workspace, the subject of the portrait, and the visual style. Similarly, here’s how you initialize displaCy ENT:

const displacy = new displaCyENT(
    'http://localhost:8000',
    container: '#displacy',
    defaultText: 'When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously.',
    defaultEnts: [person, org, date]
);

Visualizing Named Entities

With displaCy ENT ready to go, you can now render your text to visualize named entities. Here’s how:

const text = 'When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously.';
const model = 'en';
const ents = [person, org, date];
displacy.parse(text, model, ents);

Troubleshooting Tips

While using displaCy ENT, you might encounter a few hiccups. Here are some troubleshooting tips:

  • Ensure all dependencies and packages are correctly installed. Use the command: npm install in your project directory if you’re facing issues.
  • Check your server is running by visiting http://localhost:9000.
  • If you face issues rendering entities, ensure the specified container is present in your HTML.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Understanding Entity Rendering

Similarly to an artist carefully adding details to a portrait, you can manually specify the spans of entities in your text:

const spans = [
    { end: 20, start: 5, type: 'PERSON' },
    { end: 67, start: 61, type: 'ORG' },
    { end: 75, start: 71, type: 'DATE' }
];
const ents = [person, org, gpe, loc, product];
displacy.render(text, spans, ents);

As you can see, you can span out detailed information and provide a complete view of identified named entities in your text.

Wrapping Up

displaCy ENT is a valuable tool that enhances your ability to visualize and debug the operations of your NER systems. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox