tientien03 commited on
Commit
8b7bf53
1 Parent(s): 6c562db

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +139 -0
README.md ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ base_model: Viet-Mistral/Vistral-7B-Chat
4
+ language:
5
+ - vi
6
+ tags:
7
+ - LLMs
8
+ - Vietnamese
9
+ - Medical
10
+ - Health
11
+ - Vistral
12
+ - NLP
13
+ license: apache-2.0
14
+ datasets:
15
+ - hungnm/vietnamese-medical-qa
16
+ ---
17
+
18
+ ## Model Description
19
+
20
+ **viBioGPT-7B-instruct** is a Vietnamese Large Language Model (LLM) fine-tuned for the task of Question Answering within
21
+ the medical and healthcare domain. This model uses pre-trained [Vistral-Chat-7B](https://huggingface.co/Viet-Mistral/Vistral-7B-Chat), then QLora technique
22
+ to fine-tune.
23
+
24
+ Training dataset: [hungnm/vietnamese-medical-qa](https://huggingface.co/datasets/hungnm/vietnamese-medical-qa)
25
+
26
+ You can find source code: [Github](https://github.com/hungnm-ai/viBioGPT)
27
+
28
+ ## How to Use
29
+
30
+ Install libraries
31
+ ```shell
32
+ pip install peft==0.7.1 bitsandbytes==0.41.3.post2 transformers==4.36.2 torch==2.1.2
33
+
34
+ ```
35
+
36
+ Because this adapter uses pretrained [Viet-Mistral/Vistral-7B-Chat](https://huggingface.co/Viet-Mistral/Vistral-7B-Chat), ensure that you granted access to that model and set your huggingface token in code.
37
+
38
+ ```python
39
+ import torch
40
+ from peft import PeftModel
41
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
42
+
43
+ HF_TOKEN = "<your_hf_token>"
44
+ model_name = "Viet-Mistral/Vistral-7B-Chat"
45
+ adapter = "hungnm/viBioGPT-7B-instruct-qlora-adapter"
46
+
47
+ compute_dtype = getattr(torch, "bfloat16")
48
+ bnb_config = BitsAndBytesConfig(
49
+ load_in_4bit=True,
50
+ bnb_4bit_quant_type="nf4",
51
+ bnb_4bit_compute_dtype=compute_dtype,
52
+ bnb_4bit_use_double_quant=True,
53
+ )
54
+ model = AutoModelForCausalLM.from_pretrained(model_name,
55
+ quantization_config=bnb_config,
56
+ device_map={"": 0},
57
+ token=HF_TOKEN
58
+ )
59
+ model = PeftModel.from_pretrained(model, adapter)
60
+
61
+ # load and config tokenizer
62
+ tokenizer = AutoTokenizer.from_pretrained(model_name,
63
+ token=HF_TOKEN)
64
+ tokenizer.padding_side = "left"
65
+ tokenizer.pad_token_id = tokenizer.eos_token_id
66
+
67
+ system_prompt = ("Bạn là một trợ lý ảo AI trong lĩnh vực Y học, Sức Khỏe. Tên của bạn là AI-Doctor. "
68
+ "Nhiệm vụ của bạn là trả lời các thắc mắc hoặc các câu hỏi về Y học, Sức khỏe.")
69
+
70
+ question = "tôi có một ít nhân sâm nhưng đang bị viêm dạ dày. Vậy tôi có nên ăn nhân sâm ko?"
71
+ conversation = [
72
+ {
73
+ "role": "system",
74
+ "content": system_prompt},
75
+ {
76
+ "role": "user",
77
+ "content": question
78
+ }]
79
+ instruction_str = tokenizer.apply_chat_template(conversation=conversation,
80
+ tokenize=False)
81
+ token_ids = tokenizer([instruction_str], return_tensors="pt")["input_ids"]
82
+ token_ids = token_ids.to(model.device)
83
+ outputs = model.generate(input_ids=token_ids,
84
+ max_new_tokens=768,
85
+ do_sample=True,
86
+ temperature=0.1,
87
+ top_p=0.95,
88
+ top_k=40,
89
+ repetition_penalty=1.2)
90
+ all_token_ids = outputs[0].tolist()
91
+ output_token_ids = all_token_ids[token_ids.shape[-1]:]
92
+ output = tokenizer.decode(output_token_ids)
93
+
94
+ print(output)
95
+ ```
96
+
97
+ ```text
98
+ Chào anh!
99
+ Nhân sâm được biết đến như loại thảo dược quý hiếm và rất tốt cho sức khoẻ con người tuy nhiên không phải ai cũng dùng được nó đặc biệt với những bệnh nhân đau dạ dày thì càng cần thận trọng khi sử dụng vì nếu lạm dụng sẽ gây ra nhiều tác hại nghiêm trọng tới hệ tiêu hoá nói chung và tình trạng đau dạ dày nói riêng .
100
+ Vì vậy trước tiên anh hãy điều trị dứt điểm căn bênh này rồi mới nghĩ tới việc bổ sung thêm dinh dưỡng từ nhân sâm nhé !
101
+ Chúc anh mau khỏi bệnh ạ!
102
+
103
+ ```
104
+ ### Run on Google colab
105
+
106
+ [Notebook](https://colab.research.google.com/drive/1yo53qWNo6bsfBNjp0IgLORQG0Howx30o?usp=drive_link)
107
+
108
+ ### Disclaimer
109
+ Despite thorough testing, our model may still carry risks such as hallucination, toxic content, and bias. We urge users to recognize and address these risks before use. Users are responsible for compliance with regulations, and the authors disclaim liability for any resulting damages.**
110
+
111
+
112
+
113
+ ### Framework versions
114
+
115
+ ```shell
116
+ accelerate==0.21.0
117
+ sentencepiece==0.1.99
118
+ transformers==4.36.2
119
+ peft==0.7.1
120
+ bitsandbytes==0.41.3.post2
121
+ wandb==0.16.1
122
+ numpy==1.26.2
123
+ datasets==2.15.0
124
+ python-dotenv==1.0.1
125
+ flash-attn==2.5.3
126
+ ```
127
+
128
+ ## Citation
129
+
130
+ If you find our project helpful, please star our repo and cite our work. Thanks!
131
+
132
+ ```bibtex
133
+ @misc{viBioGPT,
134
+ title={Vietnamese Medical QA: Question Answering dataset for medical in Vietnamese},
135
+ author={Hung Nguyen},
136
+ howpublished={\url{https://github.com/hungnm-ai/viBioGPT}},
137
+ year={2024},
138
+ }
139
+ ```