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

Is there any way to "pin" the attention view for a single token? #129

Open
allenyllee opened this issue Jan 31, 2024 · 2 comments
Open

Is there any way to "pin" the attention view for a single token? #129

allenyllee opened this issue Jan 31, 2024 · 2 comments

Comments

@allenyllee
Copy link

Hi, thanks for your effort to develop this package! I wonder is there any way to "stick" or "pin" the attention weight view for a single token?

Currently, when I move the mouse pointer to hover a token, the attention view will only focus on connections for that token. But when I move the pointer out of that place, the view will turn in to "bird's eye view", show all the connection for all the tokens.

However, sometimes I need to show the connections for a specific token. When the sequence is so long, I have to scroll down the notebook, and move the pointer out of that token position, then I lost the focus view.

Is there any way to solve this?

@Bachstelze
Copy link

You could zoom out in the browser. That isn't the perfect solution, though could work around in some use cases.
A better solution could be collapsable sections.

@jamesanto
Copy link

I was looking for the same feature, we can probably make the HTML events configurable, but for now you can work around it using something like below:

from IPython.display import HTML, display
html = head_view(
    decoder_attention=self_attn_weights,
    cross_attention=cross_attn_weights,
    encoder_tokens=src_seq,
    decoder_tokens=tgt_seq,
    html_action='return'   # Note: by default it is 'view', you need to change it to 'return' to get the HTML data
)

#  As of now the attention highlighting is done using mouseover and mouseleave events, I have replaced them with click and dblclick respectively. This would break if the underlying javascript changes, but as of now it works with version `1.4.0`
html = HTML(html.data.replace('mouseover', 'click').replace('mouseleave', 'dblclick'))
display(html)

@jessevig please let me know if you are open to making the events configurable. Maybe just a boolean toggle to switch between mouseover/mouseleave to click/dblclick.

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

3 participants