Add TEVL to speed up sentence chunker #71
Merged
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.
This pull request includes several changes to the
src/chonkie/chunker/sentence.py
file to enhance the sentence chunking functionality. The most important changes include adding new imports, introducing a new configuration parameter, adding methods for estimating token counts, and refactoring the chunking logic to improve performance and accuracy.Enhancements to sentence chunking:
src/chonkie/chunker/sentence.py
: Added imports forbisect_left
andaccumulate
to support new chunking logic.src/chonkie/chunker/sentence.py
: Introduced theuse_approximate
parameter in the__init__
method to allow for approximate token count estimation. [1] [2]src/chonkie/chunker/sentence.py
: Added the_estimate_token_counts
method to estimate token counts based on character length, and the_get_feedback
method to adjust estimates based on actual token counts.src/chonkie/chunker/sentence.py
: Refactored the_prepare_sentences
method to use either accurate or estimated token counts, and to calculate sentence positions more efficiently.src/chonkie/chunker/sentence.py
: Refactored thechunk
method to use cumulative token counts andbisect_left
for efficient chunk creation, and added feedback adjustment for better accuracy.