--- library_name: peft base_model: Viet-Mistral/Vistral-7B-Chat language: - vi tags: - LLMs - Vietnamese - Medical - Health - Vistral - NLP license: apache-2.0 datasets: - trungtienluong/child-care-3 --- ## Model Description **viBioGPT-7B-instruct** is a Vietnamese Large Language Model (LLM) fine-tuned for the task of Question Answering within the medical and healthcare domain. This model uses pre-trained [Vistral-Chat-7B](https://huggingface.co/Viet-Mistral/Vistral-7B-Chat), then QLora technique to fine-tune. Training dataset: [hungnm/vietnamese-medical-qa](https://huggingface.co/datasets/hungnm/vietnamese-medical-qa) You can find source code: [Github](https://github.com/hungnm-ai/viBioGPT) ## How to Use Install libraries ```shell pip install peft==0.7.1 bitsandbytes==0.41.3.post2 transformers==4.36.2 torch==2.1.2 ``` 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. ```python import torch from peft import PeftModel from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig HF_TOKEN = "" model_name = "Viet-Mistral/Vistral-7B-Chat" adapter = "hungnm/viBioGPT-7B-instruct-qlora-adapter" compute_dtype = getattr(torch, "bfloat16") bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=compute_dtype, bnb_4bit_use_double_quant=True, ) model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=bnb_config, device_map={"": 0}, token=HF_TOKEN ) model = PeftModel.from_pretrained(model, adapter) # load and config tokenizer tokenizer = AutoTokenizer.from_pretrained(model_name, token=HF_TOKEN) tokenizer.padding_side = "left" tokenizer.pad_token_id = tokenizer.eos_token_id 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. " "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.") 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?" conversation = [ { "role": "system", "content": system_prompt}, { "role": "user", "content": question }] instruction_str = tokenizer.apply_chat_template(conversation=conversation, tokenize=False) token_ids = tokenizer([instruction_str], return_tensors="pt")["input_ids"] token_ids = token_ids.to(model.device) outputs = model.generate(input_ids=token_ids, max_new_tokens=768, do_sample=True, temperature=0.1, top_p=0.95, top_k=40, repetition_penalty=1.2) all_token_ids = outputs[0].tolist() output_token_ids = all_token_ids[token_ids.shape[-1]:] output = tokenizer.decode(output_token_ids) print(output) ``` ```text Chào anh! 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 . 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é ! Chúc anh mau khỏi bệnh ạ! ``` ### Run on Google colab [Notebook](https://colab.research.google.com/drive/1yo53qWNo6bsfBNjp0IgLORQG0Howx30o?usp=drive_link) ### Disclaimer 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.** ### Framework versions ```shell accelerate==0.21.0 sentencepiece==0.1.99 transformers==4.36.2 peft==0.7.1 bitsandbytes==0.41.3.post2 wandb==0.16.1 numpy==1.26.2 datasets==2.15.0 python-dotenv==1.0.1 flash-attn==2.5.3 ``` ## Citation If you find our project helpful, please star our repo and cite our work. Thanks! ```bibtex @misc{viBioGPT, title={Vietnamese Medical QA: Question Answering dataset for medical in Vietnamese}, author={Hung Nguyen}, howpublished={\url{https://github.com/hungnm-ai/viBioGPT}}, year={2024}, } ```