How to visualize named entities in custom colors
See original GitHub issueThere’s an options
in Spacy which allows us to use custom colors for named entity visualization. I’m trying to use the same options in scispacy for the named entities. I simply created two lists of entities
and randomly generated colors
and put them in options
dictionary like the following:
options = {"ents": entities, "colors": colors}
Where entities
is a list of NEs in scispacy NER models and colors
is a list of the same size. But using such an option in either displacy.serve
or displacy.render (for jupyter)
does not work. I’m using the options like the following:
displacy.serve(doc, style="ent", options=options)
I wonder if using the color option only works for predefined named entities in the Spacy or there’s something wrong with the way I’m using the option?
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top GitHub Comments
@DeNeutoy This is the exact code I’m using:
Where
get_entity_options()
is a method I wrote for getting the color options like the following (everybody, feel free to use it if you find it useful):Using the full model, I can’t see any visualization, but when I switch to a specific NER model I do see the visualization.
@phosseini : very cool, thank you! I added your code (for my own use / tests) as a method, giving the following results! 😃
entity_options.py
Python 3.7 venv
Screenshots
random colors = False
:random colors = True
: