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

cls_attn = attn[:, :, 0, 1:] #18

Open
Bugs-Bunny01 opened this issue Jun 20, 2023 · 4 comments
Open

cls_attn = attn[:, :, 0, 1:] #18

Bugs-Bunny01 opened this issue Jun 20, 2023 · 4 comments

Comments

@Bugs-Bunny01
Copy link

hi,thank you for your contributions to open source.
but i have a problem.
cls_attn = attn[:, :, 0, 1:]
What does this code mean?

@Bugs-Bunny01
Copy link
Author

What do the four dimensions represent?

@youweiliang
Copy link
Owner

Hi,
Thanks for your interest.
The attn has 4 dimensions representing [batch size, number of heads, number of tokens, number of tokens]. The last two dimensions represent the attention maps on the images.
The line cls_attn = attn[:, :, 0, 1:] is to extract the class attention (the attention values of the class token to the image tokens). As the class token is the first token, that leads to the slice [0, 1:] in the attention maps.

@Bugs-Bunny01
Copy link
Author

感谢您的回复,也就是说,attn的第三个维度的0代表着cls-token,第四个维度1:代表着除了cls,其他的token吗

@youweiliang
Copy link
Owner

Yes!

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