diff --git a/spacy/displacy/render.py b/spacy/displacy/render.py index 07550f9aa..984971812 100644 --- a/spacy/displacy/render.py +++ b/spacy/displacy/render.py @@ -249,6 +249,12 @@ class EntityRenderer: colors = dict(DEFAULT_LABEL_COLORS) user_colors = registry.displacy_colors.get_all() for user_color in user_colors.values(): + if callable(user_color): + # Since this comes from the function registry, we want to make + # sure we support functions that *return* a dict of colors + user_color = user_color() + if not isinstance(user_color, dict): + raise ValueError(Errors.E925.format(obj=type(user_color))) colors.update(user_color) colors.update(options.get("colors", {})) self.default_color = DEFAULT_ENTITY_COLOR diff --git a/spacy/errors.py b/spacy/errors.py index be71de820..165714d9e 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -476,6 +476,8 @@ class Errors: E199 = ("Unable to merge 0-length span at doc[{start}:{end}].") # TODO: fix numbering after merging develop into master + E925 = ("Invalid color values for displaCy visualizer: expected dictionary " + "mapping label names to colors but got: {obj}") E926 = ("It looks like you're trying to modify nlp.{attr} directly. This " "doesn't work because it's an immutable computed property. If you " "need to modify the pipeline, use the built-in methods like "