Fix romanize() returning empty string / literal <PAD> for thai2rom engines - #1351
Fix romanize() returning empty string / literal <PAD> for thai2rom engines#1351wannaphong with Copilot wants to merge 3 commits into
<PAD> for thai2rom engines#1351Conversation
…_onnx
- Return "" instead of literal "<PAD>" when model produces no output
- Filter special tokens (<PAD>, <start>, <end>) from romanized output
- Add romanize("สมชาย") test case for both engines (issue #1346)
- Document fixes in CHANGELOG
Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/PyThaiNLP/pythainlp/sessions/4a12e2fc-ac10-4186-9a10-f71db25d87bf
<PAD> for thai2rom engines
|
@copilot @wannaphong note that ONNX-dependent functions are in "noauto" test suite and will not be run in the test CI (due to its large dependency size and long testing time). It has to be tested locally ( The test for thai2rom_onnx is specifically at: pythainlp/tests/noauto_onnx/testn_tokenize_onnx.py Lines 83 to 91 in 715cc06 We can extend this test case to cover more cases, including edge cases. (We should also later move it to testn_transliterate_onnx.py, to put the transliterate test cases in transliterate test file) |
…rehensive test cases - Add test_thai2rom_onnx_romanize: covers somchai (bug-report case), common Thai words, and multi-word input - Add test_thai2rom_onnx_edge_cases: verifies empty string returns "" and that no raw special tokens (<PAD>, <start>, <end>) appear in output Co-authored-by: bact <128572+bact@users.noreply.github.com> Agent-Logs-Url: https://github.com/PyThaiNLP/pythainlp/sessions/a5818628-bfa1-4601-a6ed-b076cab9b8f9
Extended
The module-level import was changed from |
|
Yes but thai2rom (pytorch) should working without has output bug. It's weird. |
|
@wannaphong The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
5 similar comments
|
@wannaphong The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@wannaphong The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@wannaphong The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@wannaphong The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@wannaphong The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
Update #1346, I think it has fixed in #1349 follow #1346 (comment) |



romanize()withengine="thai2rom"orengine="thai2rom_onnx"returned either an empty string or the literal token string"<PAD>"instead of the correct romanization.What was wrong
Two bugs, both engines:
<end>(no characters generated), the code settarget = ["<PAD>"]and returned the 5-character string"<PAD>"instead of"".<PAD>,<start>, or<end>token that appeared would be included literally in the result.Additionally,
thai2rom_onnxhad three pre-existing bugs now fixed (via merged PR #1349 already in the base branch): ONNX encoderTopKK-input was a rank-0 scalar rejected by newer ONNX Runtime;ix_to_char/ix_to_target_charJSON keys are strings but were looked up asint, causingKeyErroron every decode step; loop-terminationdecoder_input == end_tokencompared a NumPy array to a scalar.How this fixes it
thai2rom.py/thai2rom_onnx.py: Return""immediately whentarget_tensor_logitsis empty. For non-empty output, filter out<PAD>,<start>,<end>before joining._SPECIAL_TARGET_TOKENSmodule-level constant (shared pattern in both modules) drives the filter.tests/extra/testx_transliterate.py): Addedromanize("สมชาย") == "somchai"for both engines — the exact case from the bug report.tests/noauto_onnx/testn_tokenize_onnx.py): ExtendedTransliterateONNXTestCaseNwith comprehensive ONNX-specific test cases:test_thai2rom_onnx_romanize: covers the bug-report case ("สมชาย"→"somchai"), common Thai words, and multi-word space-separated input.test_thai2rom_onnx_edge_cases: verifies that empty string input returns""and that no raw special tokens (<PAD>,<start>,<end>) appear in output. Run locally withpython -m unittest tests.noauto_onnx.Your checklist for this pull request
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.