CoolFace
Modelpublic

michelleAnogueira/biomistral-medquad-lora

sourceHugging Faceapache-2.0updated 19d agoView on Hugging Face
0likes86downloads
Model Card

πŸ₯ BioMistral-7B Fine-Tuned on MedQuAD

Model Description

This is a fine-tuned version of BioMistral-7B on the MedQuAD dataset (16,325 medical Q&A pairs) using QLoRA (4-bit quantization + LoRA adapters).

The model was fine-tuned as part of the Tech Challenge FIAP - Phase 3 (Final project for "AI for Developers" course) to build a medical assistant for Brazilian Portuguese healthcare professionals.

  • β€”Developed by: Michelle Almeida Nogueira Rodrigues (Flamers Team, FIAP)
  • β€”Funded by: Tech Challenge FIAP (academic project)
  • β€”Model type: Causal Language Model (decoder-only transformer)
  • β€”Language(s): English (training) + Portuguese (via translation layer)
  • β€”License: Apache 2.0 (inherited from BioMistral-7B)
  • β€”Finetuned from: BioMistral/BioMistral-7B

Model Sources

  • β€”Base model paper: BioMistral: A Collection of Biomedical Large Language Models (https://arxiv.org/abs/2402.10373)

Uses

Direct Use

This model is designed to answer medical questions in English in a structured, clinical format inspired by NIH MedQuAD. It can be used for:

  • β€”Medical Q&A systems
  • β€”Clinical decision support (with human validation)
  • β€”Educational tools for healthcare students
  • β€”Research on medical LLM fine-tuning

Downstream Use

This model is part of a larger medical assistant pipeline that includes:

  • β€”RAG (Retrieval-Augmented Generation) over 10k Brazilian drug labels (ChatBulΓ‘rio dataset)
  • β€”Translation layer (PT-BR ↔ EN using MarianMT)
  • β€”3-agent LangGraph (Triagem, SΓ­ntese, ValidaΓ§Γ£o)
  • β€”HITL (Human-in-the-Loop) mandatory validation
  • β€”Audit logging (SQLite)

Out-of-Scope Use

⚠️ This model is NOT a substitute for medical professionals. It is an academic prototype and should NEVER be used for:

  • β€”Direct patient diagnosis without physician oversight
  • β€”Prescription generation without pharmacist/doctor validation
  • β€”Emergency medical decisions
  • β€”Production medical software

Bias, Risks, and Limitations

  • β€”Training data limitations: MedQuAD is from NIH (USA), so it reflects American healthcare practices. Brazilian-specific protocols may differ.
  • β€”Hallucination risk: Like all LLMs, this model can generate plausible-sounding but factually incorrect medical information. Always validate with authoritative sources.
  • β€”Language bias: Trained primarily in English; PT-BR support requires additional translation layer.
  • β€”No factual verification: The model does not cite sources or verify claims against external databases (RAG is needed for that).
  • β€”Knowledge cutoff: BioMistral's pre-training data has a cutoff; new medical research may not be represented.

Recommendations

Users (both direct and downstream) must:

  1. 1.Always have a qualified medical professional review outputs before clinical use
  2. 2.Never rely on this model as sole source of medical information
  3. 3.Combine with up-to-date RAG over authoritative medical databases
  4. 4.Implement strict HITL validation in any production pipeline
  5. 5.Monitor for hallucinations and bias in real-world deployments

How to Get Started with the Model

Installation

bash
pip install torch transformers peft bitsandbytes accelerate

Loading the model

python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
    "BioMistral/BioMistral-7B",
    load_in_4bit=True,  # QLoRA: 4-bit quantization
    device_map="auto",
)

# Load LoRA adapter (THIS REPO)
model = PeftModel.from_pretrained(base_model, "michelleAnogueira/biomistral-medquad-lora")

tokenizer = AutoTokenizer.from_pretrained("michelleAnogueira/biomistral-medquad-lora")

Inference example

python
# Alpaca-style prompt template
prompt = """Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
What are the symptoms of diabetes?

### Response:
"""

inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(
    **inputs,
    max_new_tokens=512,
    temperature=0.5,
    top_p=0.9,
    do_sample=True,
    repetition_penalty=1.3,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response.split("### Response:")[-1].strip())

Training Details

Training Data

  • β€”Dataset: MedQuAD (Medical Question Answering Dataset)
  • β€”Source: U.S. National Library of Medicine (NLM)
  • β€”Size: 16,407 β†’ 16,325 samples (after anonymization of PHI)
  • β€”Language: English
  • β€”Split: 90% train (14,692) / 5% val (816) / 5% test (817)

Training Procedure

