Views
No views yet
1from transformers import T5Tokenizer, T5ForConditionalGeneration, T5Config
2
3model = T5ForConditionalGeneration.from_pretrained('SuperAI2-Machima/mt5-small-thai-qg-v2')
4tokenizer = T5Tokenizer.from_pretrained('SuperAI2-Machima/mt5-small-thai-qg-v2')
5
6source_text = 'บุกยึดไม้เถื่อน อดีต ส.ส.บุรีรัมย์ เตรียมสร้างคฤหาสน์ทรงไทย 1 กันยายน 2550 12:00 น. ตำรวจภูธรจ.บุรีรัมย์บุกตรวจยึดไม้แปรรูปหวงห้ามกว่า 80 แผ่น'
7
8print('Predicted Summary Text : ')
9tokenized_text = tokenizer.encode(source_text, return_tensors="pt").to(device)
10summary_ids = model.generate(tokenized_text,
11 num_beams=4,
12 no_repeat_ngram_size=2,
13 max_length=50,
14 early_stopping=True)
15output = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
16print(output)
17#Predicted Summary Text :
18#answer: 80 แผ่น question: ตํารวจภูธรจ.บุรีรัมย์บุกตรวจยึดไม้แปรรูปหวงห้ามกว่ากี่แผ่น