Instructions to use ICTNLP/Llama-2-7b-chat-TruthX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ICTNLP/Llama-2-7b-chat-TruthX with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ICTNLP/Llama-2-7b-chat-TruthX", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ICTNLP/Llama-2-7b-chat-TruthX", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("ICTNLP/Llama-2-7b-chat-TruthX", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use ICTNLP/Llama-2-7b-chat-TruthX with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ICTNLP/Llama-2-7b-chat-TruthX" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ICTNLP/Llama-2-7b-chat-TruthX", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ICTNLP/Llama-2-7b-chat-TruthX
- SGLang
How to use ICTNLP/Llama-2-7b-chat-TruthX with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ICTNLP/Llama-2-7b-chat-TruthX" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ICTNLP/Llama-2-7b-chat-TruthX", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ICTNLP/Llama-2-7b-chat-TruthX" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ICTNLP/Llama-2-7b-chat-TruthX", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ICTNLP/Llama-2-7b-chat-TruthX with Docker Model Runner:
docker model run hf.co/ICTNLP/Llama-2-7b-chat-TruthX
TruthX: Alleviating Hallucinations by Editing Large Language Models in Truthful Space
Model for paper "TruthX: Alleviating Hallucinations by Editing Large Language Models in Truthful Space".
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, TruthX yields an average enhancement of 20% in truthfulness across 13 advanced LLMs.
TruthfulQA MC1 accuracy of TruthX across 13 advanced LLMs
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:
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 and our paper 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.
- Downloads last month
- 798