初始化项目,由ModelHub XC社区提供模型
Model: varunchundru/dpo-qwen2.5-0.5b-halueval Source: Original Platform
This commit is contained in:
36
.gitattributes
vendored
Normal file
36
.gitattributes
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||
209
README.md
Normal file
209
README.md
Normal file
@@ -0,0 +1,209 @@
|
||||
---
|
||||
license: apache-2.0
|
||||
base_model: Qwen/Qwen2.5-0.5B-Instruct
|
||||
language:
|
||||
- en
|
||||
tags:
|
||||
- hallucination-reduction
|
||||
- dpo
|
||||
- direct-preference-optimization
|
||||
- qwen2
|
||||
- halueval
|
||||
- nlp
|
||||
- trl
|
||||
pipeline_tag: text-generation
|
||||
datasets:
|
||||
- pminervini/HaluEval
|
||||
---
|
||||
|
||||
# dpo-qwen2.5-0.5b-halueval
|
||||
|
||||
A **Direct Preference Optimization (DPO)** fine-tune of [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) trained to reduce hallucination across grounded QA, dialogue, and summarization tasks. Fine-tuned on preference pairs derived from all three subtasks of the [HaluEval](https://huggingface.co/datasets/pminervini/HaluEval) benchmark.
|
||||
|
||||
This model is the **mitigation component** of a complete hallucination detection + mitigation pipeline built for CS 593 NLP (Purdue University Fort Wayne, Spring 2026). Hallucination rates are measured by passing model generations through a separately fine-tuned DeBERTa detector: [`varunchundru/hallucination-detector-deberta`](https://huggingface.co/varunchundru/hallucination-detector-deberta).
|
||||
|
||||
---
|
||||
|
||||
## Model Details
|
||||
|
||||
| Field | Value |
|
||||
|---|---|
|
||||
| **Base model** | `Qwen/Qwen2.5-0.5B-Instruct` |
|
||||
| **Fine-tuning method** | Direct Preference Optimization (DPO) via TRL |
|
||||
| **Training tasks** | QA, Dialogue, Summarization (HaluEval) |
|
||||
| **Data split** | 70 / 15 / 15 stratified by task |
|
||||
| **Train pairs** | 21,000 (7,000 per task) |
|
||||
| **Test samples** | 4,500 (1,500 per task) |
|
||||
| **Model size** | 0.5B parameters |
|
||||
| **Hardware** | 1× NVIDIA A100 |
|
||||
| **Framework** | Hugging Face Transformers + TRL |
|
||||
|
||||
---
|
||||
|
||||
## Training Details
|
||||
|
||||
### Preference Pair Construction
|
||||
|
||||
Each HaluEval example was converted into a DPO triplet using task-specific formatting:
|
||||
|
||||
| Task | Prompt | Chosen | Rejected |
|
||||
|---|---|---|---|
|
||||
| **QA** | System + knowledge + question | `right_answer` | `hallucinated_answer` |
|
||||
| **Dialogue** | System + knowledge + dialogue history | `right_response` | `hallucinated_response` |
|
||||
| **Summarization** | System + document | `right_summary` | `hallucinated_summary` |
|
||||
|
||||
**System prompt (QA / Dialogue):**
|
||||
```
|
||||
You are a helpful assistant. Answer based only on the provided knowledge.
|
||||
Do not invent facts. Be concise.
|
||||
```
|
||||
|
||||
**System prompt (Summarization):**
|
||||
```
|
||||
Summarize the following document accurately.
|
||||
Do not add information not present in the document.
|
||||
```
|
||||
|
||||
### Hyperparameters
|
||||
|
||||
| Parameter | Value |
|
||||
|---|---|
|
||||
| Epochs | 1 |
|
||||
| Learning rate | 5e-6 |
|
||||
| DPO beta (KL penalty) | 0.1 |
|
||||
| Batch size (train / eval) | 16 |
|
||||
| Gradient accumulation steps | 1 |
|
||||
| Max sequence length | 512 |
|
||||
| Precision | bf16 |
|
||||
| Best model selection | Lowest eval loss |
|
||||
| Optimizer | AdamW (default TRL) |
|
||||
|
||||
---
|
||||
|
||||
## Evaluation
|
||||
|
||||
Hallucination rates are measured on the held-out 15% test split (4,500 examples, 1,500 per task) by passing each model's generation through [`varunchundru/hallucination-detector-deberta`](https://huggingface.co/varunchundru/hallucination-detector-deberta) at a 0.5 probability threshold.
|
||||
|
||||
### Overall Results
|
||||
|
||||
| Model | Hallucination Rate | Mean Hall. Prob |
|
||||
|---|---|---|
|
||||
| Qwen2.5-0.5B-Instruct (base) | 85.5% | 0.816 |
|
||||
| **dpo-qwen2.5-0.5b-halueval (this model)** | **37.7%** | **0.293** |
|
||||
| Absolute reduction | −47.7 pp | −0.523 |
|
||||
| **Relative reduction** | **−55.9%** | |
|
||||
|
||||
### Per-Task Breakdown
|
||||
|
||||
| Task | Base Rate | DPO Rate | Relative Reduction |
|
||||
|---|---|---|---|
|
||||
| QA | 93.4% | 19.0% | **−79.7%** |
|
||||
| Summarization | 63.2% | 0.0% | **−100.0%** |
|
||||
| Dialogue | 99.8% | 94.2% | −5.6% |
|
||||
|
||||
**Notable findings:**
|
||||
- **QA** sees the largest absolute improvement — the structured knowledge + question format aligns well with DPO training signal.
|
||||
- **Summarization** hallucination is effectively eliminated on the test set (0.0% rate), likely because the DPO training directly contrasts faithful vs. hallucinated summaries on similar documents.
|
||||
- **Dialogue** shows minimal improvement (−5.6%). The model still hallucinates in 94.2% of dialogue turns, suggesting that multi-turn conversation is a harder distribution to shift with preference learning at this scale.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
```python
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
import torch
|
||||
|
||||
model_id = "varunchundru/dpo-qwen2.5-0.5b-halueval"
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
model_id,
|
||||
torch_dtype=torch.bfloat16,
|
||||
device_map="auto",
|
||||
)
|
||||
model.eval()
|
||||
|
||||
|
||||
def answer_grounded(question: str, knowledge: str, max_new_tokens: int = 150) -> str:
|
||||
messages = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": (
|
||||
"You are a helpful assistant. Answer based only on the provided knowledge. "
|
||||
"Do not invent facts. Be concise."
|
||||
),
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"Knowledge: {knowledge}\n\nQuestion: {question}",
|
||||
},
|
||||
]
|
||||
text = tokenizer.apply_chat_template(
|
||||
messages, tokenize=False, add_generation_prompt=True
|
||||
)
|
||||
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
||||
with torch.no_grad():
|
||||
output = model.generate(
|
||||
**inputs,
|
||||
max_new_tokens=max_new_tokens,
|
||||
do_sample=False,
|
||||
pad_token_id=tokenizer.pad_token_id,
|
||||
eos_token_id=tokenizer.eos_token_id,
|
||||
)
|
||||
response = tokenizer.decode(
|
||||
output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True
|
||||
)
|
||||
return response.strip()
|
||||
|
||||
|
||||
# Example
|
||||
knowledge = "The Eiffel Tower is located in Paris, France, and was completed in 1889."
|
||||
question = "Where is the Eiffel Tower located and when was it finished?"
|
||||
print(answer_grounded(question, knowledge))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Intended Use & Limitations
|
||||
|
||||
**Intended use:**
|
||||
- Grounded question answering and document summarization where faithfulness to a context is required
|
||||
- Research on hallucination mitigation via preference learning
|
||||
- Mitigation component paired with [`varunchundru/hallucination-detector-deberta`](https://huggingface.co/varunchundru/hallucination-detector-deberta)
|
||||
|
||||
**Limitations:**
|
||||
- **Dialogue performance is weak** — DPO training did not meaningfully reduce hallucination for multi-turn dialogue (94.2% post-DPO rate). The dialogue task may require more training, a larger model, or task-specific preference data.
|
||||
- Trained for only 1 epoch on 0.5B parameters — further training or a larger base model would likely improve results.
|
||||
- Hallucination rates are measured by a proxy DeBERTa classifier, not human annotation.
|
||||
- `max_length=512` during DPO training may truncate long documents in the summarization task.
|
||||
- Should not be used in high-stakes domains without further validation.
|
||||
|
||||
---
|
||||
|
||||
## Project Context
|
||||
|
||||
This model is the mitigation component in a four-part hallucination pipeline:
|
||||
|
||||
1. **TF-IDF + Logistic Regression** — Lightweight lexical baseline
|
||||
2. **Zero-Shot DeBERTa-MNLI** — NLI-based detection without task-specific training (Acc=0.60, F1=0.43, AUROC=0.65)
|
||||
3. **Fine-Tuned DeBERTa-v3-base** — Task-specific hallucination detector (Acc=0.91, F1=0.91, AUROC=0.98)
|
||||
4. **DPO Fine-Tuned Qwen2.5-0.5B (this model)** — Reduces hallucination at generation time
|
||||
|
||||
**Authors:** Varun Chundru & Debasmita Biswas
|
||||
**Course:** CS 593 Natural Language Processing, Purdue University Fort Wayne, Spring 2026
|
||||
|
||||
---
|
||||
|
||||
## Citation
|
||||
|
||||
```bibtex
|
||||
@inproceedings{li2023halueval,
|
||||
title={HaluEval: A Large-Scale Hallucination Evaluation Benchmark for Large Language Models},
|
||||
author={Li, Junyi and Cheng, Xiaoxue and Zhao, Wayne Xin and Nie, Jian-Yun and Wen, Ji-Rong},
|
||||
booktitle={Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing},
|
||||
year={2023}
|
||||
}
|
||||
```
|
||||
54
chat_template.jinja
Normal file
54
chat_template.jinja
Normal file
@@ -0,0 +1,54 @@
|
||||
{%- if tools %}
|
||||
{{- '<|im_start|>system\n' }}
|
||||
{%- if messages[0]['role'] == 'system' %}
|
||||
{{- messages[0]['content'] }}
|
||||
{%- else %}
|
||||
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
|
||||
{%- endif %}
|
||||
{{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
||||
{%- for tool in tools %}
|
||||
{{- "\n" }}
|
||||
{{- tool | tojson }}
|
||||
{%- endfor %}
|
||||
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
||||
{%- else %}
|
||||
{%- if messages[0]['role'] == 'system' %}
|
||||
{{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
|
||||
{%- else %}
|
||||
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- for message in messages %}
|
||||
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
|
||||
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
||||
{%- elif message.role == "assistant" %}
|
||||
{{- '<|im_start|>' + message.role }}
|
||||
{%- if message.content %}
|
||||
{{- '\n' + message.content }}
|
||||
{%- endif %}
|
||||
{%- for tool_call in message.tool_calls %}
|
||||
{%- if tool_call.function is defined %}
|
||||
{%- set tool_call = tool_call.function %}
|
||||
{%- endif %}
|
||||
{{- '\n<tool_call>\n{"name": "' }}
|
||||
{{- tool_call.name }}
|
||||
{{- '", "arguments": ' }}
|
||||
{{- tool_call.arguments | tojson }}
|
||||
{{- '}\n</tool_call>' }}
|
||||
{%- endfor %}
|
||||
{{- '<|im_end|>\n' }}
|
||||
{%- elif message.role == "tool" %}
|
||||
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
|
||||
{{- '<|im_start|>user' }}
|
||||
{%- endif %}
|
||||
{{- '\n<tool_response>\n' }}
|
||||
{{- message.content }}
|
||||
{{- '\n</tool_response>' }}
|
||||
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
||||
{{- '<|im_end|>\n' }}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{%- if add_generation_prompt %}
|
||||
{{- '<|im_start|>assistant\n' }}
|
||||
{%- endif %}
|
||||
57
config.json
Normal file
57
config.json
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"architectures": [
|
||||
"Qwen2ForCausalLM"
|
||||
],
|
||||
"attention_dropout": 0.0,
|
||||
"bos_token_id": null,
|
||||
"dtype": "bfloat16",
|
||||
"eos_token_id": 151645,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 896,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 4864,
|
||||
"layer_types": [
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention",
|
||||
"full_attention"
|
||||
],
|
||||
"max_position_embeddings": 32768,
|
||||
"max_window_layers": 21,
|
||||
"model_type": "qwen2",
|
||||
"num_attention_heads": 14,
|
||||
"num_hidden_layers": 24,
|
||||
"num_key_value_heads": 2,
|
||||
"pad_token_id": 151643,
|
||||
"rms_norm_eps": 1e-06,
|
||||
"rope_parameters": {
|
||||
"rope_theta": 1000000.0,
|
||||
"rope_type": "default"
|
||||
},
|
||||
"sliding_window": null,
|
||||
"tie_word_embeddings": true,
|
||||
"transformers_version": "5.6.2",
|
||||
"use_cache": false,
|
||||
"use_sliding_window": false,
|
||||
"vocab_size": 151936
|
||||
}
|
||||
13
generation_config.json
Normal file
13
generation_config.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"do_sample": true,
|
||||
"eos_token_id": [
|
||||
151645,
|
||||
151643
|
||||
],
|
||||
"pad_token_id": 151643,
|
||||
"repetition_penalty": 1.1,
|
||||
"temperature": 0.7,
|
||||
"top_k": 20,
|
||||
"top_p": 0.8,
|
||||
"transformers_version": "5.6.2"
|
||||
}
|
||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:cbe723ab261778879e040cd2da94f2df9e80b42827d6e837f7b8ac1e4a81132d
|
||||
size 988097824
|
||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
|
||||
size 11421892
|
||||
30
tokenizer_config.json
Normal file
30
tokenizer_config.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"add_prefix_space": false,
|
||||
"backend": "tokenizers",
|
||||
"bos_token": null,
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "<|im_end|>",
|
||||
"errors": "replace",
|
||||
"extra_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<|object_ref_start|>",
|
||||
"<|object_ref_end|>",
|
||||
"<|box_start|>",
|
||||
"<|box_end|>",
|
||||
"<|quad_start|>",
|
||||
"<|quad_end|>",
|
||||
"<|vision_start|>",
|
||||
"<|vision_end|>",
|
||||
"<|vision_pad|>",
|
||||
"<|image_pad|>",
|
||||
"<|video_pad|>"
|
||||
],
|
||||
"is_local": true,
|
||||
"local_files_only": false,
|
||||
"model_max_length": 131072,
|
||||
"pad_token": "<|endoftext|>",
|
||||
"split_special_tokens": false,
|
||||
"tokenizer_class": "Qwen2Tokenizer",
|
||||
"unk_token": null
|
||||
}
|
||||
3
training_args.bin
Normal file
3
training_args.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:655e60f960ce1703236beca74f97756303c1d7f8544aa98961c9d470f6ba7a41
|
||||
size 5905
|
||||
Reference in New Issue
Block a user