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

[NER] add an NER visualizer #2500

Merged
merged 5 commits into from
Dec 1, 2022
Merged

Conversation

cheungdaven
Copy link
Contributor

@cheungdaven cheungdaven commented Nov 30, 2022

Description of changes:
Users can visualize the ner predictions using the added visualize_ner function.

from autogluon.multimodal.utils import visualize_ner
pred = [{'entity_group': 'B-TITLE', 'start': 0, 'end': 4}, {'entity_group': 'I-TITLE', 'start': 5, 'end': 7}, {'entity_group': 'I-TITLE', 'start': 8, 'end': 15}, {'entity_group': 'B-GENRE', 'start': 22, 'end': 30}, {'entity_group': 'B-GENRE', 'start': 31, 'end': 38}, {'entity_group': 'I-GENRE', 'start': 39, 'end': 44}, {'entity_group': 'I-DIRECTOR', 'start': 80, 'end': 87}]
sent = "Game of Thrones is an American fantasy drama television series created by David Benioff"
visualize_ner(sent, pred)

and it will be rendered as:

Screen Shot 2022-11-30 at 1 32 40 PM

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

Job PR-2500-3bc908a is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2500/3bc908a/index.html

@github-actions
Copy link

github-actions bot commented Dec 1, 2022

Job PR-2500-0ad8a2f is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2500/0ad8a2f/index.html

if entity_group.startswith("B-") or entity_group.startswith("I-"):
entity_group = entity_group[2:]
if entity_group not in self.colors:
self.colors.update({entity_group: "#%06X" % randint(0, 0xFFFFFF)})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can potentially add a “seed” option in initializer and draw random integers from the random state: https://numpy.org/doc/stable/reference/random/legacy.html?highlight=numpy%20random%20randomstate#numpy.random.RandomState

this will ensure that the colors picked for each NERVisualizer instance will be the same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to randomstate and the seed is made configurable in the latest commit.

@github-actions
Copy link

github-actions bot commented Dec 1, 2022

Job PR-2500-a37fcdc is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2500/a37fcdc/index.html

-------
An NER html visualizer.
"""
visualizer = NERVisualizer(prediction, sentence)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little curious about the advantages of defining class NERVisualizer . Would the visualization effect be the same if we call a function with the same functionality as the above _repr_html_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repr_html is an interface provided by IPython for display. It can be used to display the object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a docstring to the _repr_html_ so that developers would know about this interface?

Copy link
Contributor

@zhiqiangdon zhiqiangdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visualization looks great!

Copy link
Contributor

@suzhoum suzhoum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@bryanyzhu bryanyzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@github-actions
Copy link

github-actions bot commented Dec 1, 2022

Job PR-2500-f50a662 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2500/f50a662/index.html

@github-actions
Copy link

github-actions bot commented Dec 1, 2022

Job PR-2500-6a77759 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2500/6a77759/index.html

@cheungdaven cheungdaven merged commit af99dd1 into autogluon:master Dec 1, 2022
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.

None yet

5 participants