Views
No views yet
Chinese style (kiếm hiệp cổ trang, kiểu vậy :v)1from transformers import MT5Tokenizer, AutoModelForSeq2SeqLM
2
3tokenizer = MT5Tokenizer.from_pretrained("ntphiep/viT5_tst_chinese")
4model = AutoModelForSeq2SeqLM.from_pretrained("ntphiep/viT5_tst_chinese")
5
6def predict(text):
7 inputs = tokenizer(text, return_tensors="pt", padding='longest', max_length=64)
8 input_ids = inputs.input_ids
9 attention_mask = inputs.attention_mask
10 output = model.generate(input_ids, attention_mask=attention_mask, max_length=64)
11 return tokenizer.decode(output[0], skip_special_tokens=True)
12
13
14text = "Hội đồng Hy Lạp tại Eo Corinth , với ngoại lệ Sparta , bầu ông lên như là Tổng tư lệnh chống lại quân Ba Tư , mà trước đây chức danh này được phong tặng cho cha ông ."
15result = predict(text)
16print("👉 Output:", result)👉 Output: Chư vị Hy Lạp tại địa phận Eo Corinth, ngoại trừ Sparta, đồng lòng suy tôn ngài lên vị trí Thống soái, dẫn dắt quân binh chinh phạt Ba Tư, tước vị cao quý này xưa kia thuộc về lệnh tôn.