{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/truthx-alleviating-hallucinations-by-editing","title":"TruthX: Alleviating Hallucinations by Editing Large Language Models in Truthful Space","arxiv_id":"2402.17811","date":"2024-02-27","proceeding":null,"authors":["Shaolei Zhang","Tian Yu","Yang Feng"],"abstract":"Large Language Models (LLMs) sometimes suffer from producing hallucinations, especially LLMs may generate untruthful responses despite knowing the correct knowledge. Activating the truthfulness within LLM is the key to fully unlocking LLM's knowledge potential. In this paper, we propose TruthX, an inference-time intervention method to activate the truthfulness of LLM by identifying and editing the features within LLM's internal representations that govern the truthfulness. TruthX employs an auto-encoder to map LLM's representations into semantic and truthful latent spaces respectively, and applies contrastive learning to identify a truthful editing direction within the truthful space. During inference, by editing LLM's internal representations in truthful space, TruthX effectively enhances the truthfulness of LLM. Experiments show that TruthX improves the truthfulness of 13 advanced LLMs by an average of 20% on TruthfulQA benchmark. Further analyses suggest that TruthX can control LLM to produce truthful or hallucinatory responses via editing only one vector in LLM's internal representations.","url_abs":"https://arxiv.org/abs/2402.17811v2","url_pdf":"https://arxiv.org/pdf/2402.17811v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"truthx-alleviating-hallucinations-by-editing","repo_url":"https://github.com/ictnlp/truthx","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"jax","reach":null}],"tasks":[{"task_slug":"contrastive-learning","task_name":"Contrastive Learning"},{"task_slug":"hallucination","task_name":"Hallucination"},{"task_slug":"hallucination-evaluation","task_name":"Hallucination Evaluation"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"large-language-model","task_name":"Large Language Model"},{"task_slug":"question-answering","task_name":"Question Answering"},{"task_slug":"text-generation","task_name":"Text Generation"},{"task_slug":"truthfulqa","task_name":"TruthfulQA"}],"methods":[{"method_slug":"contrastive-learning","method_name":"Contrastive Learning"},{"method_slug":"llama","method_name":"LLaMA"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/question-answering-on-truthfulqa","task":"Question Answering","dataset":"TruthfulQA","model":"Mistral-7B-Instruct-v0.2 + TruthX","rank_in_archive_order":2,"of":33,"metrics":{"MC1":"0.56","MC2":"0.75"},"uses_additional_data":false},{"leaderboard":"/sota/question-answering-on-truthfulqa","task":"Question Answering","dataset":"TruthfulQA","model":"LLaMa-2-7B-Chat + TruthX","rank_in_archive_order":3,"of":33,"metrics":{"MC1":"0.54","MC2":"0.74"},"uses_additional_data":false}],"syntology":{"syntology_url":"https://syntology.ai/paper/2402.17811","atlas_url":"https://app.syntology.ai/?focus=2402.17811","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.17811"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ictnlp/truthx","reach":null}],"summary":{"ran":2,"unverified":1},"by_repo_kind":{"official":{"samples":3,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":3,"samples":[{"code_sha256_prefix":"ab94575b236d35ac","entry":"BaseVAE","repo":"ictnlp/truthx","repo_kind":"official","path":"truthx.py","file_url":"https://github.com/ictnlp/truthx/blob/HEAD/truthx.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"GPL-3.0","inline_ok":false,"mcp_get_code":{"code_sha256":"ab94575b236d35ac"}},{"code_sha256_prefix":"e57e5eba258c91bf","entry":"MLPAE","repo":"ictnlp/truthx","repo_kind":"official","path":"truthx.py","file_url":"https://github.com/ictnlp/truthx/blob/HEAD/truthx.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"GPL-3.0","inline_ok":false,"mcp_get_code":{"code_sha256":"e57e5eba258c91bf"}},{"code_sha256_prefix":"fd4f4ae6f89a683f","entry":"TruthX","repo":"ictnlp/truthx","repo_kind":"official","path":"truthx.py","file_url":"https://github.com/ictnlp/truthx/blob/HEAD/truthx.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"GPL-3.0","inline_ok":false,"mcp_get_code":{"code_sha256":"fd4f4ae6f89a683f"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}