Skip to content
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

[Enhancement]: add scores to Displacy entity markup #13756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cceyda
Copy link

@cceyda cceyda commented Feb 19, 2025

Description

This PR adds the ability to pass scores along with entities to displacy with the manual mode. If no score is passed there is no change.

It uses the template below:

# Doing it with a template similar to TPL_KB_LINK so that we don't get empty '()' parenthesis if no score is present
TPL_SCORE = "({score:.2f})"

not sure if should allow modification of template|precision through options?

Example

So far only tested with manual=True mode on jupyter, but if anyone else is willing to complete it feel free~

from spacy import displacy

text="Hello world with scores"
formatted_entities =[  {'start': 0,
                        'end': 5,
                        'label': 'greeting',
                        'score': 0.90},
                        {'start': 5,
                        'end': 11,
                        'label': 'planet',
                        'score': 0.86666},
                        {'start': 17,
                        'end': 23,
                        'label': 'yeay',
                        'score': 0.5},
                        ]
displacy.render([{"text": text, "ents": formatted_entities, "title": None}], style="ent", manual=True,jupyter=True)
image

If a 'score' doesn't exist it isn't shown:
image

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant