Views
No views yet
1from peft import PeftModel
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Load base model + LoRA adapter
5base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-0.6B", torch_dtype="auto", trust_remote_code=True)
6model = PeftModel.from_pretrained(base, "williyam/hallucination-detector-agent-qwen3-0.6b")
7tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-0.6B", trust_remote_code=True)
8
9messages = [
10 {"role": "system", "content": "You are a hallucination detector. Given SOURCE and PASSAGE, output JSON with action_type, hallucination_detected, hallucination_type, hallucinated_span, corrected_text, reasoning."},
11 {"role": "user", "content": "SOURCE: The Eiffel Tower is in Paris.\nPASSAGE: The Eiffel Tower is in London."}
12]
13text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
14inputs = tokenizer(text, return_tensors="pt").to(model.device)
15output = model.generate(**inputs, max_new_tokens=256)
16print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))| Base model | Qwen/Qwen3-0.6B |
| License | Apache 2.0 (ungated) |
| Method | GRPO (Group Relative Policy Optimization) |
| LoRA | rank=16, alpha=32 |
| Training | 3 epochs, lr=5e-6, beta=0.04, 2 generations/prompt |
| Task | Baseline | GRPO | Δ |
|---|---|---|---|
| Easy: Factual Error | 0.2000 | 0.8000 | +0.6000 |
| Medium: Entity+Factual | 0.2250 | 0.2250 | +0.0000 |
| Hard: Multi-type | 0.8333 | 0.8333 | +0.0000 |
| Average | 0.4194 | 0.6194 | +0.2000 |



1git clone https://github.com/your-username/hallucination-detector-gym
2cd hallucination-detector-gym
3cp .env.example .env # Add your HF_TOKEN and HF_USERNAME
4pip install -e .
5# Open training_hallucination_detector.ipynb and run all cells