bug(cleaners): translate_text passes text instead of chunk in attention window loop

Open Beginner friendly
#4,558 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@gunjan-l is already working on this.

Since Oct 19, 2026.

  • #4559 by @gunjan-l — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Read unstructured/cleaners/translate.py around translate_text() and the existing tests in test_unstructured/cleaners/test_translate.py. Check how chunk_by_attention_window() feeds the loop, then run the translation tests with a multi-chunk input. Done means each chunk is translated once and the resulting text retains all chunks; the issue also identifies skipped or ineffective tests to address.

Written by the indexing model from the issue text.

Description

Describe the bug

In unstructured/cleaners/translate.py line 70, translate_text() chunks long text across attention windows using chunk_by_attention_window(). However, inside the chunk iteration loop, _translate_text(text, model, tokenizer) is passed the original full text variable instead of the loop variable chunk.

Code Location

https://github.com/Unstructured-IO/unstructured/blob/main/unstructured/cleaners/translate.py#L66-L72

    chunks: List[str] = chunk_by_attention_window(text, tokenizer, split_function=sent_tokenize)

    translated_chunks: List[str] = []
    for chunk in chunks:
        translated_chunks.append(_translate_text(text, model, tokenizer))  # <-- passes `text` instead of `chunk`

    return " ".join(translated_chunks)
Expected behavior

Each attention-window chunk should be translated independently:

    for chunk in chunks:
        translated_chunks.append(_translate_text(chunk, model, tokenizer))
Impact

When an input document exceeds the MarianMT model attention window (resulting in multiple chunks), the first 512 tokens are translated $N$ times and joined together with spaces. The subsequent chunks ($2 \dots N$) are never translated and are lost.

Additional context

In test_unstructured/cleaners/test_translate.py:

  • Lines 59 and 64 contain comparisons without assert.
  • Line 62 def translate_works_with_arabic() is missing the test_ prefix and is skipped by pytest.
Status / Next Steps

Per the contributing guidelines, I am happy to pick this up and submit a pull request with the fix, associated multi-chunk unit tests, and changelog update.

Dominant language
HTML
Stars
15.8k
Forks
1.4k
Avg merge
8d 4h
Merged PRs (30d)
40

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Unstructured-IO/unstructured

All issues in Unstructured-IO/unstructured

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.