Skip to main content

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.

inference_base.py runs the MaternaQA-es test set through an unmodified base model — no adapter is loaded. The generated predictions form the baseline used to measure the improvement gained from QLoRA fine-tuning. The output file is a JSONL of per-sample predictions that can be fed directly into evaluate_model_predictions.py for scoring.

Usage

python scripts/inference_base.py \
  --model-name google/gemma-4-E2B-it \
  --output-prefix outputs/gemma4-base/test
python scripts/inference_base.py \
  --model-name google/medgemma-1.5-4b-it \
  --output-prefix outputs/medgemma-base/test \
  --limit 10
The output file is written to <output-prefix>_predictions.jsonl. For example, --output-prefix outputs/gemma4-base/test produces outputs/gemma4-base/test_predictions.jsonl.

CLI Flags

FlagTypeDefaultDescription
--model-namestr(required)Hugging Face model ID or local path of the base model.
--model-classstrautoModel loading class. auto uses AutoModelForImageTextToText for Gemma 4/MedGemma and AutoModelForCausalLM for others. Choices: auto, causal-lm, image-text-to-text.
--dataset-rootPathdatasets/obstetrics/qa/publicationRoot folder containing the publication variant subdirectories.
--dataset-variantstrsft_groundedSFT variant to read the test split from. Choices: sft_closed_book, sft_grounded.
--output-prefixPath(required)Path prefix for the output file. The script appends _predictions.jsonl to produce the final filename.
--max-new-tokensint512Maximum number of new tokens the model may generate per prediction.
--temperaturefloat0.7Sampling temperature. Only applied when --do-sample is set.
--top-pfloat0.9Nucleus sampling probability threshold. Only applied when --do-sample is set.
--do-sampleflagFalseUse stochastic sampling. By default the script uses greedy decoding for reproducible evaluation.
--limitintNoneMaximum number of test examples to process. Useful for smoke tests.
--trust-remote-codeflagFalsePass trust_remote_code=True to model and tokenizer loaders.
--attn-implementationstrNoneOptional attention backend override: eager, sdpa, flash_attention_2, etc.
--load-in-4bitboolTrueLoad the base model in 4-bit NF4 quantization to keep inference memory-comparable to training and reduce VRAM usage.
--resumeboolTrueResume from an existing <output-prefix>_predictions.jsonl, skipping already-processed qa_ids. Use --no-resume to overwrite the file from scratch.

What It Does

  1. Loads the base model in 4-bit NF4 quantization (matching the training setup) using BitsAndBytesConfig with bnb_4bit_quant_type="nf4" and double quantization enabled. The model is loaded with device_map="auto" and placed in eval() mode.
  2. Reads the test split from <dataset-root>/<dataset-variant>/test.jsonl. The --dataset-variant flag controls whether the model receives source context (sft_grounded) or only the question (sft_closed_book).
  3. Builds a prompt for each example by extracting all messages up to (but not including) the last assistant turn, then applying the tokenizer’s chat template with add_generation_prompt=True.
  4. Generates a prediction using greedy decoding by default (set --do-sample for stochastic generation). The new tokens are decoded and stripped of special tokens.
  5. Writes results incrementally to the output JSONL file, flushing after every prediction so the run can be safely interrupted and resumed.

Output File

Each line in <output-prefix>_predictions.jsonl is a JSON object with the following fields:
FieldDescription
idqa_id from dataset metadata, or sequential index as fallback
model_roleAlways "base" for predictions from this script
model_nameThe value of --model-name
adapter_dirAlways null (no adapter loaded)
dataset_variantThe value of --dataset-variant
questionExtracted question text
generated_answerThe model’s generated prediction
reference_answerThe ground-truth answer from the test split
source_contextSource context from metadata.contexto_fuente
prompt_textThe full rendered prompt string sent to the model
metadataFull metadata dict from the original JSONL record
The repository includes pre-computed baseline predictions ready for evaluation. You can use them directly without re-running inference:
  • outputs/gemma4-base/test_predictions.jsonl
  • outputs/medgemma-base/test_predictions.jsonl

Next Step

Pipe the predictions file into evaluate_model_predictions.py to compute faithfulness, answer relevancy, answer correctness, and semantic similarity scores:
python scripts/evaluate_model_predictions.py \
  --input outputs/gemma4-base/test_predictions.jsonl \
  --output outputs/gemma4-base/test_eval.json

Build docs developers (and LLMs) love