[GH-ISSUE #47] attention on the text #45

Closed
opened 2026-10-31 21:10:11 +00:00 by bsakaguchi · 4 comments
Owner

Originally created by @haofanwang on GitHub (Feb 21, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/47

Given a sentence, is it possible to know which words receive more attention? In practice, I found that CLIP focused on several keywords in the sentence.

Originally created by @haofanwang on GitHub (Feb 21, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/47 Given a sentence, is it possible to know which words receive more attention? In practice, I found that CLIP focused on several keywords in the sentence.
Author
Owner

@jongwook commented on GitHub (Feb 21, 2021):

See #18

<!-- gh-comment-id:782814357 --> @jongwook commented on GitHub (Feb 21, 2021): See #18
Author
Owner

@haofanwang commented on GitHub (Feb 21, 2021):

Hi, @jongwook, I modified the code based on the suggestion, so I got the weight from the multihead-attention layer. But it is a tensor with shape (batch_size, target sequence length, source sequence length) = (1, 77, 77). How do I visualize this matrix to show the importance of each word?

<!-- gh-comment-id:782830273 --> @haofanwang commented on GitHub (Feb 21, 2021): Hi, @jongwook, I modified the code based on the suggestion, so I got the weight from the multihead-attention layer. But it is a tensor with shape (batch_size, target sequence length, source sequence length) = (1, 77, 77). How do I visualize this matrix to show the importance of each word?
Author
Owner

@haofanwang commented on GitHub (Feb 21, 2021):

solved.

<!-- gh-comment-id:782858349 --> @haofanwang commented on GitHub (Feb 21, 2021): solved.
Author
Owner

@jongwook commented on GitHub (Feb 21, 2021):

Glad to know that it sorted out! I haven't actually tried visualizing the attention map, and it's very intriguing to see. Thanks for making a notebook for this :D

<!-- gh-comment-id:782927580 --> @jongwook commented on GitHub (Feb 21, 2021): Glad to know that it sorted out! I haven't actually tried visualizing the attention map, and it's very intriguing to see. Thanks for making [a notebook](https://colab.research.google.com/github/haofanwang/natural-language-joint-query-search/blob/main/colab/clip_attention.ipynb) for this :D
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#45
No description provided.