bug(cleaners): translate_text passes text instead of chunk in attention window loop
Maintainers usually reply within 6 days
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 82/100
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 thetest_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
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Unstructured-IO/unstructured
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Unstructured-IO/unstructured#4876 ·
Maintainers usually reply within 6 days
-
bug: partition_email() raises io.UnsupportedOperation on a file-like object that cannot seekPossibly taken @Bensonluo claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Unstructured-IO/unstructured#4864 ·
Maintainers usually reply within 6 days
-
fix(nlp): match single-letter bullets in the enumerated bullet patternPossibly taken @Eapp1e claimed this 33 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Unstructured-IO/unstructured#4635 ·
Maintainers usually reply within 6 days
-
extract_text_before/extract_text_after raise UnboundLocalError when the pattern is absentPossibly taken @ayam04 claimed this 103 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Unstructured-IO/unstructured#4427 · 3 comments ·
Maintainers usually reply within 6 days
-
Large HTML documents cannot be partitioned using the partition_html function.Possibly taken @CrepuscularIRIS claimed this 229 days ago. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Unstructured-IO/unstructured#4289 · 1 comment ·
Maintainers usually reply within 6 days
All issues in Unstructured-IO/unstructured
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TigreGotico/orthography2ipa#2950 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
🐛 bug 👩💻 équipe CE
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
betagouv/conseillers-entreprises#4835 ·
Maintainers usually reply within 1 day
-
area: integrations documentation priority: P2 size: XS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
eddiejaoude/StackDash#798 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ThinkR-open/mordew#88 ·