Link to blog post: https://www.alexanderjunge.net/blog/ner-vis-displacy/
Last active
October 25, 2020 09:12
-
-
Save JungeAlexander/dd651e5079853b31f5db6738148f85b6 to your computer and use it in GitHub Desktop.
Simple NER visualization using displaCy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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