Views
No views yet
VietAI/vit5-base for Vietnamese medical question answering tasks. The model uses an encoder-decoder architecture and is trained on a custom Vietnamese medical dataset with knowledge graph enhancement.| Metric | Score |
|---|---|
| BLEU | 46.71 |
| ROUGE-L | 46.01 |
| BERTScore-F1 | 90.00 |
1from transformers import T5ForConditionalGeneration, T5Tokenizer
2
3model_name = "your-username/your-model-name"
4model = T5ForConditionalGeneration.from_pretrained(model_name, trust_remote_code=True)
5tokenizer = T5Tokenizer.from_pretrained(model_name, trust_remote_code=True)
6
7# Prepare input
8question = "Triệu chứng của bệnh tiểu đường là gì?"
9context = "Bệnh tiểu đường là một bệnh mãn tính ảnh hưởng đến cách cơ thể chuyển hóa glucose..."
10
11# Format input for ViT5
12input_text = f"câu hỏi: {question} ngữ cảnh: {context}"
13
14# Tokenize
15inputs = tokenizer(input_text, max_length=512, truncation=True, return_tensors="pt")
16
17# Generate
18outputs = model.generate(
19 **inputs,
20 max_length=128,
21 num_beams=4,
22 early_stopping=True,
23 temperature=0.7,
24 repetition_penalty=1.2
25)
26
27# Decode
28answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
29print(answer)1from transformers import T5ForConditionalGeneration, T5Tokenizer
2from rank_bm25 import BM25Okapi
3
4# Load model
5model = T5ForConditionalGeneration.from_pretrained("your-username/your-model-name", trust_remote_code=True)
6tokenizer = T5Tokenizer.from_pretrained("your-username/your-model-name", trust_remote_code=True)
7
8# Retrieve context using BM25
9question = "Triệu chứng của bệnh tiểu đường là gì?"
10# ... BM25 retrieval code ...
11context = retrieved_context # Retrieved from your knowledge base
12
13# Generate answer
14input_text = f"câu hỏi: {question} ngữ cảnh: {context}"
15inputs = tokenizer(input_text, return_tensors="pt")
16outputs = model.generate(**inputs, max_length=128, num_beams=4)
17answer = tokenizer.decode(outputs[0], skip_special_tokens=True)câu hỏi: <question> ngữ cảnh: <context><question>: The medical question in Vietnamese<context>: Relevant context retrieved from knowledge base (optional but recommended)1@misc{your_username_your_model_name},
2 title={Vietnamese Medical Abstractive Question Answering Model},
3 author={Your Name},
4 year={2024},
5 publisher={Hugging Face},
6 howpublished={\url{https://huggingface.co/your-username/your-model-name}}
7}