fix: support large input texts with chunking - #100
Open
RSKKSOFFICIAL wants to merge 3 commits into
Open
Conversation
Signed-off-by: RSKKSOFFICIAL <rsksofficial02@gmail.com>
Signed-off-by: RSKKSOFFICIAL <rsksofficial02@gmail.com>
Signed-off-by: RSKKSOFFICIAL <rsksofficial02@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #71
What this does
Large input texts (>250 words) were being silently truncated by the model
because the output hit the decoding length limit mid-document. This adds a
chunking layer that splits the input into smaller pieces before translation,
then joins the results back into a single output.
Changes
lib/Service.py_chunk_text(): splits input at sentence boundaries into chunks ofmax 80 words. Hard-splits any single sentence that exceeds the limit.
_join_chunks(): joins translated chunks in document order. Uses anempty string separator for no-space languages (zh, ja, th, etc.) and a
single space for all others. Chunk order is always preserved regardless of
source/target script direction — each chunk is already translated correctly
by the model independently.
translate(): applies chunking when input exceeds the threshold,caps
max_decoding_lengthproportionally per chunk to prevent runawayrepetition loops, and enforces a minimum
repetition_penaltyper chunk.config.jsonchunkingsection with four configurable parameters:chunk_threshold(250): word count above which input is chunkedchunk_size(80): max words per chunkmin_repetition_penalty(1.5): lower bound for repetition penalty per chunk, prevents output loops on dense scripts like Devanagarimax_decoding_multiplier(3): output token cap as a multiple of input tokens per chunkTesting
Tested with 350+ word inputs across 7 language pairs:
All pairs now produce complete output covering the full input. Before this
change every pair was truncated at roughly Section 03/04 of a 5-section test
document.
RTL languages (Arabic, Persian) are handled correctly, chunks are always
joined in forward document order since each chunk is translated independently.