-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Displacy vizualization for entity linking #9129
Comments
Thanks for the suggestion! |
Let's add those links using "manual" option in displacy. In Rendering data manually there is an example: ex = [{"text": "But Google is starting from behind.",
"ents": [{"start": 4, "end": 10, "label": "ORG"}],
"title": None}]
html = displacy.render(ex, style="ent", manual=True) I propose to add two more keys to "ents" ("kb_id" and "kb_url"): ex = [{"text": "But Google is starting from behind.",
"ents": [{"start": 4, "end": 10, "label": "ORG", "kb_id": "Q95", "kb_url": "https://www.wikidata.org/wiki/Q95"}],
"title": None}]
html = displacy.render(ex, style="ent", manual=True) Then in templates.py we need to add one more line to "TPL_ENT": TPL_ENT = """
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;">
{text}
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">{label}</span>
<a style="text-decoration: none; color: black; font-weight: bold" href="{kb_url}">{kb_id}</a>
</mark>
""" And in render.py we need to add two more lines (to specify kb_id = str(span.get("kb_id") or "")
kb_url = str(span.get("kb_url") or "")
ent_settings = {"label": label, "text": entity, "bg": color, "kb_id": kb_id, "kb_url": kb_url} If that's fine, I could make PR. |
That looks good to me. If you go ahead and open a PR someone more familiar with the related bits of code can review it. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Displacy can vizualize the enitity recognizer. It would be nice to have vizualization for entity linking pipelines as well. So that the links to entities in a knowledge base are also shown.
The text was updated successfully, but these errors were encountered: