Skip to content

Instantly share code, notes, and snippets.

@JungeAlexander
Last active October 25, 2020 09:12
Show Gist options
  • Save JungeAlexander/dd651e5079853b31f5db6738148f85b6 to your computer and use it in GitHub Desktop.
Save JungeAlexander/dd651e5079853b31f5db6738148f85b6 to your computer and use it in GitHub Desktop.
Simple NER visualization using displaCy
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import spacy
from spacy import displacy
# In[2]:
spacy.__version__
# In[3]:
doc_text = "A common human skin tumour is caused by activating mutations in beta-catenin."
# In[4]:
start_end_labels = [[15, 26, "disease"], [64, 76, "protein"]]
# In[5]:
colors = {"DISEASE": "linear-gradient(90deg, #999999, #cccccc)",
"PROTEIN": "linear-gradient(90deg, #aa9cfc, #fc9ce7)"
}
options = {"ents": ["DISEASE", "PROTEIN"], "colors": colors}
# In[6]:
ex = [{"text": doc_text,
"ents": [{"start": x[0], "end": x[1], "label": x[2]} for x in start_end_labels],
"title": "Displacy test from Jupyter"}]
html = displacy.render(ex, style="ent", manual=True, options=options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment