mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #371] Question / Confirmation on arange in encode_text #323
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openai/CLIP#323
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AwePhD on GitHub (Jun 29, 2023).
Original GitHub issue: https://github.com/openai/CLIP/issues/371
Hello,
This is a minor question about the code, I want to be sure I do not let slip any subtleties.
In L354 of
model.py, there is the final step to extract the textself.text_projectionis the last projection to have the text featurestext.argmax(dim=-1)picks the features of the EOT token.Why there is a
torch.arange(x.shape[0])? It could bex[:, text.argmax(dim=-1)], right?Thanks for the work, code and model.
@jongwook commented on GitHub (Jun 29, 2023):
We need to extract the features (of shape
transformer.width) from specific different locations of the EOT token across the batch, so the shape becomes[batch_size, transformer.width].If we did
x[:, text.argmax(dim=-1)], it simply selects the features at any of the argmax indices across the batch, so the shape would become[batch_size, batch_size, transformer.width].It could be simpler to use
index_selectinstead and still achieve the same effect, but I found myself fewer mistakes by explicitly indexing withtorch.arange().@AwePhD commented on GitHub (Jul 11, 2023):
Hello,
You are absolutely right, thanks for your time to clear my confusion!