A fine-tuned Gemma 3n model for document-grounded question answering that eliminates hallucination and knows when to say "I don't know."
Metric
This Model
Baseline
Improvement
Exact Match
83.2%
22.0%
+61.2 pts
Token F1
90.0%
34.8%
+55.2 pts
Abstention F1
98.9%
~0%
+98.9 pts
TL;DR
This model answers questions only from provided context. When the answer isn't there, it says NOT FOUND IN DOCUMENTS instead of making things up.
The problem it solves: The baseline Gemma 3n hallucinates answers not in the context. Ask "Who is the president of France?" with context about the Eiffel Tower, and baseline confidently says "Emmanuel Macron" - information it made up. This fine-tuned version correctly responds "NOT FOUND IN DOCUMENTS."
1import requests
23defask_document(question:str, context:str)->str:4 prompt =f"""You are a helpful assistant that answers questions based on provided context.
5If the answer is not found in the context, respond with "NOT FOUND IN DOCUMENTS".
67Question: {question}89Context:
10{context}"""1112 response = requests.post(13"http://localhost:11434/api/generate",14 json={15"model":"gemma3n-qa-v4-fixed",16"prompt": prompt,17"stream":False18}19)20return response.json()["response"]2122# Example23answer = ask_document(24 question="When was the Eiffel Tower built?",25 context="The Eiffel Tower was built from 1887 to 1889 by Gustave Eiffel."26)27print(answer)# Output: "from 1887 to 1889"
The Hallucination Problem (Why This Model Exists)
Baseline Behavior (Bad)
Question: Who is the president of France?
Context: The Eiffel Tower is in Paris. It was built by Gustave Eiffel.
Baseline Response: "Emmanuel Macron" ← HALLUCINATED! Not in context!
Fine-tuned Behavior (Good)
Question: Who is the president of France?
Context: The Eiffel Tower is in Paris. It was built by Gustave Eiffel.
Fine-tuned Response: "NOT FOUND IN DOCUMENTS" ← Correct abstention!
This is critical for RAG applications where you need the model to be honest about what it doesn't know.
Prompt Format (Required)
The model requires this specific prompt format to work correctly:
You are a helpful assistant that answers questions based on provided context.
If the answer is not found in the context, respond with "NOT FOUND IN DOCUMENTS".
Question: {your question}
Context:
{your context}
Without the abstention instruction, the model may not properly refuse to answer questions outside the context.
Source: Synthetic generation from SimpleQA-Verified knowledge base
Generation: GPT-4o-mini
Cost: ~$15-20 USD
Critical Implementation Detail
The v4 success came from manual label masking - training only on model responses, not on the prompt. Previous versions (v1, v3) failed because this wasn't properly implemented.
How-To Guides
Use with llama.cpp
bash
1# Download2wget https://huggingface.co/adorosario/gemma3n-qa-v4-fixed/resolve/main/gemma3n-qa-v4-fixed-q4_k_m.gguf
34# Run5./llama-cli -m gemma3n-qa-v4-fixed-q4_k_m.gguf \6 -p "You are a helpful assistant...\n\nQuestion: ...\n\nContext:\n..."\7 --temp 0
Use in a RAG Pipeline
python
1from langchain.llms import Ollama
23llm = Ollama(model="gemma3n-qa-v4-fixed", temperature=0)45defrag_query(question:str, retrieved_docs:list)->str:6 context ="\n\n".join(retrieved_docs)7 prompt =f"""You are a helpful assistant that answers questions based on provided context.
8If the answer is not found in the context, respond with "NOT FOUND IN DOCUMENTS".
910Question: {question}1112Context:
13{context}"""14return llm.invoke(prompt)
Use with AnythingLLM
Import the GGUF into Ollama (see Quick Start)
In AnythingLLM, select gemma3n-qa-v4-fixed as the model
Set system prompt to include the abstention instruction
Set temperature to 0
Limitations
What This Model Does Well
Extracting answers from provided context
Knowing when to abstain ("NOT FOUND IN DOCUMENTS")
Running on CPU-only hardware
Fast inference (4-6 seconds on CPU)
What This Model Does NOT Do
Generate answers beyond the context (by design)
Multi-hop reasoning requiring external knowledge
Non-English languages (trained on English only)
Long contexts beyond 4096 tokens
Multi-turn conversation (single-turn QA only)
Known Issues
Requires specific prompt format for abstention
~2% quality loss from Q4_K_M quantization
May struggle with heavily paraphrased answers
Files
File
Size
Description
gemma3n-qa-v4-fixed-q4_k_m.gguf
7.68 GB
Main model (Q4_K_M quantization)
Citation
bibtex
1@misc{gemma3n-qa-v4-fixed-2025,
2 author = {Do Rosario, Alden},
3 title = {gemma3n-qa-v4-fixed: Fine-tuned Gemma 3n for Document-Grounded QA with Abstention},
4 year = {2025},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/adorosario/gemma3n-qa-v4-fixed},
7 note = {Fine-tuned for extractive QA with learned abstention behavior}
8}