diff --git a/CITATION.cff b/CITATION.cff index 2d85753aa..923f0d4fe 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -23,6 +23,7 @@ authors: abstract: PyThaiNLP is a Thai natural language processing library for Python. It provides standard linguistic analysis for the Thai language, including tokenization and part-of-speech tagging. Additionally, it offers standard Thai locale utility functions, such as Thai Buddhist Era date formatting and the conversion of numbers into Thai text. repository-code: "https://github.com/PyThaiNLP/pythainlp" type: software +doi: 10.5281/zenodo.3519354 version: 5.2.0 license-url: "https://spdx.org/licenses/Apache-2.0" keywords: diff --git a/pythainlp/translate/en_th.py b/pythainlp/translate/en_th.py index 0ec11defc..1c517806d 100644 --- a/pythainlp/translate/en_th.py +++ b/pythainlp/translate/en_th.py @@ -11,6 +11,7 @@ from __future__ import annotations import os +import warnings try: from fairseq.models.transformer import TransformerModel @@ -126,26 +127,33 @@ def __init__(self, use_gpu: bool = False): self._model_name = _TH_EN_MODEL_NAME _download_install(self._model_name) - self._model = TransformerModel.from_pretrained( - model_name_or_path=_get_translate_path( - self._model_name, - _TH_EN_FILE_NAME, - "models", - ), - checkpoint_file="checkpoint.pt", - data_name_or_path=_get_translate_path( - self._model_name, - _TH_EN_FILE_NAME, - "vocab", - ), - bpe="sentencepiece", - sentencepiece_model=_get_translate_path( - self._model_name, - _TH_EN_FILE_NAME, - "bpe", - "spm.th.model", - ), - ) + # Suppress model type mismatch warning from transformers + # The pre-trained model has camembert config but works fine + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + message="(?i).*using a model of type .* to instantiate a model of type.*", + ) + self._model = TransformerModel.from_pretrained( + model_name_or_path=_get_translate_path( + self._model_name, + _TH_EN_FILE_NAME, + "models", + ), + checkpoint_file="checkpoint.pt", + data_name_or_path=_get_translate_path( + self._model_name, + _TH_EN_FILE_NAME, + "vocab", + ), + bpe="sentencepiece", + sentencepiece_model=_get_translate_path( + self._model_name, + _TH_EN_FILE_NAME, + "bpe", + "spm.th.model", + ), + ) if use_gpu: self._model.cuda()