Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
2import torch
3
4MODEL_NAME = "wtarit/nllb-600M-th-en"
5
6model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
7tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8device = 0 if torch.cuda.is_available() else "cpu"
9
10translation_pipeline = pipeline(
11 "translation",
12 model=model,
13 tokenizer=tokenizer,
14 src_lang="tha_Thai",
15 tgt_lang="eng_Latn",
16 max_length=400,
17 device=device
18)
19
20# Run translation pipeline
21result = translation_pipeline("สวัสดี เราคือโมเดลแปลภาษา")
22print(result[0]['translation_text'])