mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #429] encode_text gives different clip features for the same text, single batch vs mutliple batch #367
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#367
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 @KevinNWalker on GitHub (Feb 27, 2024).
Original GitHub issue: https://github.com/openai/CLIP/issues/429
I seem to get different results from encode_text when providing text as a single batch, or as part of several batches.
See the code sample below:
` import clip
import numpy
When I run this I get the following results:
Max diff in tokens 0 Max diff in features 0.000732421875Is this to be expected or am I using the code incorrectly?
Many thanks
@bonjour-npy commented on GitHub (Mar 2, 2024):
Hi there👋
I think your code is correct and the result of your code is also correct.
To the best of my knowledge (I can't be certain it's 100% right), the tokenization of the text in CLIP model is taking corresponding values from the
fixeddictvocab. In other words, if the input text is the same, the tokenizer will always return the same result. That's whytext_1,text_2[0]andtext_2[1]are exactly the same.But when it comes to function
encode_text, it's generated bynn.Embedding, and the output of the Embedding Layer may be affected by the batch_size and context of the input or something else like that.Here's a simple test:
And my output is shown below:
We can jump to a conclusion (not meticulous enough apparently) from the result of text3 and text4, the context didn't affect the output of encode_text, it was the batch_size.
If you'd like to further communicate, feel free to reach out to me at
nipeiyang@163.com.