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

Fix random_mask_tokenize when the text is long #680

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/open_clip/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def random_mask_tokenize(texts: Union[str, List[str]], context_length: int = 77)
if len(tokens) > context_length - 2: # 2 for sot and eot token
indices = np.random.permutation(len(tokens)).tolist()
indices = indices[:context_length - 2]
tokens = tokens[indices]
tokens = [tokens[i] for i in indices]
tokens = [sot_token,] + tokens + [eot_token,]
result[i, :len(tokens)] = torch.tensor(tokens)

Expand Down Expand Up @@ -350,4 +350,4 @@ def get_order(x):
tokens[-1] = eot_token
result[i, :len(tokens)] = torch.tensor(tokens)

return result
return result