GithubHelp home page GithubHelp logo

qiguanjie / icd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hillzhang1999/icd

1.0 0.0 0.0 14.67 MB

Code & Data for our Paper "Alleviating Hallucinations of Large Language Models through Induced Hallucinations"

Home Page: https://arxiv.org/abs/2312.15710

License: MIT License

Shell 0.14% C++ 0.04% Python 98.95% C 0.01% Cuda 0.39% Makefile 0.01% Jupyter Notebook 0.40% Cython 0.01% Dockerfile 0.04% Jsonnet 0.01%

icd's Introduction

Alleviating Hallucinations of Large Language Models through Induced Hallucinations

1Soochow University, Suzhou, China
2Tencent AI Lab

Version Stars Issues

image

Introduction

Despite their impressive capabilities, large language models (LLMs) have been observed to generate responses that include inaccurate or fabricated information, a phenomenon commonly known as ``hallucination''. In this work, we propose a simple Induce-then-Contrast Decoding (ICD) strategy to mitigate this issue. We first construct a factually weak LLM by inducing hallucinations from the original LLMs. Then, we penalize these induced hallucinations during decoding to enhance the factuality of the generated content. Concretely, we determine the final next-token predictions by amplifying the predictions from the original model and downplaying the induced untruthful predictions via contrastive decoding. Experimental results on both discrimination-based and generation-based hallucination evaluation benchmarks, such as TruthfulQA and FActScore, demonstrate that our proposed ICD methods can effectively enhance the factuality of LLMs across various model sizes and families. For example, when equipped with our approach, Llama2-7B-Chat and Mistral-7B-Instruct now can achieve performance comparable to ChatGPT and GPT4 on TruthfulQA, respectively.

On TruthfulQA, our ICD approach significantly improves the truthfulness of Llama2-7B-Chat (+8 MC1 score) and Mistral-7B-Instruct (+20 MC1 score). With these improvements, the enhanced Llama2-7B-Chat and Mistral-7B-Instruct now match the performance levels of ChatGPT and GPT4, respectively.

image

If you are interested in our work, please cite:

@article{zhang-etal-2023-ICD,
  title     = {Alleviating Hallucinations of Large Language Models through Induced Hallucinations},
  author    = {Zhang, Yue  and
               Cui, Leyang  and
               Wei, Bi and
               Shuming Shi},
  journal   = {arXiv preprint arXiv:2312.15710},
}

How to Install

You can use the following commands to install the environment for ICD:

conda create -n icd python==3.8
conda activate icd
pip install -r requirements.txt
cd ./transformers
pip install --editable ./

Run

Try the following command to test our method on TruthfulQA:

cd ./exp_scripts/benchmark
sh truthfulqa.sh

For experiments on Factscore, please try:

cd ./exp_scripts/benchmark
sh factscore.sh

For evaluation on Factscore, please kindly refer to their repo.

Contact

If you have any questions, please feel free to email me or drop me an issue.

icd's People

Contributors

hillzhang1999 avatar

Stargazers

亓官劼 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.