[Flax/run_hybrid_clip] Fix duplicating images when captions_per_image exceeds the number of captions, enable truncation #12752
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Do not duplicate images when the number of captions in an example is smaller than
captions_per_image
.Truncate tokens when number of tokens exceeds
max_length
.Currently, if an example contains a number of captions smaller than
captions_per_image
, the dataset will get scrambled, because the image paths are going to be duplicated but the number of captions is not.For example, if an example contains a single caption and
captions_per_image
is equal to 2, one caption will be appended to the captions list, but two image path will be appended to theimage_paths list
. This results in mismatching file_path-caption pairs.This pull request fixes this issue.
Currently, if a tokenized sentence contains a number of tokens >
max_length
, the dimensions of inputs within a batch won't match.This pull request fixes this issue by truncating the tokens to max_length.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@patil-suraj