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

Small extension for visualize_text function #401

Closed
p16i opened this issue Jun 10, 2020 · 4 comments
Closed

Small extension for visualize_text function #401

p16i opened this issue Jun 10, 2020 · 4 comments

Comments

@p16i
Copy link
Contributor

p16i commented Jun 10, 2020

Hi,

As a user, it would be great if visualize_text can produce legend for me. Although it might be obvious that green is positive and red is for negative attributions, I still think it might be useful to show it explicitly via legend in some context or situation.

Here is my prototype for the functionality purposed.

image

What do you think?

@bilalsal
Copy link
Contributor

Hi @heytitle, that is a great suggestion, thank you!

We agree on offering the option to show such legend.
If your prototype uses matplotlib, we would much appreciate if you create a PR, that we can review to offer this functionality in the next release.

Thanks!
Bilal

@p16i
Copy link
Contributor Author

p16i commented Jun 10, 2020

Because visualize_text is based on HTML DOMs, my prototype is also based on that.

This is the code I added into visualize_text:

  if legend:
      dom.append('<div style="border-top: 1px solid; margin-top: 5px; padding-top: 5px; display: inline-block">')
      dom.append('<b>Legend: </b>')
      for value, label in zip([-1, 0, 1], ["Negative", "Neutral", "Positive Attribution"]):
        dom.append(
            (
              f'<span style="display: inline-block; width: 10px; height: 10px; border: 1px solid; background-color: {visualization._get_color(value)}"></span>'
              f' {label}'
              f'  '
            )
        )
      dom.append('</div>')

@bilalsal
Copy link
Contributor

Thank you very much @heytitle! You are right, it is implemented in HTML.
We will include your contribution in the next release.

@p16i
Copy link
Contributor Author

p16i commented Jun 10, 2020

hi everyone,

Thanks for the feedback! I'll create a PR soon.

facebook-github-bot pushed a commit that referenced this issue Jul 28, 2020
Summary:
Related to #401.

The PR adds an option for the user to show the legend for `visualize_text`.

<img width="643" alt="image" src="https://user-images.githubusercontent.com/1214890/84386814-45d14780-abf2-11ea-8a5d-6445186597b8.png">

Pull Request resolved: #403

Reviewed By: bilalsal

Differential Revision: D22758674

Pulled By: NarineK

fbshipit-source-id: e8d3c7b222098a59f249e44b0f503230d1ca177e
@p16i p16i closed this as completed Aug 11, 2020
NarineK pushed a commit to NarineK/captum-1 that referenced this issue Nov 19, 2020
Summary:
Related to pytorch#401.

The PR adds an option for the user to show the legend for `visualize_text`.

<img width="643" alt="image" src="https://user-images.githubusercontent.com/1214890/84386814-45d14780-abf2-11ea-8a5d-6445186597b8.png">

Pull Request resolved: pytorch#403

Reviewed By: bilalsal

Differential Revision: D22758674

Pulled By: NarineK

fbshipit-source-id: e8d3c7b222098a59f249e44b0f503230d1ca177e
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

No branches or pull requests

2 participants