pythainlp.translate
The pythainlp.translate
for machine translation.
Modules
- class pythainlp.translate.Translate(src_lang: str, target_lang: str, use_gpu: bool = False)[source]
Machine Translation
- Parameters
- Options for source & target language
th - en - Thai to English
en - th - English to Thai
th - zh - Thai to Chinese
zh - th - Chinese to Thai
th - fr - Thai to French
- Example
Translate text from Thai to English:
from pythainlp.translate import Translate th2en = Translate('th', 'en') th2en.translate("ฉันรักแมว") # output: I love cat.
- __init__(src_lang: str, target_lang: str, use_gpu: bool = False) None [source]
- Parameters
- Options for source & target language
th - en - Thai to English
en - th - English to Thai
th - zh - Thai to Chinese
zh - th - Chinese to Thai
th - fr - Thai to French
- Example
Translate text from Thai to English:
from pythainlp.translate import Translate th2en = Translate('th', 'en') th2en.translate("ฉันรักแมว") # output: I love cat.
- pythainlp.translate.en_th.download_model_all() None [source]
Download all translation models in advanced
- class pythainlp.translate.en_th.EnThTranslator(use_gpu: bool = False)[source]
English-Thai Machine Translation
from VISTEC-depa Thailand Artificial Intelligence Research Institute
Website: https://airesearch.in.th/releases/machine-translation-models/
:param bool use_gpu : load model to gpu (Default is False)
- translate(text: str) str [source]
Translate text from English to Thai
- Parameters
text (str) – input text in source language
- Returns
translated text in target language
- Return type
- Example
Translate text from English to Thai:
from pythainlp.translate import EnThTranslator enth = EnThTranslator() enth.translate("I love cat.") # output: ฉันรักแมว
- class pythainlp.translate.en_th.ThEnTranslator(use_gpu: bool = False)[source]
Thai-English Machine Translation
from VISTEC-depa Thailand Artificial Intelligence Research Institute
Website: https://airesearch.in.th/releases/machine-translation-models/
:param bool use_gpu : load model to gpu (Default is False)
- translate(text: str) str [source]
Translate text from Thai to English
- Parameters
text (str) – input text in source language
- Returns
translated text in target language
- Return type
- Example
Translate text from Thai to English:
from pythainlp.translate import ThEnTranslator then = ThEnTranslator() then.translate("ฉันรักแมว") # output: I love cat.
- class pythainlp.translate.zh_th.ThZhTranslator(use_gpu: bool = False, pretrained: str = 'Lalita/marianmt-th-zh_cn')[source]
Thai-Chinese Machine Translation
from Lalita @ AI builder
:param bool use_gpu : load model to gpu (Default is False)
- translate(text: str) str [source]
Translate text from Thai to Chinese
- Parameters
text (str) – input text in source language
- Returns
translated text in target language
- Return type
- Example
Translate text from Thai to Chinese:
from pythainlp.translate import ThZhTranslator thzh = ThZhTranslator() thzh.translate("ผมรักคุณ") # output: 我爱你
- class pythainlp.translate.zh_th.ZhThTranslator(use_gpu: bool = False, pretrained: str = 'Lalita/marianmt-zh_cn-th')[source]
Chinese-Thai Machine Translation
from Lalita @ AI builder
:param bool use_gpu : load model to gpu (Default is False)
- translate(text: str) str [source]
Translate text from Chinese to Thai
- Parameters
text (str) – input text in source language
- Returns
translated text in target language
- Return type
- Example
Translate text from Chinese to Thai:
from pythainlp.translate import ZhThTranslator zhth = ZhThTranslator() zhth.translate("我爱你") # output: ผมรักคุณนะ
- class pythainlp.translate.th_fr.ThFrTranslator(use_gpu: bool = False, pretrained: str = 'Helsinki-NLP/opus-mt-th-fr')[source]
Thai-French Machine Translation
Trained by OPUS Corpus
Model from Language Technology Research Group at the University of Helsinki
BLEU 20.4
:param bool use_gpu : load model to gpu (Default is False)
- translate(text: str) str [source]
Translate text from Thai to French
- Parameters
text (str) – input text in source language
- Returns
translated text in target language
- Return type
- Example
Translate text from Thai to French:
from pythainlp.translate.th_fr import ThFrTranslator thfr = ThFrTranslator() thfr.translate("ทดสอบระบบ") # output: "Test du système."