{"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/unibias-unveiling-and-mitigating-llm-bias","title":"UniBias: Unveiling and Mitigating LLM Bias through Internal Attention and FFN Manipulation","arxiv_id":"2405.20612","date":"2024-05-31","proceeding":null,"authors":["Hanzhang Zhou","Zijian Feng","Zixiao Zhu","Junlang Qian","Kezhi Mao"],"abstract":"Large language models (LLMs) have demonstrated impressive capabilities in various tasks using the in-context learning (ICL) paradigm. However, their effectiveness is often compromised by inherent bias, leading to prompt brittleness, i.e., sensitivity to design settings such as example selection, order, and prompt formatting. Previous studies have addressed LLM bias through external adjustment of model outputs, but the internal mechanisms that lead to such bias remain unexplored. Our work delves into these mechanisms, particularly investigating how feedforward neural networks (FFNs) and attention heads result in the bias of LLMs. By Interpreting the contribution of individual FFN vectors and attention heads, we identify the biased LLM components that skew LLMs' prediction toward specific labels. To mitigate these biases, we introduce UniBias, an inference-only method that effectively identifies and eliminates biased FFN vectors and attention heads. Extensive experiments across 12 NLP datasets demonstrate that UniBias significantly enhances ICL performance and alleviates prompt brittleness of LLMs.","url_abs":"https://arxiv.org/abs/2405.20612v2","url_pdf":"https://arxiv.org/pdf/2405.20612v2.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":"unibias-unveiling-and-mitigating-llm-bias","repo_url":"https://github.com/hzzhou01/unibias","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2405.20612","atlas_url":"https://app.syntology.ai/?focus=2405.20612","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2405.20612"}},"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":"deterministic:regex_extraction","url":"https://github.com/hzzhou01/UniBias","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/hzzhou01/unibias","reach":{"status":"ok"}}],"summary":{"ran_honours":2,"ran_draft_wrong":3,"ran":2,"ran_violates":3,"unverified":13},"by_repo_kind":{"official":{"samples":23,"ran":10,"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":23,"samples":[{"code_sha256_prefix":"4c2cdc6d46710e28","entry":"find_answer_location","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4c2cdc6d46710e28"}},{"code_sha256_prefix":"ac8b2b45bae5272c","entry":"find_biased_FFN_neuron_candidates","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ac8b2b45bae5272c"}},{"code_sha256_prefix":"f3445e3da098c0a5","entry":"find_possible_ids_for_multi_str","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f3445e3da098c0a5"}},{"code_sha256_prefix":"5f015227f97c50b8","entry":"find_value_logits","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5f015227f97c50b8"}},{"code_sha256_prefix":"e1367404ff17e8ef","entry":"is_ans_in_anslist","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e1367404ff17e8ef"}},{"code_sha256_prefix":"fb283407ff03f0fd","entry":"logit_bias_estimation","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"fb283407ff03f0fd"}},{"code_sha256_prefix":"37daafb3c4572430","entry":"logit_bias_measure","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"37daafb3c4572430"}},{"code_sha256_prefix":"18431ee4acf533be","entry":"remove_identical_sublist","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"18431ee4acf533be"}},{"code_sha256_prefix":"8bc4af0229b22f6d","entry":"set_value_activations","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8bc4af0229b22f6d"}},{"code_sha256_prefix":"b558ac818ed0c9de","entry":"task_labels","repo":"hzzhou01/UniBias","repo_kind":"official","path":"utils.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b558ac818ed0c9de"}},{"code_sha256_prefix":"6595f909f76e9813","entry":"ICL_evaluation","repo":"hzzhou01/UniBias","repo_kind":"official","path":"evaluation.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/evaluation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6595f909f76e9813"}},{"code_sha256_prefix":"7631387e693a38cf","entry":"attention_manipulate","repo":"hzzhou01/UniBias","repo_kind":"official","path":"attention_manipulate.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/attention_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7631387e693a38cf"}},{"code_sha256_prefix":"bb52ec836a875bf1","entry":"biased_FFN_identify_and_eliminate","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bb52ec836a875bf1"}},{"code_sha256_prefix":"a67008b9b855e757","entry":"biased_FFN_identify_and_eliminate","repo":"hzzhou01/UniBias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a67008b9b855e757"}},{"code_sha256_prefix":"d898356a336356c6","entry":"biased_attention_head_identification","repo":"hzzhou01/UniBias","repo_kind":"official","path":"attention_manipulate.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/attention_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d898356a336356c6"}},{"code_sha256_prefix":"3bfab6f86cee8c69","entry":"find_biased_FFN_neurons","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3bfab6f86cee8c69"}},{"code_sha256_prefix":"3e2f0f0bb88ba822","entry":"get_logp_estimate_data","repo":"hzzhou01/UniBias","repo_kind":"official","path":"evaluation.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/evaluation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3e2f0f0bb88ba822"}},{"code_sha256_prefix":"5464ddd4e6a77518","entry":"get_p_content_free","repo":"hzzhou01/UniBias","repo_kind":"official","path":"evaluation.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/evaluation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5464ddd4e6a77518"}},{"code_sha256_prefix":"7de4b9c5a4513457","entry":"grid_search_biased_FFNs","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7de4b9c5a4513457"}},{"code_sha256_prefix":"f8c50a188608d6bd","entry":"logit_bias_estimate","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f8c50a188608d6bd"}},{"code_sha256_prefix":"30eaa50322113838","entry":"prepare_dataset_test","repo":"hzzhou01/UniBias","repo_kind":"official","path":"utils.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"30eaa50322113838"}},{"code_sha256_prefix":"a2937f0a2487dd76","entry":"prepare_dataset_validate","repo":"hzzhou01/UniBias","repo_kind":"official","path":"utils.py","file_url":"https://github.com/hzzhou01/UniBias/blob/HEAD/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a2937f0a2487dd76"}},{"code_sha256_prefix":"568b3828c10a0702","entry":"remove_all_hooks","repo":"hzzhou01/unibias","repo_kind":"official","path":"FFN_manipulate.py","file_url":"https://github.com/hzzhou01/unibias/blob/HEAD/FFN_manipulate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"568b3828c10a0702"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}