Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a473911
Initial plan
Copilot Mar 31, 2026
adb3ca1
Fix docstrings and comments in tokenize and util modules
Copilot Mar 31, 2026
1f5856d
fix: correct doctests and documentation in soundex and tag modules
Copilot Mar 31, 2026
46a8613
docs: fix docstrings and comments in corpus, transliterate, spell, tools
Copilot Mar 31, 2026
f460fae
docs: fix docstrings and comments across multiple modules
Copilot Mar 31, 2026
07d520a
Fix review comments: rtype syntax, version range, CHANGELOG scope
Copilot Mar 31, 2026
7f93359
Changes before error encountered
Copilot Mar 31, 2026
5f3b7a7
Convert :Example: code blocks to proper doctest format in util/ files
Copilot Mar 31, 2026
990e0a0
Update CHANGELOG.md
bact Mar 31, 2026
61e0368
Update pythainlp/soundex/complete_soundex.py
bact Mar 31, 2026
ff7ad8f
docs: convert analyze_thai_text :Example: to doctest format
Copilot Mar 31, 2026
06bf162
docs: convert :Example: sections to runnable doctest format in sounde…
Copilot Mar 31, 2026
c3a52a4
docs: convert :Example: docstrings from RST to runnable doctest format
Copilot Mar 31, 2026
9850bf2
docs: convert :Example: docstrings to runnable doctest format
Copilot Mar 31, 2026
ae86281
docs: fix docstring review issues
Copilot Mar 31, 2026
ea8a599
docs: convert remaining :Example: RST :: blocks to doctest format
Copilot Mar 31, 2026
8301b38
Fix doctest examples in strftime.py
bact Apr 1, 2026
948df5d
Remove doctest skip comments from examples
bact Apr 1, 2026
272184d
Remove doctest SKIP comments from examples
bact Apr 1, 2026
01d1c2f
Update examples in time.py documentation
bact Apr 1, 2026
45daaa7
Remove doctest SKIP comments from examples
bact Apr 1, 2026
acc4814
Fix import example for to_lunar_date function
bact Apr 1, 2026
4abd28c
Fix import statements in time.py for time functions
bact Apr 1, 2026
ce58840
Apply suggestion from @Copilot
bact Apr 1, 2026
3aa8bee
Apply suggestion from @bact
bact Apr 1, 2026
52a7bf0
Fix doctest examples in pronounce.py
bact Apr 1, 2026
5bda967
Refactor example usage in pronounce.py docstrings
bact Apr 1, 2026
3aa3aea
Update doctests in remove_trailing_repeat_consonants
bact Apr 1, 2026
87a2b9b
Update spell_words.py
bact Apr 1, 2026
7892663
Update CHANGELOG with issue reference for changes
bact Apr 1, 2026
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ and this project adheres to
- Full release notes: <https://github.com/PyThaiNLP/pythainlp/releases>
- Commit history: <https://github.com/PyThaiNLP/pythainlp/compare/v5.3.1...v5.3.3>

## [Unreleased]

### Changed

- Fix doctests, docstring formatting, typos, and outdated content
across all modules (#1392).

## [5.3.3] - 2026-03-26

Security fixes and thai2rom_onnx bug fixes.
Expand Down
24 changes: 10 additions & 14 deletions pythainlp/ancient/aksonhan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,24 @@
def aksonhan_to_current(word: str) -> str:
"""Convert AksonHan words to current Thai words

AksonHan (อักษรหัน) writes down two consonants for the \
spelling of the /a/ vowels. (สระ อะ).
AksonHan (อักษรหัน) writes two consonants to spell
the short /a/ vowel (สระ อะ).

Today, รร is an aksonHan word that is still used in Thai.
Today, รร is an aksonhan pattern still used in Thai.

:param str word: Thai word
:return: Thai AksonHan to be converted to current Thai word
:rtype: str

:Example:
::

from pythainlp.ancient import aksonhan_to_current

print(aksonhan_to_current("จกก"))
# output: จัก

print(aksonhan_to_current("บงงคบบ"))
# output: บังคับ

print(aksonhan_to_current("สรรเพชญ")) # รร is still used.
# output: สรรเพชญ
>>> from pythainlp.ancient import aksonhan_to_current
>>> print(aksonhan_to_current("จกก"))
จัก
>>> print(aksonhan_to_current("บงงคบบ"))
บังคับ
>>> print(aksonhan_to_current("สรรเพชญ")) # รร is still used.
สรรเพชญ

"""
if len(word) < 3:
Expand Down
20 changes: 4 additions & 16 deletions pythainlp/ancient/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,10 @@ def convert_currency(value: float, from_unit: str) -> dict[str, float]:
:rtype: dict[str, float]

:Example:
::

from pythainlp.ancient import convert_currency

print(convert_currency(8, "บาท"))
# output:
# {
# 'เบี้ย': 51200.0,
# 'อัฐ': 512.0,
# 'ไพ': 256.0,
# 'เฟื้อง': 64.0,
# 'สลึง': 32.0,
# 'บาท': 8.0,
# 'ตำลึง': 2.0,
# 'ชั่ง': 0.1
# }
>>> from pythainlp.ancient import convert_currency
>>> print(convert_currency(8, "บาท"))
{'เบี้ย': 51200.0, 'อัฐ': 512.0, 'ไพ': 256.0, 'เฟื้อง': 64.0, 'สลึง': 32.0, 'บาท': 8.0, 'ตำลึง': 2.0, 'ชั่ง': 0.1}

"""
conversion_factors_to_att = {
Expand All @@ -57,7 +45,7 @@ def convert_currency(value: float, from_unit: str) -> dict[str, float]:

if from_unit not in conversion_factors_to_att:
raise NotImplementedError(
f"Currency unit '{from_unit}' is not support."
f"Currency unit '{from_unit}' is not supported."
)

# start from 'อัฐ'
Expand Down
9 changes: 4 additions & 5 deletions pythainlp/augment/lm/phayathaibert.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ def augment(
:rtype: List[str]

:Example:
::

from pythainlp.augment.lm import ThaiTextAugmenter
>>> from pythainlp.augment.lm import ThaiTextAugmenter # doctest: +SKIP

aug = ThaiTextAugmenter()
aug.augment("ช้างมีทั้งหมด 50 ตัว บน", num_args=5)
>>> aug = ThaiTextAugmenter() # doctest: +SKIP
>>> aug.augment("ช้างมีทั้งหมด 50 ตัว บน", num_args=5) # doctest: +SKIP

# output = ['ช้างมีทั้งหมด 50 ตัว บนโลกใบนี้ครับ.',
['ช้างมีทั้งหมด 50 ตัว บนโลกใบนี้ครับ.',
'ช้างมีทั้งหมด 50 ตัว บนพื้นดินครับ...',
'ช้างมีทั้งหมด 50 ตัว บนท้องฟ้าครับ...',
'ช้างมีทั้งหมด 50 ตัว บนดวงจันทร์.‼',
Expand Down
9 changes: 4 additions & 5 deletions pythainlp/augment/lm/wangchanberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ def augment(self, sentence: str, num_replace_tokens: int = 3) -> list[str]:
:rtype: List[str]

:Example:
::

from pythainlp.augment.lm import Thai2transformersAug
>>> from pythainlp.augment.lm import Thai2transformersAug # doctest: +SKIP

aug = Thai2transformersAug()
>>> aug = Thai2transformersAug() # doctest: +SKIP

aug.augment("ช้างมีทั้งหมด 50 ตัว บน")
# output: ['ช้างมีทั้งหมด 50 ตัว บนโลกใบนี้',
>>> aug.augment("ช้างมีทั้งหมด 50 ตัว บน") # doctest: +SKIP
['ช้างมีทั้งหมด 50 ตัว บนโลกใบนี้',
'ช้างมีทั้งหมด 50 ตัว บนสุด',
'ช้างมีทั้งหมด 50 ตัว บนบก',
'ช้างมีทั้งหมด 50 ตัว บนนั้น',
Expand Down
9 changes: 4 additions & 5 deletions pythainlp/augment/word2vec/bpemb_wv.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ def augment(
:return: list of synonyms
:rtype: list[str]
:Example:
::

from pythainlp.augment.word2vec.bpemb_wv import BPEmbAug
>>> from pythainlp.augment.word2vec.bpemb_wv import BPEmbAug # doctest: +SKIP

aug = BPEmbAug()
aug.augment("ผมเรียน", n_sent=2, p=0.5)
# output: ['ผมสอน', 'ผมเข้าเรียน']
>>> aug = BPEmbAug() # doctest: +SKIP
>>> aug.augment("ผมเรียน", n_sent=2, p=0.5) # doctest: +SKIP
['ผมสอน', 'ผมเข้าเรียน']
"""
self.sentence: str = sentence.replace(" ", "▁")
self.temp: list[tuple[str, ...]] = self.aug.augment(
Expand Down
9 changes: 4 additions & 5 deletions pythainlp/augment/word2vec/ltw2v.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ def augment(
:rtype: List[Tuple[str]]

:Example:
::

from pythainlp.augment.word2vec import LTW2VAug
>>> from pythainlp.augment.word2vec import LTW2VAug # doctest: +SKIP

aug = LTW2VAug()
aug.augment("ผมเรียน", n_sent=2, p=0.5)
# output: [('เขา', 'เรียนหนังสือ'), ('เขา', 'สมัครเรียน')]
>>> aug = LTW2VAug() # doctest: +SKIP
>>> aug.augment("ผมเรียน", n_sent=2, p=0.5) # doctest: +SKIP
[('เขา', 'เรียนหนังสือ'), ('เขา', 'สมัครเรียน')]
"""
return self.aug.augment(sentence, n_sent, p)
9 changes: 4 additions & 5 deletions pythainlp/augment/word2vec/thai2fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ def augment(
:rtype: List[Tuple[str]]

:Example:
::

from pythainlp.augment.word2vec import Thai2fitAug
>>> from pythainlp.augment.word2vec import Thai2fitAug # doctest: +SKIP

aug = Thai2fitAug()
aug.augment("ผมเรียน", n_sent=2, p=0.5)
# output: [('พวกเรา', 'เรียน'), ('ฉัน', 'เรียน')]
>>> aug = Thai2fitAug() # doctest: +SKIP
>>> aug.augment("ผมเรียน", n_sent=2, p=0.5) # doctest: +SKIP
[('พวกเรา', 'เรียน'), ('ฉัน', 'เรียน')]
"""
return self.aug.augment(sentence, n_sent, p)
9 changes: 4 additions & 5 deletions pythainlp/augment/wordnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,12 @@ def augment(
:rtype: list[list[str]]

:Example:
::

from pythainlp.augment import WordNetAug
>>> from pythainlp.augment import WordNetAug # doctest: +SKIP

aug = WordNetAug()
aug.augment("เราชอบไปโรงเรียน")
# output: [('เรา', 'ชอบ', 'ไป', 'ร.ร.'),
>>> aug = WordNetAug() # doctest: +SKIP
>>> aug.augment("เราชอบไปโรงเรียน") # doctest: +SKIP
[('เรา', 'ชอบ', 'ไป', 'ร.ร.'),
('เรา', 'ชอบ', 'ไป', 'รร.'),
('เรา', 'ชอบ', 'ไป', 'โรงเรียน'),
('เรา', 'ชอบ', 'ไป', 'อาคารเรียน'),
Expand Down
76 changes: 38 additions & 38 deletions pythainlp/benchmarks/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,22 @@ def bleu_score(
:rtype: BleuScore

:Example:
::

from pythainlp.benchmarks import bleu_score

references = ["สวัสดีครับ วันนี้อากาศดีมาก"]
hypotheses = ["สวัสดีค่ะ วันนี้อากาศดี"]
score = bleu_score(references, hypotheses)
print(f"BLEU score: {score['bleu']:.2f}")

::

# Multiple references per hypothesis
references = [
["สวัสดีครับ", "สวัสดีค่ะ"], # two refs for first hypothesis
["ลาก่อนครับ", "ลาก่อนค่ะ"], # two refs for second hypothesis
]
hypotheses = ["สวัสดี", "ลาก่อน"]
score = bleu_score(references, hypotheses)
>>> from pythainlp.benchmarks import bleu_score

>>> references = ["สวัสดีครับ วันนี้อากาศดีมาก"]
>>> hypotheses = ["สวัสดีค่ะ วันนี้อากาศดี"]
>>> score = bleu_score(references, hypotheses)
>>> print(f"BLEU score: {score['bleu']:.2f}")
BLEU score: 28.12

>>> # Multiple references per hypothesis
>>> references = [
... ["สวัสดีครับ", "สวัสดีค่ะ"], # two refs for first hypothesis
... ["ลาก่อนครับ", "ลาก่อนค่ะ"], # two refs for second hypothesis
... ]
>>> hypotheses = ["สวัสดี", "ลาก่อน"]
>>> score = bleu_score(references, hypotheses)
"""
from pythainlp.tokenize import word_tokenize

Expand Down Expand Up @@ -282,16 +280,18 @@ def rouge_score(
:rtype: dict[str, RougeScore]

:Example:
::

from pythainlp.benchmarks import rouge_score

reference = "สวัสดีครับ วันนี้อากาศดีมาก"
hypothesis = "สวัสดีค่ะ วันนี้อากาศดี"
scores = rouge_score(reference, hypothesis)
print(f"ROUGE-1 F-measure: {scores['rouge1']['fmeasure']:.4f}")
print(f"ROUGE-2 F-measure: {scores['rouge2']['fmeasure']:.4f}")
print(f"ROUGE-L F-measure: {scores['rougeL']['fmeasure']:.4f}")
>>> from pythainlp.benchmarks import rouge_score

>>> reference = "สวัสดีครับ วันนี้อากาศดีมาก"
>>> hypothesis = "สวัสดีค่ะ วันนี้อากาศดี"
>>> scores = rouge_score(reference, hypothesis)
>>> print(f"ROUGE-1 F-measure: {scores['rouge1']['fmeasure']:.4f}")
ROUGE-1 F-measure: 0.6000
>>> print(f"ROUGE-2 F-measure: {scores['rouge2']['fmeasure']:.4f}")
ROUGE-2 F-measure: 0.2500
>>> print(f"ROUGE-L F-measure: {scores['rougeL']['fmeasure']:.4f}")
ROUGE-L F-measure: 0.6000
"""
from pythainlp.tokenize import word_tokenize

Expand Down Expand Up @@ -391,14 +391,14 @@ def word_error_rate(
:rtype: float

:Example:
::

from pythainlp.benchmarks import word_error_rate
>>> from pythainlp.benchmarks import word_error_rate

reference = "สวัสดีครับ วันนี้อากาศดีมาก"
hypothesis = "สวัสดีค่ะ วันนี้อากาศดี"
wer = word_error_rate(reference, hypothesis)
print(f"WER: {wer:.4f}")
>>> reference = "สวัสดีครับ วันนี้อากาศดีมาก"
>>> hypothesis = "สวัสดีค่ะ วันนี้อากาศดี"
>>> wer = word_error_rate(reference, hypothesis)
>>> print(f"WER: {wer:.4f}")
WER: 0.4000
"""
from pythainlp.tokenize import word_tokenize

Expand Down Expand Up @@ -469,14 +469,14 @@ def character_error_rate(
:rtype: float

:Example:
::

from pythainlp.benchmarks import character_error_rate
>>> from pythainlp.benchmarks import character_error_rate

reference = "สวัสดีครับ"
hypothesis = "สวัสดีค่ะ"
cer = character_error_rate(reference, hypothesis)
print(f"CER: {cer:.4f}")
>>> reference = "สวัสดีครับ"
>>> hypothesis = "สวัสดีค่ะ"
>>> cer = character_error_rate(reference, hypothesis)
>>> print(f"CER: {cer:.4f}")
CER: 0.3000
"""
# Work with characters directly (no tokenization needed)
ref_chars = list(reference)
Expand Down
Loading
Loading