Views
No views yet
| Field | Description |
|---|---|
| Base Model | Gemma-3 |
| Fine-tuning Framework | Unsloth |
| Task Type | Multiple-Choice Reading Comprehension |
| Dataset | RACE |
| Language | English |
| Reward Function | Custom GRPO (mc_reward_grpo) |
| License | Gemma License |
| Training Objective | Reinforcement Fine-tuning for reasoning clarity and correctness |
1import re, math
2LETTER_RE = re.compile(r'final(?:\s*answer)?\s*:\s*([A-D])', re.IGNORECASE)
3CONF_RE = re.compile(r'(\d{1,3})\s*%')
4
5CORRECT = 1.5
6INCORRECT = -1.0
7MALFORMED = -1.5
8
9def mc_reward_grpo(completions, answer=None, **kwargs):
10 penalty = float(kwargs.get("malformed_penalty", MALFORMED))
11 texts = [str(c.get("content", c)) if isinstance(c, dict) else str(c) for c in completions or []]
12 golds = [answer] if isinstance(answer, str) else list(answer or [None]*len(texts))
13 golds = (golds * math.ceil(len(texts) / len(golds)))[:len(texts)]
14
15 rewards = []
16 for txt, g in zip(texts, golds):
17 m = LETTER_RE.findall(txt or "")
18 conf_match = CONF_RE.search(txt)
19 confidence = float(conf_match.group(1)) / 100 if conf_match else 1.0
20 length = len(txt.split())
21
22 if not m:
23 reward = penalty * (0.5 if "final" in txt.lower() else 1)
24 else:
25 pred = m[-1].upper()
26 reward = CORRECT if g is None or pred == str(g).upper() else INCORRECT
27
28 clarity_bonus = max(0, 1 - length / 200)
29 reward = reward * confidence + 0.3 * clarity_bonus
30 rewards.append(round(reward, 3))
31
32 return rewards| Setting | Value |
|---|---|
| Optimizer | AdamW |
| Learning Rate | 5e-6 |
| Epochs | 1 |
| Reward Type | Scalar |
| Engine | Unsloth Reinforcement Fine-tuning |
| Hardware | 1xT4 16GB |

1prompt = """
2Passage: The fox saw the grapes hanging high and decided they were sour.
3Question: What does the phrase "sour grapes" mean?
4Choices:
5A. The fox liked the grapes.
6B. The fox couldn’t reach the grapes, so he pretended not to care.
7C. The grapes were actually sour.
8D. The fox wanted to share the grapes.
9
10Final answer:
11"""
12
13response = model.generate(prompt)
14print(response)The phrase "sour grapes" refers to pretending not to care about something you cannot have.
Final answer: B1@misc{gemma3_race_unsloth,
2 title = {Gemma-3 Fine-tuned on RACE with Unsloth and GRPO Reward},
3 author = {Samuel Lopera Torres},
4 year = {2025},
5 howpublished = {\url{https://huggingface.co/Senshi5620/gemma-3-finetune}},
6}
7