Skip to content

Commit adefafc

Browse files
authored
Merge pull request #1268 from PyThaiNLP/copilot/verify-type-hints-and-docs
Verify and fix type hints, annotations, and docstrings
2 parents bbb5854 + 964f209 commit adefafc

117 files changed

Lines changed: 618 additions & 404 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ module = [
433433
"torch.*",
434434
"tqdm.*",
435435
"transformers.*",
436+
"ufal.*",
436437
"ufal.chu_liu_edmonds.*",
437438
"word2word.*",
438439
"wtpsplit.*",

pythainlp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
thai_above_vowels = "\u0e31\u0e34\u0e35\u0e36\u0e37\u0e4d\u0e47" # 7
1515
thai_below_vowels = "\u0e38\u0e39" # 2
1616

17-
thai_tonemarks = "\u0e48\u0e49\u0e4a\u0e4b" # 4
17+
thai_tonemarks: str = "\u0e48\u0e49\u0e4a\u0e4b" # 4
1818

1919
# Paiyannoi, Maiyamok, Phinthu, Thanthakhat, Nikhahit, Yamakkan:
2020
# These signs can be part of a word
2121
thai_signs = "\u0e2f\u0e3a\u0e46\u0e4c\u0e4d\u0e4e" # 6 chars
2222

2323
# Any Thai character that can be part of a word
24-
thai_letters = "".join(
24+
thai_letters: str = "".join(
2525
[thai_consonants, thai_vowels, thai_tonemarks, thai_signs]
2626
) # 74
2727

pythainlp/ancient/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
22
# SPDX-FileType: SOURCE
33
# SPDX-License-Identifier: Apache-2.0
4-
"""Ancient versions of the Thai language
5-
"""
4+
"""Ancient versions of the Thai language"""
65

76
__all__ = ["aksonhan_to_current", "convert_currency"]
87

pythainlp/augment/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
22
# SPDX-FileType: SOURCE
33
# SPDX-License-Identifier: Apache-2.0
4-
"""Thai text augment
5-
"""
4+
"""Thai text augment"""
65

76
__all__ = ["WordNetAug"]
87

pythainlp/augment/lm/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
22
# SPDX-FileType: SOURCE
33
# SPDX-License-Identifier: Apache-2.0
4-
"""Language Models
5-
"""
4+
"""Language Models"""
65

76
__all__ = [
87
"FastTextAug",

pythainlp/augment/lm/fasttext.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class FastTextAug:
1515
"""
1616

1717
def __init__(self, model_path: str):
18-
""":param str model_path: path of model file
19-
"""
18+
""":param str model_path: path of model file"""
2019
from gensim.models.fasttext import FastText as FastText_gensim
2120
from gensim.models.keyedvectors import KeyedVectors
2221

@@ -38,8 +37,8 @@ def tokenize(self, text: str) -> list[str]:
3837
"""
3938
return word_tokenize(text, engine="icu")
4039

41-
def modify_sent(self, sent: str, p: float = 0.7) -> list[list[str]]:
42-
""":param str sent: text of sentence
40+
def modify_sent(self, sent: list[str], p: float = 0.7) -> list[list[str]]:
41+
""":param list[str] sent: text of sentence
4342
:param float p: probability
4443
:rtype: List[List[str]]
4544
"""
@@ -57,7 +56,7 @@ def modify_sent(self, sent: str, p: float = 0.7) -> list[list[str]]:
5756

5857
def augment(
5958
self, sentence: str, n_sent: int = 1, p: float = 0.7
60-
) -> list[tuple[str]]:
59+
) -> list[tuple[str, ...]]:
6160
"""Text Augment from fastText
6261
6362
You may want to download the Thai model

pythainlp/augment/lm/phayathaibert.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def __init__(self) -> None:
2020
)
2121

2222
self.tokenizer = AutoTokenizer.from_pretrained(_MODEL_NAME)
23-
self.model_for_masked_lm = AutoModelForMaskedLM.from_pretrained(_MODEL_NAME)
23+
self.model_for_masked_lm = AutoModelForMaskedLM.from_pretrained(
24+
_MODEL_NAME
25+
)
2426
self.model = pipeline(
2527
"fill-mask",
2628
tokenizer=self.tokenizer,
@@ -53,7 +55,9 @@ def generate(
5355

5456
return gen_txt
5557

56-
def augment(self, text: str, num_augs: int = 3, sample: bool = False) -> list[str]:
58+
def augment(
59+
self, text: str, num_augs: int = 3, sample: bool = False
60+
) -> list[str]:
5761
"""Text augmentation from PhayaThaiBERT
5862
5963
:param str text: Thai text
@@ -87,7 +91,9 @@ def augment(self, text: str, num_augs: int = 3, sample: bool = False) -> list[st
8791
if num_augs <= MAX_NUM_AUGS:
8892
for rank in range(num_augs):
8993
gen_text = self.generate(text, rank, sample=sample)
90-
processed_text = re.sub("<_>", " ", self.processor.preprocess(gen_text))
94+
processed_text = re.sub(
95+
"<_>", " ", self.processor.preprocess(gen_text)
96+
)
9197
augment_list.append(processed_text)
9298
else:
9399
raise ValueError(

pythainlp/augment/word2vec/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
22
# SPDX-FileType: SOURCE
33
# SPDX-License-Identifier: Apache-2.0
4-
"""Word2Vec
5-
"""
4+
"""Word2Vec"""
65

76
__all__ = ["Word2VecAug", "Thai2fitAug", "LTW2VAug"]
87

pythainlp/augment/word2vec/bpemb_wv.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def tokenizer(self, text: str) -> list[str]:
2727
return self.bpemb_temp.encode(text) # type: ignore[no-any-return]
2828

2929
def load_w2v(self):
30-
"""Load BPEmb model
31-
"""
30+
"""Load BPEmb model"""
3231
self.aug = Word2VecAug(
3332
self.model, tokenize=self.tokenizer, type="model"
3433
)

pythainlp/augment/word2vec/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
class Word2VecAug:
1111
def __init__(
12-
self, model: str, tokenize: Callable[[str], list[str]], type: str = "file"
12+
self,
13+
model: str,
14+
tokenize: Callable[[str], list[str]],
15+
type: str = "file",
1316
) -> None:
1417
""":param str model: path of model
1518
:param Callable[[str], list[str]] tokenize: tokenize function

0 commit comments

Comments
 (0)