Skip to content

Align word box columns with reversed text for RTL recognition - #18386

Open
longzhenren wants to merge 1 commit into
PaddlePaddle:mainfrom
longzhenren:fix/rtl-word-box-column-alignment
Open

longzhenren wants to merge 1 commit into
PaddlePaddle:mainfrom
longzhenren:fix/rtl-word-box-column-alignment

Conversation

@longzhenren

Copy link
Copy Markdown

Root cause: For dicts with "arabic" in the filename, BaseRecLabelDecode sets reverse=True and decode() reverses the decoded text with pred_reverse() before calling get_word_info(). pred_reverse keeps runs of LTR characters together and reverses the token sequence, but selection (the feature-column mask) was passed through unchanged. get_word_info then pairs each character of the reversed text with the ascending column list, so every word-level box is attributed to the wrong columns.

Reproduction (return_word_box=True, reversed dict, text "Hello مرحبا"):

character reported column actual column
first char of reversed text (ا) 0 10
last char (space) never reported 5

Every column after the first LTR run shifts, so downstream word-level bbox alignment for RTL models is wrong end to end.

Fix: when reversing, reorder the selected columns with the same token mapping as pred_reverse (new helper reverse_selection returning an explicit column array) and pass that to get_word_info, which now accepts either the boolean mask or an explicit column array. Non-reversed decoding is untouched.

Test: tests/unit/test_rec_postprocess.py covers the mixed LTR/RTL case (columns follow the reversed reading order, including with interleaved blanks) and the unchanged LTR behavior. Run with pytest tests/unit/test_rec_postprocess.py (5 passed).

@CLAassistant

CLAassistant commented Oct 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@longzhenren

Copy link
Copy Markdown
Author

I have read and agree to the Contributor License Agreement

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants