This guide walks you through everything you need to start working with MaternaQA-es from scratch. You will clone the repository, set up a Python virtual environment, install all required dependencies, load a dataset split in Python, and validate that the full fine-tuning pipeline is functional by running a lightweight smoke test — all in under 10 minutes.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/NicolasHoyosDevss/MaternaQA-es/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, ensure your environment meets the following requirements:
- Python 3.11+ — the project is developed and tested against Python 3.11.
- NVIDIA GPU with ≥ 16 GB VRAM — required for QLoRA fine-tuning. Dataset loading and exploration work on CPU without a GPU.
OPENAI_API_KEY— only needed if you intend to regenerate Q&A pairs from corpus chunks usinggenerate_synthetic_qa.py. Dataset loading and fine-tuning do not require it.HF_TOKEN— a Hugging Face account with an active token, and accepted gated model terms for both Gemma 4 and MedGemma on huggingface.co. Required to download model weights for fine-tuning.
Installation
Create and activate a virtual environment
Create an isolated Python environment to avoid dependency conflicts with other projects:
Install dependencies
Install all required packages — this covers PDF extraction, Q&A generation, Ragas evaluation, and the full fine-tuning stack (TRL, PEFT, QLoRA):Key packages installed include
datasets, transformers, trl, peft, bitsandbytes, ragas, openai, and pymupdf.Load a dataset variant
The published dataset ships in three variants. Load the recommendedsft_grounded variant — which pairs a clinical context chunk with each question — using the datasets library:
Smoke test fine-tuning
Before launching a full multi-hour training run, validate your setup end-to-end with a smoke test. The smoke test runs for only 10 steps with 64 training examples and 32 evaluation examples, completes in approximately 3 minutes, and confirms that model loading, QLoRA adapter initialization, training loop, and checkpoint saving all work correctly on your hardware.The smoke test trains for 10 steps with 64 train examples and 32 eval examples. It typically completes in ~3 minutes on a 16 GB GPU and validates the full load → train → save flow without committing to a full dataset run.The training script loads the model in 4-bit quantization, trains LoRA adapters (r=16) over all linear layers, and saves only the adapter weights to
output-dir/ — the base model is never modified.If MedGemma fails with an architecture error, add --model-class causal-lm to the command. Run python scripts/train_qlora_trl.py --help to see all available hyperparameter flags.What’s next
Dataset Variants
Compare
sft_grounded, sft_closed_book, and qa_flat_jsonl in detail — schema, fields, and recommended use cases for each format.Full Fine-tuning Guide
Run a complete QLoRA training job over all 5,093 training pairs with Gemma 4 or MedGemma, including hyperparameter guidance.
Pipeline Overview
Understand the full 8-step construction pipeline, from PDF curation through synthetic Q&A generation and Ragas evaluation.
Dataset Quality
Review Ragas faithfulness and relevance scores, grounding overlap metrics, and audit procedures used during dataset construction.
