File size: 4,753 Bytes
cb11b66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48884af
 
 
 
 
 
 
 
 
 
 
 
cb11b66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22afb78
 
 
 
 
 
 
 
 
 
 
 
 
 
cb11b66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
library_name: peft
base_model: ytu-ce-cosmos/Turkish-Gemma-9b-v0.1
tags:
  - qlora
  - medical-qa
  - turkish
  - gemma
  - lora
license: apache-2.0
language:
  - tr
datasets:
  - MedTurkQuAD
---

# Turkish-Gemma-9B Medical QA (QLoRA Adapter)

Parameter-efficient fine-tuned **LoRA adapter** for medical question answering in Turkish.

**+50 EM and +49 F1 improvement using QLoRA with only 1.05% trainable parameters.**

## Overview

This LoRA adapter demonstrates that a decoder-based large language model can be adapted via QLoRA to perform context-grounded medical question answering in Turkish. 

Rather than training multiple task-specific encoder models (e.g., NER or extractive QA), we explore whether a single generative model can approximate extractive behavior through structured prompt conditioning. 

The fine-tuned adapter improves Exact Match from 4.63% to 54.76% and F1 from 25.80% to 75.39% on the MedTurkQA validation set.

## Intended Use

This adapter is designed for context-grounded, single-turn medical question answering in Turkish. Given a passage and a question, the model generates a concise answer conditioned on the provided context. 

It expects inputs formatted with the structured Bağlam / Soru / Cevap prompt template described in the Usage section.

The model is intended for research, experimentation, and NLP benchmarking — particularly in the areas of parameter-efficient fine-tuning, Turkish NLP, and domain adaptation of large language models.

It is not intended for clinical decision-making, diagnostic support, or real-world medical deployment. 

Outputs should not be interpreted as medical advice and may contain inaccuracies, especially on topics outside the training distribution.


## Model Details

| Property | Value |
|---|---|
| Base model | [ytu-ce-cosmos/Turkish-Gemma-9b-v0.1](https://huggingface.co/ytu-ce-cosmos/Turkish-Gemma-9b-v0.1) |
| Method | QLoRA (4-bit NF4, double quantization) |
| Compute dtype | float16 |
| LoRA rank | 16 |
| LoRA alpha | 32 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Trainable parameters | 54M / 5.1B (1.05%) |
| Dataset | MedTurkQuAD |
| Epochs | 2 |
| Optimizer | paged_adamw_8bit |

## Evaluation Results

| Metric | Base Model | Fine-tuned (LoRA) | Delta |
|---|---|---|---|
| Exact Match (EM) | 4.63% | 54.76% | +50.12% |
| Token F1 | 25.80% | 75.39% | +49.58% |

Evaluated on 820 validation samples with greedy decoding.

## Usage

This repository contains only the LoRA adapter weights. Load the base model separately:

```python
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch

base_model_name = "ytu-ce-cosmos/Turkish-Gemma-9b-v0.1"
adapter_name = "Ahmetemintek/turkish-gemma-9b-medical-qlora"

tokenizer = AutoTokenizer.from_pretrained(adapter_name)

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_name,
    quantization_config=bnb_config,
    device_map="auto",
)

model = PeftModel.from_pretrained(model, adapter_name)
model.eval()

prompt = """Bağlam:
Verem, Mycobacterium tuberculosis adlı bakteri tarafından neden olunan bakteriyel ve bulaşıcı bir hastalıktır.

Soru:
Vereme ne neden olur?

Cevap:
"""

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128, do_sample=False)
answer = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(answer) # Output: "Mycobacterium tuberculosis"
```

## Prompt Format

```
Bağlam:
{context}

Soru:
{question}

Cevap:
```

## Limitations

-  The model was fine-tuned on ~6.5k QA samples and evaluated only on the MedTurkQA validation split; results may not generalize beyond similar medical text distributions.
-  The training setup uses a generative objective, which may produce paraphrased or slightly verbose answers rather than exact span extraction.
-  The model does not provide token-level offsets or guaranteed extractive spans.
-  This adapter is intended for research and experimentation, not clinical decision-making.

## Repository

Full training code, evaluation scripts, and notebooks are available at:

**[github.com/Ahmetemintek/gemma-finetuning](https://github.com/Ahmetemintek/gemma-finetuning)**

## Acknowledgements

This adapter is built on top of the base model ytu-ce-cosmos/Turkish-Gemma-9b-v0.1.
The model was fine-tuned on the MedTurkQA dataset.
The training approach follows the QLoRA method for parameter-efficient fine-tuning.