Views
No views yet

1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4llama2chat_with_truthx = "ICTNLP/Llama-2-7b-chat-TruthX"
5tokenizer = AutoTokenizer.from_pretrained(llama2chat_with_truthx, trust_remote_code=True)
6model = AutoModelForCausalLM.from_pretrained(llama2chat_with_truthx, trust_remote_code=True,torch_dtype=torch.float16).cuda()
7
8question = "What are the benefits of eating an apple a day?"
9encoded_inputs = tokenizer(question, return_tensors="pt")["input_ids"]
10outputs = model.generate(encoded_inputs.cuda())[0, encoded_inputs.shape[-1] :]
11outputs_text = tokenizer.decode(outputs, skip_special_tokens=True).strip()
12print(outputs_text)@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}
}zhangshaolei20z@ict.ac.cn.