Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("preechanon/mt5-base-thaisum-text-summarization")
5model = AutoModelForSeq2SeqLM.from_pretrained("preechanon/mt5-base-thaisum-text-summarization")
6new_input_string = "ข้อความที่ต้องการ"
7input_ = tokenizer(new_input_string, truncation=True, max_length=1024, return_tensors="pt")
8with torch.no_grad():
9 preds = model.generate(
10 input_['input_ids'].to('cpu'),
11 num_beams=15,
12 num_return_sequences=1,
13 no_repeat_ngram_size=1,
14 remove_invalid_values=True,
15 max_length=140,
16 )
17
18summary = tokenizer.decode(preds[0], skip_special_tokens=True)
19summaryปรีชานนท์ ชาติไทย และ สัจจวัจน์ ส่งเสริม. (2567),
การสรุปข้อความข่าวภาษาไทยด้วยโครงข่ายประสาทเทียม (Thai News Text Summarization Using Neural Network),
วิทยาศาสตรบัณฑิต (วทบ.):ขอนแก่น, มหาวิทยาลัยขอนแก่น