Downloads · 30 days
11
24% of all-time downloads
BJyotibrat/Llama-3.1-8B-Instruct-BotMed-v2
Llama-3.1-8B-Instruct-BotMed-v2 is a question answering model from BJyotibrat. Use it when the input is a question plus a passage. It is set up for transformers. The card lists the license as llama3.1.
BotMed-v2 is a fine-tuned version of Llama 3.1 8B Instruct, adapted for medical chatbot use cases using LoRA.
Downloads · 30 days
11
24% of all-time downloads
All-time downloads
46
Public
Parameters
8B
7.8 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors7.8 GB · 100%
How the weights are stored.
U87B · 87%
From the Hugging Face model README
BotMed-v2 is a fine-tuned version of Llama 3.1 8B Instruct, adapted for medical chatbot use cases using LoRA.
BotMed-v2 is a fine-tuned version of Meta's Llama 3.1 8B Instruct, specialized for medical chatbot and question-answering use cases. It was trained using LoRA (Low-Rank Adaptation) on the ruslanmv/ai-medical-chatbot dataset, with the base model loaded in 4-bit NF4 quantization to enable efficient fine-tuning on Kaggle GPUs.
The LoRA adapters (rank 16, alpha 32) target the attention and MLP projection layers (q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj), allowing the model to adapt to medical dialogue patterns while preserving the general instruction-following capabilities of the base Llama 3.1 model. Training was run for up to 3 epochs with early stopping based on evaluation loss, using a cosine learning rate schedule and the paged AdamW 8-bit optimizer.
BotMed-v2 is intended to support use cases such as retrieval-augmented generation (RAG) pipelines for medical knowledge bases, clinical communication training simulations, synthetic medical dialogue generation, and preliminary response drafting in human-in-the-loop healthcare workflows. It is not a certified diagnostic tool and should not be used as a substitute for professional medical advice.
Intended for medical chatbot / medical question-answering conversational use cases.
We envision several potential downstream uses for Llama-3.1-8B-Instruct-BotMed-v2 that extend beyond direct conversational question answering. These potential applications include:
(1) Retrieval-Augmented Generation (RAG) pipelines, serving as a domain-adapted generator integrated with verified medical knowledge bases,
(2) medical education and training, simulating doctor-patient interactions for clinical communication practice,
(3) synthetic data generation, creating synthetic dialogue datasets in conjunction with an evaluator model, and
(4) preliminary query drafting, acting as an assistive tool to generate initial responses for human-in-the-loop healthcare workflows.
(Note: This model is built with Llama and distributed under the Llama 3.1 Community License. Any downstream applications, derivative models, or software integrating this model must comply with Meta's Acceptable Use Policy and include the required "Built with Llama" attribution.)
We caution potential users of the model that Llama-3.1-8B-Instruct-BotMed-v2 is not a certified medical diagnostic tool, unlike verified clinical software. As such, it is completely unsafe and inappropriate for end-users that require actual medical advice, diagnosis, or treatment, for which a licensed human medical professional (such as a doctor or physician) would be the only appropriate resource.
Additionally, any use of this model must strictly adhere to the Llama 3.1 Acceptable Use Policy. Use cases that violate this policy, or commercial applications exceeding 700 million monthly active users without explicit permission from Meta, are strictly out of scope.
Users (both direct and downstream) should be made aware of the risks, biases, and limitations of the model. In particular:
Use the code below to get started with the model.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
model_id = "BJyotibrat/Llama-3.1-8B-Instruct-BotMed-v2" # full merged model (base + LoRA already merged)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=bnb_config,
device_map="auto",
dtype=torch.float16,
)
model.eval()
prompts = [
"What are the symptoms of diabetes?",
"How can high blood pressure be managed?"
]
for idx, t in enumerate(prompts, start=1):
print(f"\nPrompt {idx}: {t}\n")
messages = [{"role": "user", "content": t}]
prompt = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(
prompt,
return_tensors="pt",
truncation=True,
max_length=2048
).to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
do_sample=True,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.2,
pad_token_id=tokenizer.eos_token_id
)
input_length = inputs["input_ids"].shape[1]
answer = tokenizer.decode(
outputs[0][input_length:],
skip_special_tokens=True,
clean_up_tokenization_spaces=False
).strip()
print(f"Answer {idx}: {answer}\n")
Fine-tuned on the ruslanmv/ai-medical-chatbot dataset. The dataset was split into train/test sets using a 95/5 split (test_size=0.05, seed=65).
Fine-tuned using LoRA (Low-Rank Adaptation) on Kaggle GPUs, with the base model loaded in 4-bit quantization via BitsAndBytes.
Quantization (BitsAndBytes):
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
model = AutoModelForCausalLM.from_pretrained(
base_model,
quantization_config=bnb_config,
device_map="auto",
attn_implementation=attn_implementation,
dtype=torch.float16,
)
model = prepare_model_for_kbit_training(model)
LoRA Configuration:
peft_config = LoraConfig(
r=16,
lora_alpha=32,
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM",
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
)
model = get_peft_model(model, peft_config)
model.print_trainable_parameters()
load_best_model_at_end=True, metric_for_best_model="eval_loss") — training was manually stopped after the 2nd epoch showed no further improvementsave_total_limit=3)training_arguments = SFTConfig(
output_dir=new_model,
per_device_train_batch_size=2,
per_device_eval_batch_size=2,
gradient_accumulation_steps=4,
optim="paged_adamw_8bit",
num_train_epochs=3, # 3 epochs max, early stopping will protect
eval_strategy="steps",
eval_steps=200,
save_strategy="steps",
save_steps=200,
logging_steps=50,
warmup_steps=36,
learning_rate=1e-4,
lr_scheduler_type="cosine",
fp16=False,
bf16=False,
report_to="wandb",
gradient_checkpointing=True,
load_best_model_at_end=True,
metric_for_best_model="eval_loss",
greater_is_better=False,
save_total_limit=3, # keep one checkpoint per epoch
)
Final Weights & Biases run summary (best checkpoint, selected on lowest eval_loss):
| Metric | Value |
|---|---|
| eval/loss | 2.01318 |
| eval/entropy | 1.92125 |
| eval/mean_token_accuracy | 0.56194 |
| eval/num_tokens | 3,259,218 |
| eval/runtime (s) | 302.3117 |
| eval/samples_per_second | 1.654 |
| eval/steps_per_second | 0.827 |
| train/entropy | 1.87502 |
| train/epoch | 1.34695 |
| total_flos | 1.7632157585149133e+17 |
Full step-by-step run history is available as a CSV export: wandb_run_history - BotMed v2.csv.
A held-out set of 100 medical questions, with model-generated answers compared against reference answers. The full question set, generated answers, and per-question scoring are available here: BotMed_v2_QA_Results.csv.
Evaluation was conducted on general open-domain medical Q&A prompts; no disaggregation by medical specialty, demographic, or question type was performed.
distilbert-base-uncased), capturing semantic alignment even when wording differs.| Metric | Score |
|---|---|
| F1 Score | 0.1142 |
| ROUGE-1 | 0.1834 |
| ROUGE-L | 0.1060 |
| Cosine Similarity | 0.5199 |
| BERTScore Precision | 0.7588 |
| BERTScore Recall | 0.7272 |
| BERTScore F1 | 0.7415 |
Full per-question predictions and scores (100 questions) are available in BotMed_v2_QA_Results.csv.
Lexical overlap metrics (F1, ROUGE) are low, indicating the model rarely reproduces the reference answers' exact wording. However, BERTScore and Cosine Similarity indicate moderate-to-strong semantic alignment, suggesting the model generally captures the intent and relevant medical concepts of the reference answers while phrasing them differently. This is consistent with the free-form, conversational nature of the training data.
Prompt 1: What are the symptoms of diabetes?
Answer 1: Symptoms include increased thirst and urination, blurring or double vision, fatigue, slow healing cuts/sores, etc. Also, if you have a family history of diabetes then it would be good to get yourself tested as well for early detection and treatment. You can also visit your doctor with these details so that he/she may advise accordingly.
Prompt 2: How can high blood pressure be managed?
Answer 2: High BP needs to be controlled by medications such as diuretics, calcium channel blockers like amlodipine or ACE inhibitors like enalapril. Lifestyle modification includes dietary restrictions, avoidance of salt in diet, regular exercise, etc.
(Note: raw model outputs include fabricated sign-offs such as doctor names and specialties)
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
Llama 3.1 8B Instruct architecture, fine-tuned via LoRA (rank 16, alpha 32) targeting the q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, and down_proj modules, for medical chatbot dialogue generation. Base model loaded in 4-bit NF4 quantization for training.
Kaggle GPUs
Kaggle GPU instance(s).
🤗 Transformers, PEFT (LoRA), TRL (SFTConfig/SFTTrainer), BitsAndBytes, Weights & Biases and Kaggle.
Bindupautra Jyotibrat (BJyotibrat)
Email: [email protected]