--- license: gpl-3.0 --- # TruthX: Alleviating Hallucinations by Editing Large Language Models in Truthful Space > [Shaolei Zhang](https://zhangshaolei1998.github.io/), Tian Yu, [Yang Feng](https://people.ucas.edu.cn/~yangfeng?language=en)* **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.
img

TruthfulQA MC1 accuracy of TruthX across 13 advanced LLMs

This repo provide **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 for more details.