Fix thai2rom_onnx: patch ONNX encoder model and fix inference bugs - #1349
Merged
Conversation
Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix bug with thai2rom_onnx not working
Fix thai2rom_onnx: patch ONNX encoder model and fix inference bugs
Mar 20, 2026
|
bact
reviewed
Mar 20, 2026
| ) | ||
| self.assertEqual( | ||
| romanize("กานต์ ณรงค์", engine="thai2rom_onnx"), "kan narong" | ||
| romanize("กานต์ ณรงค์", engine="thai2rom_onnx"), "kan narang" |
Member
There was a problem hiding this comment.
Note that "kan narang" is a wrong transliteration.
The transliteration should be along these lines:
- กานต์ / กาน / kan
- ณรงค์ / นะ-รง / na-rong
Member
There was a problem hiding this comment.
It's weird. It should get same output. I think new onnxruntime may change the output.
2 tasks
2 tasks
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.



thai2rom_onnxwas completely broken — it crashed on both model load and inference. Three independent bugs, all requiring fixes to restore function.What do these changes do
Restore
thai2rom_onnxromanization to working order:What was wrong
thai2rom_encoder.onnx— model load failure: Newer ONNX Runtime enforces thatTopK'sKinput be a 1-D tensor of shape[1]. The model had threeTopKnodes whoseKinput was a scalar (rank-0) tensor produced byGather. ORT rejected the model outright.JSON key type mismatch —
KeyErrorat inference:ix_to_charandix_to_target_charare loaded from JSON, where all dict keys are strings. The code looked them up withintkeys (self._ix_to_target_char[int(t)]), causingKeyErroron every decode step.NumPy array truth-value — ambiguous comparison:
if decoder_input == end_token:compared a numpy array to a scalar, returning a boolean array rather than a Pythonbool.How this fixes it
thai2rom_encoder.onnx: InsertsConstant+Reshapenode pairs after each offendingGatherto convert the scalarKto shape[1]before eachTopK. ONNX model checker passes.thai2rom_onnx.py— key types: Converts string keys tointat load time via dict comprehensions:{int(k): v for k, v in loader["ix_to_char"].items()}.thai2rom_onnx.py— comparison: Changesif decoder_input == end_token:→if decoder_input.item() == end_token:."กานต์ ณรงค์"from"kan narong"to"kan narang"— the ONNX model produces a slightly different result than the PyTorch model for this word.Your checklist for this pull request
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.