Preprocessing
  1. 1.Anonymization: Regex-based removal of PHI (URLs, phones, emails, CPFs, SSNs) - 367 substitutions
  2. 2.Normalization: UTF-8 NFC encoding, whitespace collapse, truncation at 2,500 chars
  3. 3.Split: 90/5/5 with seed=42 for reproducibility
  4. 4.Format: Alpaca-style prompts (### Instruction:, ### Response:)
Training Hyperparameters
HyperparameterValueJustification
MethodQLoRA (4-bit) + UnslothFits in 40GB A100 GPU
LoRA rank (r)16Balance between capacity and overfitting
LoRA alpha32Convention: alpha = 2 Γ— rank
LoRA dropout0.05Light regularization
Target modulesq, k, v, o, gate, up, downAll linear layers
Learning rate2e-4Standard for LoRA (QLoRA paper)
LR schedulercosineSmooth decay
Warmup steps50Stable training start
Optimizeradamw_8bitMemory-efficient
Epochs2Sweet spot for 14k samples
Batch size2 (per device)VRAM limit
Gradient accumulation4Effective batch = 8
Max sequence length4096Fits longest MedQuAD samples
Hardware & Time
  • β€”GPU: NVIDIA A100-SXM4-40GB (Google Colab Pro)
  • β€”VRAM usage: ~28 GB / 40 GB
  • β€”Training time: ~3.5 hours (2 epochs)
  • β€”Peak memory: ~28 GB GPU

Evaluation

Testing Data

  • β€”Validation set: 816 samples from MedQuAD (model never saw during training)
  • β€”Test set: 817 samples (also held out)

Metrics

MetricValueInterpretation
Training Loss (final)~0.50Model adapted to format
Validation Loss0.5864Good generalization
Validation Perplexity2.18Excellent (hesitates between ~2 words)
Base Model Perplexity (val)4.31Baseline reference
Perplexity Reduction49.4%Fine-tuning cut hesitation in half
Train-Val Gap1.47Γ—Small gap, no harmful overfitting

Generalization Tests

15 out-of-distribution tests performed:

  • β€”βœ… 5/5 general medical questions (lung cancer, MS, heart disease, etc.)
  • β€”βœ… 5/5 modern diseases (COVID-19, mRNA vaccines, dengue, monkeypox, Zika) - model correctly answered about diseases never seen in training
  • β€”βš οΈ 2/5 edge cases (empty input, gibberish) showed expected hallucinations

Conclusion: No harmful overfitting. The model maintains general medical knowledge while adopting the MedQuAD response style.

Environmental Impact

  • β€”Hardware Type: NVIDIA A100-SXM4-40GB
  • β€”Hours used: ~3.5 hours (training only, not counting evaluation/inference)
  • β€”Cloud Provider: Google Colab Pro
  • β€”Compute Region: us-east (estimated)
  • β€”Carbon Emitted: Estimated ~0.4 kg COβ‚‚eq (based on A100 ~250W Γ— 3.5h Γ— ~0.4 kg COβ‚‚/kWh)

Technical Specifications

Model Architecture

  • β€”Architecture: Transformer decoder (Mistral-7B base)
  • β€”Parameters: 7.24 billion (base) + ~40 million trainable (LoRA)
  • β€”Context length: 4096 tokens
  • β€”Tokenizer: SentencePiece (vocab=32,000)

Compute Infrastructure

  • β€”Framework: PyTorch 2.1.0 + CUDA 12.1
  • β€”Libraries: transformers 4.44.0, peft 0.10.0, bitsandbytes 0.43.3, unsloth
  • β€”Quantization: 4-bit (NF4) with double quantization

Citation

BibTeX

bibtex
@misc{biomistral-medquad-2026,
  author = {Michelle Almeida Nogueira Rodrigues},
  title = {BioMistral-7B Fine-Tuned on MedQuAD for Medical Question Answering},
  year = {2026},
  publisher = {HuggingFace},
  howpublished = {\\url{https://huggingface.co/michelleAnogueira/biomistral-medquad-lora}},
  note = {Tech Challenge FIAP - Phase 3}
}

APA

Nogueira Rodrigues, M. A. (2026). BioMistral-7B Fine-Tuned on MedQuAD for Medical Question Answering. HuggingFace. https://huggingface.co/michelleAnogueira/biomistral-medquad-lora

Model Card Authors

Michelle Almeida Nogueira Rodrigues

Model Card Contact

michellinha_an@hotmail.com (via GitHub: @MichelleANogueira)

Framework versions

  • β€”PEFT 0.20.0
  • β€”Transformers 4.44.0
  • β€”PyTorch 2.1.0+cu121
  • β€”Bitsandbytes 0.43.3
  • β€”Unsloth (latest)

Disclaimer: This is an academic project. The model is provided "as-is" without warranty. Not for production medical use without extensive validation, regulatory approval, and ongoing human oversight.