File size: 2,647 Bytes
986fa9c 0314fc0 2d186e9 0314fc0 a2c1ca1 0314fc0 2d186e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
---
license: gpl-3.0
---
# TruthX: Alleviating Hallucinations by Editing Large Language Models in Truthful Space
> [Shaolei Zhang](https://zhangshaolei1998.github.io/), [Tian Yu](https://tianyu0313.github.io/), [Yang Feng](https://people.ucas.edu.cn/~yangfeng?language=en)*
Model for paper "[TruthX: Alleviating Hallucinations by Editing Large Language Models in Truthful Space](https://arxiv.org/pdf/2402.17811.pdf)".
**TruthX** is an inference-time method to elicit the truthfulness of LLMs by editing their internal representations in truthful space, thereby mitigating the hallucinations of LLMs. On the [TruthfulQA benchmark](https://paperswithcode.com/sota/question-answering-on-truthfulqa), TruthX yields an average **enhancement of 20% in truthfulness** across 13 advanced LLMs.
<div align="center">
<img src="./truthx_results.png" alt="img" width="100%" />
</div>
<p align="center">
TruthfulQA MC1 accuracy of TruthX across 13 advanced LLMs
</p>
This repo provides **Llama-2-7B-Chat-TruthX**, a Llama-2-7B-Chat model with baked-in TruthX model. You can directly download this baked-in model and use it like standard Llama, no additional operations are required.
## Quick Starts
Inference with Llama-2-7B-Chat-TruthX:
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
llama2chat_with_truthx = "ICTNLP/Llama-2-7b-chat-TruthX"
tokenizer = AutoTokenizer.from_pretrained(llama2chat_with_truthx, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(llama2chat_with_truthx, trust_remote_code=True,torch_dtype=torch.float16).cuda()
question = "What are the benefits of eating an apple a day?"
encoded_inputs = tokenizer(question, return_tensors="pt")["input_ids"]
outputs = model.generate(encoded_inputs.cuda())[0, encoded_inputs.shape[-1] :]
outputs_text = tokenizer.decode(outputs, skip_special_tokens=True).strip()
print(outputs_text)
```
Please refer to [GitHub repo](https://github.com/ictnlp/TruthX) and [our paper](https://arxiv.org/pdf/2402.17811.pdf) for more details.
## Licence
Model weights and the inference code are released under The GNU General Public License v3.0 (GPLv3)
## Citation
If this repository is useful for you, please cite as:
```
@misc{zhang2024truthx,
title={TruthX: Alleviating Hallucinations by Editing Large Language Models in Truthful Space},
author={Shaolei Zhang and Tian Yu and Yang Feng},
year={2024},
eprint={2402.17811},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2402.17811}
}
```
If you have any questions, feel free to contact `zhangshaolei20z@ict.ac.cn`.
|