[GH-ISSUE #56] tokenizer.encode vs tokenizer.encoder #49

Closed
opened 2026-10-31 21:10:15 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @normster on GitHub (Mar 10, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/56

Hi,

I noticed that in the code and the colab notebooks you alternate between calling tokenizer.encode() and indexing into the tokenizer.encoder dict. What's the difference between the two? tokenizer.encode('the') returns [518] but tokenizer.encoder['the'] returns 599.

Thanks!

Originally created by @normster on GitHub (Mar 10, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/56 Hi, I noticed that in the code and the colab notebooks you alternate between calling tokenizer.encode() and indexing into the tokenizer.encoder dict. What's the difference between the two? `tokenizer.encode('the')` returns `[518]` but `tokenizer.encoder['the']` returns `599`. Thanks!
Author
Owner

@crowsonkb commented on GitHub (Mar 19, 2021):

If you look at the tokenizer.encoder dict, you can see that 599 is 'the' but 518 is 'the' followed by a word boundary. So .encode('the p') gives [518, 335] while .encode('thep') gives [599, 335]. It's probably correct to use the encode() method.

<!-- gh-comment-id:802888441 --> @crowsonkb commented on GitHub (Mar 19, 2021): If you look at the tokenizer.encoder dict, you can see that 599 is 'the' but 518 is 'the' followed by a word boundary. So `.encode('the p')` gives `[518, 335]` while `.encode('thep')` gives `[599, 335]`. It's probably correct to use the `encode()` method.
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#49
No description provided.