To fine-tune Gemma-3 instruct models with a Hugging Face dataset in 'instruction', 'input', 'output' format, first convert your data to a single text field using a prompt template, then apply the Gemma-3 chat template. The recommended approach is:
- Use a formatting function to merge your fields into a prompt, e.g.:
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
EOS_TOKEN = tokenizer.eos_token
def formatting_prompts_func(examples):
instructions = examples["instruction"]
inputs = examples["input"]
outputs = examples["output"]
texts = []
for instruction, input, output in zip(instructions, inputs, outputs):
text = alpaca_prompt.format(instruction, input, output) + EOS_TOKEN
texts.append(text)
return { "text": texts }
- Map this function to your dataset, then use Unsloth's
get_chat_templatewithchat_template="gemma-3"for the tokenizer before training with SFTTrainer. See Kaggle-Gemma3_(4B).py and data formatting guide.
Would you like a full code example or more detail on applying the chat template?
Sources:
💡 **Hint:** Mention @RunLLM in the thread for followups.