Welcome to the official Hugging Face repository for Health Chatbot, a conversational AI model fine-tuned to assist with health-related queries. This model is based on LLaMA 3.2, fine-tuned using QLoRA for lightweight and efficient training.
Health Chatbot is designed to provide accurate and conversational responses for general health advice and wellness information. The model is intended for educational purposes and is not a substitute for professional medical consultation.
Key Features:
You can load and use the model in your Python environment with the transformers library:
Make sure you have the necessary dependencies installed:
pip install transformers accelerate bitsandbytes
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("RayyanAhmed9477/Health-Chatbot")
model = AutoModelForCausalLM.from_pretrained(
"RayyanAhmed9477/Health-Chatbot",
device_map="auto",
load_in_8bit=True
)
# Generate a response
def chat(prompt):
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_length=150, do_sample=True, temperature=0.7)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
# Example usage
prompt = "What are some common symptoms of the flu?"
print(chat(prompt))
If you want to fine-tune the model further on a custom dataset, follow the steps below.
pip install datasets peft
Prepare your dataset in a JSON or CSV format with input and output fields:
Example Dataset (JSON):
[
{"input": "What are some symptoms of dehydration?", "output": "Symptoms include dry mouth, fatigue, and dizziness."},
{"input": "How can I boost my immune system?", "output": "Eat a balanced diet, exercise regularly, and get enough sleep."}
]
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import prepare_model_for_int8_training, LoraConfig, get_peft_model
from datasets import load_dataset
# Load the base model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("RayyanAhmed9477/Health-Chatbot")
model = AutoModelForCausalLM.from_pretrained(
"RayyanAhmed9477/Health-Chatbot",
device_map="auto",
load_in_8bit=True
)
# Prepare model for training
model = prepare_model_for_int8_training(model)
# Define LoRA configuration
lora_config = LoraConfig(
r=8,
lora_alpha=32,
target_modules=["q_proj", "v_proj"],
lora_dropout=0.1,
bias="none",
task_type="CAUSAL_LM"
)
model = get_peft_model(model, lora_config)
# Load your custom dataset
data = load_dataset("json", data_files="your_dataset.json")
# Fine-tune the model
from transformers import TrainingArguments, Trainer
training_args = TrainingArguments(
output_dir="./results",
per_device_train_batch_size=4,
num_train_epochs=3,
logging_dir="./logs",
save_strategy="epoch",
evaluation_strategy="epoch",
learning_rate=1e-4,
fp16=True
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=data["train"]
)
trainer.train()
# Save the fine-tuned model
model.save_pretrained("./fine_tuned_health_chatbot")
tokenizer.save_pretrained("./fine_tuned_health_chatbot")
Evaluate the model's performance using metrics like perplexity and BLEU:
from datasets import load_metric
# Load evaluation dataset
eval_data = load_dataset("json", data_files="evaluation_dataset.json")
# Evaluate with perplexity
def compute_perplexity(model, dataset):
metric = load_metric("perplexity")
results = metric.compute(model=model, dataset=dataset)
return results
print(compute_perplexity(model, eval_data["test"]))
Contributions are welcome! If you have suggestions, improvements, or issues to report, please create a pull request or an issue in this repository.
This model is released under the Apache 2.0 License.
For any queries or collaborations, reach out to me via GitHub or email at [email protected], LinkedIn .
Special thanks to the Hugging Face and Meta AI teams for their open-source contributions to the NLP and machine learning community.
results/checkpoint-1405/optimizer.pt 111 MiBresults/checkpoint-2106/optimizer.pt 111 MiBresults/checkpoint-702/optimizer.pt 111 MiBmodel.safetensors 55 MiBresults/checkpoint-1405/adapter_model.safetensors 55 MiBresults/checkpoint-2106/adapter_model.safetensors 55 MiBresults/checkpoint-702/adapter_model.safetensors 55 MiBresults/checkpoint-1405/rng_state.pth 13.9 KiBresults/checkpoint-2106/rng_state.pth 13.9 KiBresults/checkpoint-702/rng_state.pth 13.9 KiBresults/checkpoint-1405/training_args.bin 5.2 KiBresults/checkpoint-2106/training_args.bin 5.2 KiBresults/checkpoint-702/training_args.bin 5.2 KiBresults/checkpoint-1405/scheduler.pt 1 KiBresults/checkpoint-2106/scheduler.pt 1 KiBresults/checkpoint-702/scheduler.pt 1 KiB