Fine-tuned ViT5 model for Vietnamese text summarization.
This model is a fine-tuned version of ViT5 on Vietnamese summarization dataset. Unified extractive/abstractive summaries from Vietnamese documents.
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3model_name = "thnhan3/sft_model"
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to("cuda")
6
7document = """
8Ngày 16 tháng 11 năm 2025, Chính phủ Việt Nam công bố kế hoạch phát triển kinh tế số
9trong giai đoạn 2025-2030. Kế hoạch tập trung vào 3 trọng tâm chính: phát triển hạ tầng
10số, đào tạo nguồn nhân lực công nghệ cao, và thúc đẩy chuyển đổi số doanh nghiệp.
11Mục tiêu đặt ra là đến năm 2030, kinh tế số chiếm 30% GDP và tạo ra 2 triệu việc làm mới.
12"""
13
14inputs = tokenizer(
15 document,
16 max_length=1280,
17 truncation=True,
18 return_tensors="pt"
19).to("cuda")
20
21outputs = model.generate(
22 inputs.input_ids,
23 max_new_tokens=256,
24 num_beams=4,
25 length_penalty=1.0,
26 early_stopping=True,
27 no_repeat_ngram_size=3
28)
29
30summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
31print(summary)
1import torch
2
3documents = [
4 "Văn bản 1...",
5 "Văn bản 2...",
6 "Văn bản 3...",
7]
8
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10model = model.to(device)
11
12inputs = tokenizer(
13 documents,
14 max_length=1280,
15 truncation=True,
16 padding=True,
17 return_tensors="pt"
18).to(device)
19
20outputs = model.generate(
21 inputs.input_ids,
22 attention_mask=inputs.attention_mask,
23 max_new_tokens=256,
24 num_beams=4,
25 length_penalty=1.0,
26 early_stopping=True,
27 no_repeat_ngram_size=3
28)
29
30summaries = tokenizer.batch_decode(outputs, skip_special_tokens=True)
31for i, summary in enumerate(summaries):
32 print(f"Summary {i+1}: {summary}")
1import torch
2
3device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
4model = model.to(device).half()
5
6with torch.inference_mode():
7 inputs = tokenizer(
8 document,
9 max_length=1280,
10 truncation=True,
11 return_tensors="pt"
12 ).to(device)
13
14 with torch.amp.autocast('cuda'):
15 outputs = model.generate(
16 inputs.input_ids,
17 max_new_tokens=256,
18 num_beams=4,
19 length_penalty=1.0,
20 early_stopping=True,
21 no_repeat_ngram_size=3
22 )
23
24 summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
1@misc{vit5-vietnamese-summarization,
2 author = {Tran Huu Nhan},
3 title = {ViT5 Vietnamese Summarization},
4 year = {2025},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/thnhan3/sft_model}}
7}