Papers › UniBias: Unveiling and Mitigating LLM Bias through Internal Attention and FFN Manipulation

UniBias: Unveiling and Mitigating LLM Bias through Internal Attention and FFN Manipulation

31 May 2024arXiv:2405.20612archive 2025-07-28

Hanzhang Zhou, Zijian Feng, Zixiao Zhu, Junlang Qian, Kezhi Mao

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.

PaperPDFCodeCode Syntology ranMethod as code

In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, on Syntology's MCP service (how to connect):

Code

Syntology 23 code samples harvested from 1 repository linked to this paper: 10 ran (of which 0 constructed an object rather than computing a result; 6 with no instrument failure: 2 honoured, 3 violated, 1 with no contract checked; 4 where Syntology's instrument failed) · 13 unverified. Where Syntology's instrument failed: 4 where our contract draft was wrong; failures of Syntology's instrument, not of the code.

By repository: official repository: 23 samples from 1 repository, 10 ran (6 with no instrument failure; 4 where Syntology's instrument failed). The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

Levels written between 2026-09-22 and 2026-09-25 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed.

hzzhou01/unibias officialmentioned in papermentioned on GitHubpytorchSyntology: 23 samples, 10 ran (4 instrument-failed) · 13 unverified report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

23 samples harvested: 10 ran (of which 0 constructed an object rather than computing a result; 6 with no instrument failure: 2 honoured, 3 violated, 1 with no contract checked; 4 where Syntology's instrument failed) · 13 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page last changed ; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

2ran · honoured contract
3ran · violated contract
4ran · our draft was wrong
1ran
13unverified

Licence: 23 of the 23 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from hzzhou01/unibias. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: 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. Samples are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of six reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

A function or class name links to its page when the name occurs in the harvested code of at least 5 papers; the name is a string, not an identity.

hzzhou01/unibias official repository 23 samples, 10 ran (4 instrument-failed) · 13 unverified
find_answer_location FFN_manipulate.py ran · honoured contract no licence file found · pointer only · 4c2cdc6d46710e28 · report fixture: signature full_tokens:list/1/str, task:str/0/str · returned int · level recorded 2026-09-22
find_biased_FFN_neuron_candidates FFN_manipulate.py ran · our draft was wrong no licence file found · pointer only · ac8b2b45bae5272c · report fixture: signature logits:list/1/Tensor, logits_sum:list/1/Tensor, th:float/0/float, bias_th:float/0/float · returned dict · level recorded 2026-09-22
find_possible_ids_for_multi_str FFN_manipulate.py ran · honoured contract no licence file found · pointer only · f3445e3da098c0a5 · report fixture: signature arg_str_list:list/1/tuple, tokenizer:MockTokenizer/0/? · returned list · level recorded 2026-09-22
find_value_logits FFN_manipulate.py ran no licence file found · pointer only · 5f015227f97c50b8 · report fixture: signature model:callable/0/?, ans_ids_list:Tensor/2/int · returned tuple · level recorded 2026-09-25
is_ans_in_anslist FFN_manipulate.py ran · violated contract fingerprinted no licence file found · pointer only · e1367404ff17e8ef · report fixture: signature ans:str/0/str, ans_list:list/1/list · returned bool · level recorded 2026-09-22
logit_bias_estimation FFN_manipulate.py ran · violated contract fingerprinted no licence file found · pointer only · fb283407ff03f0fd · report fixture: signature label_logit_list:list/1/float · returned float64 · level recorded 2026-09-22
logit_bias_measure FFN_manipulate.py ran · violated contract fingerprinted no licence file found · pointer only · 37daafb3c4572430 · report fixture: signature label_logit_list:list/1/float · returned float · level recorded 2026-09-22
remove_identical_sublist FFN_manipulate.py ran · our draft was wrong no licence file found · pointer only · 18431ee4acf533be · report fixture: signature biased_list:list/1/dict · returned list · level recorded 2026-09-22
set_value_activations FFN_manipulate.py ran · our draft was wrong no licence file found · pointer only · 8bc4af0229b22f6d · report fixture: signature model:callable/0/?, values_per_layer:dict/0/?, coef_value:int/0/int · returned list · level recorded 2026-09-22
task_labels utils.py ran · our draft was wrong no licence file found · pointer only · b558ac818ed0c9de · report fixture: signature dataset_name:str/0/str · returned list · level recorded 2026-09-24
ICL_evaluation evaluation.py unverified no licence file found · pointer only · 6595f909f76e9813 · report
attention_manipulate attention_manipulate.py unverified no licence file found · pointer only · 7631387e693a38cf · report
biased_FFN_identify_and_eliminate FFN_manipulate.py unverified no licence file found · pointer only · bb52ec836a875bf1 · report
biased_FFN_identify_and_eliminate FFN_manipulate.py unverified no licence file found · pointer only · a67008b9b855e757 · report
biased_attention_head_identification attention_manipulate.py unverified no licence file found · pointer only · d898356a336356c6 · report
find_biased_FFN_neurons FFN_manipulate.py unverified no licence file found · pointer only · 3bfab6f86cee8c69 · report
get_logp_estimate_data evaluation.py unverified no licence file found · pointer only · 3e2f0f0bb88ba822 · report
get_p_content_free in 6 papers evaluation.py unverified no licence file found · pointer only · 5464ddd4e6a77518 · report
grid_search_biased_FFNs FFN_manipulate.py unverified no licence file found · pointer only · 7de4b9c5a4513457 · report
logit_bias_estimate FFN_manipulate.py unverified no licence file found · pointer only · f8c50a188608d6bd · report
prepare_dataset_test utils.py unverified no licence file found · pointer only · 30eaa50322113838 · report
prepare_dataset_validate utils.py unverified no licence file found · pointer only · a2937f0a2487dd76 · report
remove_all_hooks FFN_manipulate.py unverified no licence file found · pointer only · 568b3828c10a0702 · report

Method as code Syntology

What Syntology's graph records as this paper's claimed method, lifted into code: each assembly names its bricks (functions and classes), each with its own role and its own verification level. An assembly is not a check that the code implements the method correctly or reproduces the paper's results. Levels are each brick's own verification level in Syntology's graph (level 0: no recorded run), listed brick by brick and never combined into one level; “ran” means the brick executed on a synthesized input, not that its output is correct, and the instrument figure counts failures of Syntology's instrument, not of the code. Where a model read the code against the paper's claim, each assembly's label verdict is one model's judgement, kept in this page's JSON twin; it is not calibrated, so no card prints it.

1 assembly on this paper: 1 harvested, 0 generated.

harvested Assembly for UniBias (graph method: UniBias). 14 bricks; individually on a fixture: 9 ran (of which 0 constructed an object rather than computing a result; 6 with no instrument failure: 2 honoured, 3 violated, 1 with no contract checked; 3 where Syntology's instrument failed) · 5 unverified. The assembly has not been run end-to-end.

  1. biased_FFN_identify_and_eliminate entry · level 0 · unverified · bb52ec836a875bf1
  2. find_biased_FFN_neuron_candidates helper · level 1 · ran · our draft was wrong · ac8b2b45bae5272c
  3. find_biased_FFN_neurons helper · level 0 · unverified · 3bfab6f86cee8c69
  4. find_possible_ids_for_multi_str helper · level 1 · ran · honoured contract · f3445e3da098c0a5
  5. find_value_logits helper · level 1 · ran · 5f015227f97c50b8
  6. grid_search_biased_FFNs helper · level 0 · unverified · 7de4b9c5a4513457
  7. logit_bias_estimate metric · level 0 · unverified · f8c50a188608d6bd
  8. remove_identical_sublist helper · level 1 · ran · our draft was wrong · 18431ee4acf533be
  9. set_value_activations model · level 1 · ran · our draft was wrong · 8bc4af0229b22f6d
  10. logit_bias_measure helper · level 1 · ran · violated contract · 37daafb3c4572430
  11. find_answer_location helper · level 1 · ran · honoured contract · 4c2cdc6d46710e28
  12. is_ans_in_anslist helper · level 1 · ran · violated contract · e1367404ff17e8ef
  13. logit_bias_estimation helper · level 1 · ran · violated contract · fb283407ff03f0fd
  14. remove_all_hooks helper · level 0 · unverified · 568b3828c10a0702

Each brick ends with its code_sha256, Syntology's identity for that exact code; click one to copy the get_code call that returns it. For agents, on Syntology's MCP service: assembly(arxiv_id="2405.20612") returns these assemblies with each brick's role and wiring (how to connect).

Tasks

In-Context Learning

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections