{"id":28676506,"url":"https://github.com/zjunlp/factchd","last_synced_at":"2025-06-13T23:04:58.930Z","repository":{"id":184474149,"uuid":"623752214","full_name":"zjunlp/FactCHD","owner":"zjunlp","description":"[IJCAI 2024] FactCHD: Benchmarking Fact-Conflicting Hallucination Detection","archived":false,"fork":false,"pushed_at":"2024-04-28T23:58:58.000Z","size":8829,"stargazers_count":87,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-07T20:34:15.885Z","etag":null,"topics":["benchmark","dataset","factchd","factual","hallucination","knowledge","large-language-models","natural-language-processing"],"latest_commit_sha":null,"homepage":"https://zjunlp.github.io/project/FactCHD","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zjunlp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-05T02:29:30.000Z","updated_at":"2025-04-01T06:05:17.000Z","dependencies_parsed_at":"2024-01-22T06:28:27.567Z","dependency_job_id":"7252ea8d-09b1-4f98-8042-6cfe9e0b9821","html_url":"https://github.com/zjunlp/FactCHD","commit_stats":null,"previous_names":["zjunlp/factcheckllm","zjunlp/factchd"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zjunlp/FactCHD","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FFactCHD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FFactCHD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FFactCHD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FFactCHD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zjunlp","download_url":"https://codeload.github.com/zjunlp/FactCHD/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FFactCHD/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259732772,"owners_count":22903087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","dataset","factchd","factual","hallucination","knowledge","large-language-models","natural-language-processing"],"created_at":"2025-06-13T23:04:58.319Z","updated_at":"2025-06-13T23:04:58.915Z","avatar_url":"https://github.com/zjunlp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FactCHD: Benchmarking Fact-Conflicting Hallucination Detection\n\n[![Pytorch](https://img.shields.io/badge/PyTorch-%23EE4C2C.svg?e\u0026logo=PyTorch\u0026logoColor=white)](https://pytorch.org/)![](https://img.shields.io/badge/version-1.0.1-blue) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/zjunlp/MolGen/blob/main/LICENSE)\n\n🔥  Code for the IJCAI 2024 paper \"[FactCHD: Benchmarking Fact-Conflicting Hallucination Detection](https://arxiv.org/abs/2310.12086)\".\n🔥  The whole dataset is available in [FactCHD_Dataset](https://drive.google.com/file/d/1dvc_PzTOfVAcdpfrGGbedaha_CSJ9p0w/view?usp=sharing) on Google Drive or [FactCHD_Dataset](https://huggingface.co/datasets/zjunlp/FactCHD) on Huggingface. \n\n\n# 🚀 Overview\nLarge Language Models (LLMs), such as ChatGPT/GPT-4, have garnered widespread attention owing to their myriad of practical applications, yet their adoption has been constrained by issues of fact-conflicting hallucinations across web platforms. The assessment of factuality in text, produced by LLMs, remains inadequately explored, extending not only to the judgment of vanilla facts but also encompassing the evaluation of factual errors emerging in complex inferential tasks like multi-hop, and etc. In response, we introduce FACTCHD, a fact-conflicting hallucination detection benchmark meticulously designed for LLMs. Functioning as a pivotal tool in evaluating factuality within `\"Query-Respons\"`  contexts, our benchmark assimilates a large-scale dataset, encapsulating a broad spectrum of factuality patterns, such as vanilla, multi-hops, comparison, and set-operation patterns. A distinctive feature of our benchmark\nis its incorporation of fact-based chains of evidence, thereby facilitating comprehensive and conducive factual reasoning throughout the assessment process. We evaluate multiple LLMs, demonstrating the effectiveness of the benchmark and current methods fall short of faithfully detecting factual errors. Furthermore, we present TRUTH-TRIANGULATOR that synthesizes reflective considerations by tool-enhanced ChatGPT and LoRA-tuning based on Llama2, aiming to yield more credible detection through the amalgamation of predictive results and evidence.\n\n\n## Illustration of Fact-Conflicting Hallucination Detection \nInspired by the saying ``to know it and to know the reason why of it`` by ``Zhuzi``, `FACTCHD` incorporates fact-based chains of evidence to provide  explanations for its binary predictions.  Based on `FACTCHD`, we aim to explore the application  of fact-conflicting hallucination detection task.\n\n\u003cdiv align=center\u003e\u003cimg src=\"figs/intro.png\" width=\"70%\" height=\"70%\" /\u003e\u003c/div\u003e\n\n\n## FACTCHD Benchmark Construction\n\nOur benchmark `FACTCHD` comprises a comprehensive dataset, consisting of ``51,383`` ``factual``/``non-factual`` samples for training and  additional ``6,960`` samples for LLM analysis and evaluation. It covers a wide range of domains, including health, medicine, climate, science, and more. `FACTCHD` endeavors to explore the factuality aspect of LLMs by examining four distinct patterns that encompass individual facts and interactions between multiple facts. \nOur automated data construction strategy  centers around harnessing a wealth of extensive knowledge (KG), including the data collection process,  generation of `\"Query-Respons\"` contexts, fact-based chains of evidence and  human filtering and statistical analysis.\n\n\u003cdiv align=center\u003e\u003cimg src=\"figs/construct.png\" width=\"95%\" height=\"95%\" /\u003e\u003c/div\u003e\n\n\n# 📕 Requirements\nTo run the codes, you need to install the requirements:\n```\nconda create -n fact python=3.9\nconda activate fact\npip install -r requirements.txt\n\nmkdir results\nmkdir lora\nmkdir data\n```\n\n# 🤗 Baseline Models \nHere are the baselines models in our evaluation:\n* [Alpaca-7b](https://huggingface.co/circulus/alpaca-7b)\n* [Vicuna-7b](https://huggingface.co/eachadea/vicuna-7b-1.1)\n* [Alpaca-13b](https://huggingface.co/chavinlo/alpaca-13b)\n* [Llama2-7b](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf)\n\n\n# 📚 Resource Illustration\n\n## Statistical Analysis of the Benchmark\nWe provide the  visual representation of the dataset’s domain distribution as following figures.\n\u003cdiv align=center\u003e\u003cimg src=\"figs/distribution.png\" width=\"70%\" height=\"70%\" /\u003e\u003c/div\u003e\n\n## Data format\nwe randomly provide several case examples of our FactLLM in the folder ```/data```.\n\n```json \nid: unique identifier ID.\ninstruction: instruction for the model indicating a fallacy finder task.\ninput: includes #Question# and #Answer#.\noutput: includes labels(NON-FACTUAL or FACTUAL) and justification.\n```\n\n##  Input for Tuning\n```json\n{\"id\": \"common_183152\", \"instruction\": \"I want you to act as a 'fallacy finder'. You will be on the lookout for invalid arguments so you can call out any logical errors or inconsistencies that may be present in the #Question# and the #Answer#. Your job is to provide evidence-based feedback and point out any fallacies, faulty reasoning, false assumptions, or incorrect conclusions which may be present in the #Question# and the #Answer#. Begin your response with either FACTUAL or NON-FACTUAL, followed by your justification.\", \"input\": \"#Question#: Could you please inform me whether Tata Motors is included in the BSE SENSEX index?\\n#Answer#: Tata Motors is excluded from the BSE SENSEX index.\", \"output\": \"NON-FACTUAL.The answer that Tata Motors is excluded from the BSE SENSEX index is incorrect. According to the evidence provided, Tata Motors is actually a constituent of the BSE SENSEX index. Therefore, this is a false incorrect conclusion.\"}\n```\n\n# 🙌 How to run\n\n\n+ ## Data Generation\n1. ### Knowledge Graph\n   Taking the high-quality dense subset [Wikidata15k](https://cloud.tsinghua.edu.cn/f/ea83c57d262b4a09ab92/?dl=1) from Wikidata as an example, it includes 794 concepts, 16,960 entities, 363 relations, and 846 properties. The generated subgraphs of the knowledge graph contain four types: `MULTI_HOP_REASONING`、`SET_OPERATION`、`QUANTITATIVE_COMPARISON`、`ALL`. \n   Other knowledge graph datasets can refer to this code. This code involves datasets like `Wikidata` and `PrimeKG`. \n   ```bash\n   cd data_generate\n   python kg_data_generate.py\n   ```\n2. ### Text\n   Taking the FEVER dataset as an example, download the preprocessed dataset [FEVER](https://thunlp.oss-cn-qingdao.aliyuncs.com/KernelGAT/FEVER/KernelGAT.zip). Other datasets in different domains can refer to the following process. This code involves datasets like `FEVER`, `Climate-Fever`, `Health-Fever`, `COVID-FACT`, and `SCIFACT`.\n    ```bash\n   cd data_generate\n   python text_data_generate.py\n    ```\n+ ## Finetune\n```bash\noutput_dir='lora/alpaca-7b-fact'\nmkdir -p ${output_dir}\nCUDA_VISIBLE_DEVICES=\"0,1,2\" torchrun --nproc_per_node=3 --master_port=1331 src/finetune.py \\\n    --base_model 'models/alpaca-7b' \\\n    --train_path 'data/fact/train.json' \\\n    --output_dir=${output_dir}  \\\n    --batch_size 240 \\\n    --micro_train_batch_size 10 \\\n    --micro_eval_batch_size 10 \\\n    --preprocessing_num_workers 4 \\\n    --num_epochs 10 \\\n    --learning_rate 1e-4 \\\n    --cutoff_len 800 \\\n    --val_set_size 2000 \\\n    --lora_r 16 \\\n    --lora_alpha 32 \\\n    --lora_dropout 0.05 \\\n    --group_by_length \\\n    | tee ${output_dir}/train.log \\\n    2\u003e ${output_dir}/train.err\n```\nThere are some differents among the finetune of alpaca、vicuna, please refer to `scripts/run_*` for more details. \n\n+ ## Inference\nPlease make sure the trained lora weights are placed in the path of `lora_weights`.\n```bash\nCUDA_VISIBLE_DEVICES=\"0\" python src/inference.py \\\n    --lora_weights 'lora/alpaca-7b-fact' \\\n    --base_model 'models/alpaca-7b' \\\n    --input_file 'data/test.json' \\\n    --output_file 'results/alpaca_7b_fact_test.json' \n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjunlp%2Ffactchd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzjunlp%2Ffactchd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjunlp%2Ffactchd/lists"}