masakhane/afrimmlu
Viewer • Updated • 10.9k • 1.71k • 12
How to use Dineochiloane/gemma-3-4b-isizulu-afrimmlu with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("google/gemma-3-4b-it")
model = PeftModel.from_pretrained(base_model, "Dineochiloane/gemma-3-4b-isizulu-afrimmlu")Fine-tuned Gemma-3-4b-it model for isiZulu AFRIMMLU multiple-choice question answering.
Answer the following multiple-choice question about [subject].
Question: [isiZulu question]
Choices:
A) [choice 1]
B) [choice 2]
C) [choice 3]
D) [choice 4]
Select the correct answer (A, B, C, or D) first before you explain. The first character in your answer should be your choice (A,B,C, or D):
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
# Load model
base_model = AutoModelForCausalLM.from_pretrained("google/gemma-3-4b-it")
tokenizer = AutoTokenizer.from_pretrained("google/gemma-3-4b-it")
model = PeftModel.from_pretrained(base_model, "Dineochiloane/gemma-3-4b-isizulu-afrimmlu")
# Format question
messages = [{
"role": "user",
"content": "Answer the following multiple-choice question about elementary mathematics.\n\nQuestion: Lithini inani lika p ku 24 = 2p?\n\nChoices:\nA) p = 4\nB) p = 8\nC) p = 12\nD) p = 24\n\nSelect the correct answer (A, B, C, or D) first before you explain. The first character in your answer should be your choice (A,B,C, or D):"
}]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt")
outputs = model.generate(input_ids, max_new_tokens=100, temperature=0.0)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
This model was fine-tuned as part of research on cross-lingual transfer learning for African languages, specifically comparing zero-shot vs fine-tuned performance on isiZulu AFRIMMLU.