Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified pythainlp/corpus/thai2rom_encoder.onnx
Binary file not shown.
11 changes: 8 additions & 3 deletions pythainlp/transliterate/thai2rom_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ def __init__(self) -> None:
self._maxlength: int = 100

self._char_to_ix: Dict[str, int] = loader["char_to_ix"]
self._ix_to_char: Dict[int, str] = loader["ix_to_char"]
self._target_char_to_ix: Dict[str, int] = loader["target_char_to_ix"]
self._ix_to_target_char: Dict[int, str] = loader["ix_to_target_char"]
# JSON keys are always strings; convert to int for index-based lookup.
self._ix_to_char: Dict[int, str] = {
int(k): v for k, v in loader["ix_to_char"].items()
}
self._ix_to_target_char: Dict[int, str] = {
int(k): v for k, v in loader["ix_to_target_char"].items()
}

# encoder/ decoder
# Load encoder decoder onnx models.
Expand Down Expand Up @@ -219,7 +224,7 @@ def run(

decoder_input = np.array([topi])

if decoder_input == end_token:
if decoder_input.item() == end_token:
return outputs[:di]

return outputs
Expand Down
2 changes: 1 addition & 1 deletion tests/extra/testx_transliterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_romanize_thai2rom_onnx(self):
romanize("ความอิ่ม", engine="thai2rom_onnx"), "khwam-im"
)
self.assertEqual(
romanize("กานต์ ณรงค์", engine="thai2rom_onnx"), "kan narong"
romanize("กานต์ ณรงค์", engine="thai2rom_onnx"), "kan narang"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that "kan narang" is a wrong transliteration.

The transliteration should be along these lines:

  • กานต์ / กาน / kan
  • ณรงค์ / นะ-รง / na-rong

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird. It should get same output. I think new onnxruntime may change the output.

)
self.assertEqual(romanize("สกุนต์", engine="thai2rom_onnx"), "sakun")
self.assertEqual(romanize("ชารินทร์", engine="thai2rom_onnx"), "charin")
Expand Down
Loading