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
2 changes: 1 addition & 1 deletion pythainlp/augment/lm/phayathaibert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import random
import re
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from transformers import AutoModelForMaskedLM, AutoTokenizer, Pipeline
Expand Down
2 changes: 1 addition & 1 deletion pythainlp/augment/lm/wangchanberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from transformers import CamembertTokenizer, Pipeline
Expand Down
2 changes: 1 addition & 1 deletion pythainlp/augment/word2vec/bpemb_wv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from pythainlp.augment.word2vec.core import Word2VecAug

Expand Down
2 changes: 1 addition & 1 deletion pythainlp/augment/word2vec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import itertools
from typing import TYPE_CHECKING, Any, Callable
from typing import TYPE_CHECKING, Callable

if TYPE_CHECKING:
from gensim.models.keyedvectors import KeyedVectors
Expand Down
4 changes: 2 additions & 2 deletions pythainlp/corpus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import tarfile
import zipfile
from http.client import HTTPResponse
from http.client import HTTPMessage, HTTPResponse
from importlib.resources import files
from typing import TYPE_CHECKING

Expand All @@ -34,7 +34,7 @@ class _ResponseWrapper:
"""Wrapper to provide requests.Response-like interface for urllib response."""

status_code: int
headers: "http.client.HTTPMessage"
headers: HTTPMessage
_content: bytes

def __init__(self, response: HTTPResponse) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pythainlp/el/_multiel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Union
from typing import TYPE_CHECKING, Union

if TYPE_CHECKING:
from multiel import BELA
Expand Down
1 change: 0 additions & 1 deletion pythainlp/morpheme/thaiwordcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import re
from typing import Pattern

_THANTHAKHAT_CHAR: str = "\u0e4c" # Thanthakhat (cancellation of sound)

Expand Down
2 changes: 1 addition & 1 deletion pythainlp/parse/transformers_ud.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

if TYPE_CHECKING:
from transformers import (
AutoTokenizer,
AutoModelForQuestionAnswering,
AutoTokenizer,
TokenClassificationPipeline,
)

Expand Down
3 changes: 2 additions & 1 deletion pythainlp/spell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"get_words_spell_suggestion",
]

from pythainlp.spell.pn import NorvigSpellChecker
from typing import Type

from pythainlp.spell.pn import NorvigSpellChecker

DEFAULT_SPELL_CHECKER: Type[NorvigSpellChecker] = NorvigSpellChecker

# these imports are placed here to avoid circular imports
Expand Down
16 changes: 9 additions & 7 deletions pythainlp/spell/words_spelling_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ def __init__(

"""
try:
import numpy as np
import numpy as np # noqa: F401
except ModuleNotFoundError:
raise ModuleNotFoundError("""
raise ModuleNotFoundError(
"""
Please installing the package via 'pip install numpy onnxruntime'.
""")
"""
)
except Exception as e:
raise RuntimeError(f"An unexpected error occurred: {e}") from e
self.model_dir = model_dir
Expand All @@ -81,7 +83,7 @@ def __init__(
def _load_embeddings(self) -> tuple[list[str], NDArray[np.float32]]:
"""Loads embeddings matrix and vocabulary list."""
import numpy as np

input_matrix = np.load(
os.path.join(self.model_dir, "embeddings.npy")
)
Expand All @@ -95,7 +97,7 @@ def _load_embeddings(self) -> tuple[list[str], NDArray[np.float32]]:
def _load_suggestion_words(self, words_list: list[str]) -> NDArray[np.str_]:
"""Loads the list of words used for suggestions."""
import numpy as np

words = np.array(words_list)
return words

Expand Down Expand Up @@ -152,7 +154,7 @@ def _get_subwords(self, word: str) -> tuple[list[str], NDArray[np.int_]]:
def get_word_vector(self, word: str) -> NDArray[np.float32]:
"""Computes the normalized vector for a single word."""
import numpy as np

# subword_ids[1] contains the array of indices for the word and its subwords
subword_ids = self._get_subwords(word)[1]

Expand Down Expand Up @@ -193,7 +195,7 @@ def _tokenize(self, sentence: str) -> list[str]:
def get_sentence_vector(self, line: str) -> NDArray[np.float32]:
"""Computes the mean vector for a sentence."""
import numpy as np

tokens = self._tokenize(line)
vectors = []
for t in tokens:
Expand Down
2 changes: 1 addition & 1 deletion pythainlp/translate/small100.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from transformers import M2M100ForConditionalGeneration
import torch
from transformers import M2M100ForConditionalGeneration

from .tokenization_small100 import SMALL100Tokenizer

Expand Down
4 changes: 2 additions & 2 deletions pythainlp/translate/th_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import torch
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer


class ThFrTranslator:
Expand Down
4 changes: 2 additions & 2 deletions pythainlp/translate/tokenization_small100.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import os
from pathlib import Path
from shutil import copyfile
from typing import TYPE_CHECKING, Optional, Union, cast
from typing import TYPE_CHECKING, Any, Optional, Union, cast

if TYPE_CHECKING:
from sentencepiece import SentencePieceProcessor
Expand Down Expand Up @@ -439,7 +439,7 @@ def load_spm(
path: str, sp_model_kwargs: dict[str, str]
) -> SentencePieceProcessor:
import sentencepiece

spm = sentencepiece.SentencePieceProcessor(**sp_model_kwargs)
spm.Load(str(path))
return spm
Expand Down
4 changes: 2 additions & 2 deletions pythainlp/translate/zh_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import torch
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer


class ThZhTranslator:
Expand Down
2 changes: 1 addition & 1 deletion pythainlp/transliterate/thaig2p_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Use a pipeline as a high-level helper
from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from transformers import Pipeline
Expand Down
2 changes: 1 addition & 1 deletion pythainlp/transliterate/umt5_thaig2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Use a pipeline as a high-level helper
from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from transformers import Pipeline
Expand Down
1 change: 0 additions & 1 deletion pythainlp/util/emojiconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import annotations

import re
from typing import Pattern

_emoji_th: dict[str, str] = {
"😀": "หน้ายิ้มยิงฟัน",
Expand Down
1 change: 0 additions & 1 deletion pythainlp/util/syllable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from __future__ import annotations

import re

from typing import Pattern

from pythainlp import thai_consonants, thai_tonemarks
Expand Down
6 changes: 5 additions & 1 deletion pythainlp/wangchanberta/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from typing import TYPE_CHECKING, Union

if TYPE_CHECKING:
from transformers import CamembertTokenizer, PreTrainedModel, PreTrainedTokenizerBase
from transformers import (
CamembertTokenizer,
PreTrainedModel,
PreTrainedTokenizerBase,
)
from transformers.pipelines import TokenClassificationPipeline

from pythainlp.tokenize import word_tokenize
Expand Down
Loading