fix: More robust token offset handling for Huggingface tokenizers by benbrandt · Pull Request #131 · benbrandt/text-splitter · GitHub
Skip to content

fix: More robust token offset handling for Huggingface tokenizers - #131

Merged
benbrandt merged 3 commits into
mainfrom
129-not-working-with-certain-tokenizers
Apr 3, 2024
Merged

benbrandt merged 3 commits into
mainfrom
129-not-working-with-certain-tokenizers

Conversation

@benbrandt

Copy link
Copy Markdown
Owner

Handles two issues:

  1. Previously padding tokens were treated as any other token, which provides unexpected behavior in the chunking.
  2. I made some previously wrong assumptions with how the offset ranges were represented (I thought they were inclusive when they were in fact exclusive, just didn't include whitespaces)

Prior to this, if a tokenizer had a padding argument, the chunk sizer would base the count off of the padded tokens. However, for chunk sizing, we don't want to calculate based on the padding tokens, we just want to know how many tokens the given text is.
I had previously assumed the offsets were non-inclusive and needed to become inclusive, however this isn't actually the case, and may not be consistent beyond ByteLevel preprocessors. It seems the offsets refer to the words themselves, and don't need to be adjusted. And therefore we also don't have to adjust for prefixing either, as the offsets stay the same even for prefixed text.
@benbrandt benbrandt linked an issue Apr 3, 2024 that may be closed by this pull request
@codecov

codecov Bot commented Apr 3, 2024 •

Copy link
Copy Markdown

@benbrandt
benbrandt merged commit 47d86fb into main Apr 3, 2024
@benbrandt
benbrandt deleted the 129-not-working-with-certain-tokenizers branch April 3, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not working with certain tokenizer(s)

1 participant