Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: vi
|
| 3 |
+
datasets:
|
| 4 |
+
- cc100
|
| 5 |
+
tags:
|
| 6 |
+
- summarization
|
| 7 |
+
|
| 8 |
+
license: mit
|
| 9 |
+
|
| 10 |
+
widget:
|
| 11 |
+
- text: "ViFortuneAI."
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# ViT5-Base Finetuned on `vietnews` Abstractive Summarization (No prefix needed)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
State-of-the-art pretrained Transformer-based encoder-decoder model for Vietnamese.
|
| 18 |
+
[](https://paperswithcode.com/sota/abstractive-text-summarization-on-vietnews?p=vit5-pretrained-text-to-text-transformer-for)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
## How to use
|
| 22 |
+
For more details, do check out [our Github repo](https://github.com/vietai/ViT5) and [eval script](https://github.com/vietai/ViT5/blob/main/eval/Eval_vietnews_sum.ipynb).
|
| 23 |
+
|
| 24 |
+
```python
|
| 25 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 26 |
+
|
| 27 |
+
# Load model và tokenizer
|
| 28 |
+
model_name = "ViFortune-AI/ViT5Summer"
|
| 29 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 30 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 31 |
+
model.cuda()
|
| 32 |
+
|
| 33 |
+
# DỮ LIỆU ĐẦU VÀO CỦA BẠN: nguyên văn hội thoại (giống trong dataset)
|
| 34 |
+
sentence = "Bạn đã thanh toán cho cà phê không?>> Hmm... tôi nghĩ không phải là vậy, nhưng nó cũng không sao, tôi sẽ thanh toán anh ta mai nhé."
|
| 35 |
+
|
| 36 |
+
# ✅ KHÔNG thêm "summarize:", KHÔNG thêm "</s>"
|
| 37 |
+
encoding = tokenizer(
|
| 38 |
+
sentence,
|
| 39 |
+
return_tensors="pt",
|
| 40 |
+
max_length=512,
|
| 41 |
+
truncation=True,
|
| 42 |
+
padding=False # hoặc "max_length" nếu muốn
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
input_ids = encoding["input_ids"].to("cuda")
|
| 46 |
+
attention_mask = encoding["attention_mask"].to("cuda")
|
| 47 |
+
|
| 48 |
+
# Generate
|
| 49 |
+
outputs = model.generate(
|
| 50 |
+
input_ids=input_ids,
|
| 51 |
+
attention_mask=attention_mask,
|
| 52 |
+
max_length=256,
|
| 53 |
+
min_length=10,
|
| 54 |
+
num_beams=4,
|
| 55 |
+
early_stopping=True,
|
| 56 |
+
no_repeat_ngram_size=2,
|
| 57 |
+
length_penalty=1.0
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Decode
|
| 61 |
+
for output in outputs:
|
| 62 |
+
summary = tokenizer.decode(output, skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
| 63 |
+
print("Tóm tắt:", summary)
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
## Citation
|
| 67 |
+
```
|
| 68 |
+
@inproceedings{phan-etal-2022-vit5,
|
| 69 |
+
title = "{V}i{T}5: Pretrained Text-to-Text Transformer for {V}ietnamese Language Generation",
|
| 70 |
+
author = "Phan, Long and Tran, Hieu and Nguyen, Hieu and Trinh, Trieu H.",
|
| 71 |
+
booktitle = "Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies: Student Research Workshop",
|
| 72 |
+
year = "2022",
|
| 73 |
+
publisher = "Association for Computational Linguistics",
|
| 74 |
+
url = "https://aclanthology.org/2022.naacl-srw.18",
|
| 75 |
+
pages = "136--142",
|
| 76 |
+
}
|
| 77 |
+
```
|