Visualizing token importance for black-box language models Paulius Rauba; Qiyao Wei; Mihaela van der Schaar AISTATS 2025 Original record: https://proceedings.mlr.press/v258/rauba25a.html Original PDF: https://raw.githubusercontent.com/mlresearch/v258/main/assets/rauba25a/rauba25a.pdf Original paper text extracted automatically from the PDF. Equations, tables and layout may be imperfect in this representation; consult the PDF for exact notation and reported values. This is the original research text, distinct from the language-model-generated explanation on the landing page. === PDF PAGE 1 === Visualizing token importance for black-box language models Paulius Rauba→ Qiyao Wei→ Mihaela van der Schaar University of Cambridge University of Cambridge University of Cambridge Abstract We consider the problem of auditing black-box large language models (LLMs) to ensure they behave reliably when deployed in production settings, particularly in high-stakes domains such as legal, medical, and regulatory compli- ance. Existing approaches for LLM auditing often focus on isolated aspects of model behav- ior, such as detecting specific biases or eval- uating fairness. We are interested in a more general question—can we understand how the outputs of black-box LLMs depend on each input token? There is a critical need to have such tools in real-world applications that rely on inaccessible API endpoints to language models. However, this is a highly non-trivial problem, as LLMs are stochastic functions (i.e. two outputs will be di!erent by chance), while computing prompt-level gradients to ap- proximate input sensitivity is infeasible. To address this, we propose Distribution-Based Sensitivity Analysis (DBSA), a lightweight model-agnostic procedure to evaluate the sen- sitivity of the output of a language model for each input token, without making any distri- butional assumptions about the LLM. DBSA is developed as a practical tool for practition- ers, enabling quick, plug-and-play visual ex- ploration of LLMs reliance on specific input tokens. Through illustrative examples, we demonstrate how DBSA can enable users to inspect LLM inputs and find sensitivities that may be overlooked by existing LLM inter- pretability methods. 1 Introduction Auditing black-box language models is a fundamen- tal requirement to ensuring they behave reliably when Proceedings of the 28th International Conference on Artifi- cial Intelligence and Statistics (AISTATS) 2025, Mai Khao, Thailand. PMLR: Volume 258. Copyright 2025 by the author(s). deployed in the real-world. Society implicitly expects LLMs to operate ethically, comply with regulations, and deliver technically sound responses without causing harm. This has resulted in the development of broad audit frameworks focused on governance and regulatory oversight (Mökander et al., 2023; Meskó and Topol, 2023; Raji et al., 2022). Despite these high-level frame- works, practical algorithms that practitioners could employ to audit LLMs are scarce. Why is there a need for practical LLM audit al- gorithms? While high-level frameworks are necessary, there is an increasing demand for practical algorithms that provide detailed, interpretable insights into LLM behavior. The urgency for such tools arises from two factors: mitigating real-world harm and complying with regulatory demands. Without precise auditing tools, LLMs may propagate biases or deliver inconsistent out- puts, leading to societal harm (Gehman et al., 2020; Nozza, Bianchi, Hovy, et al., 2021) or diverge from their intended purpose over time, causing unforseen negative impacts (Lauer, 2021; Rahwan, 2018; Dafoe, 2018). Regulatory frameworks like the EU AI Act are considering classifying LLMs as “high-risk AI systems” that would require mandatory third-party audits be- fore deployment (Helberger, Diakopoulos, et al., 2023; Mökander et al., 2023). Existing tools do not meet these needs because they either focus narrowly on spe- cific biases or require complex, benchmark-oriented setups that are not adaptable to diverse real-world scenarios. What is missing from current LLM auditing methods? The auditing landscape for LLMs is domi- nated by methods that target isolated dimensions, such as bias detection (Borkan et al., 2019; Dixon et al., 2018; Park, Shin, and Fung, 2018), fairness evaluation (Garg et al., 2019), or adversarial robustness (Geisler et al., 2024). While these approaches are valuable for targeted analysis, they lack the flexibility and general applicability required by practitioners who need quick, interpretable feedback on LLM behavior across varied domains. What is missing is a practical, easy-to-deploy, statistically-grounded tool that provides actionable, visual insights into the behavior of any black-box LLM. === PDF PAGE 2 === Visualizing token importance for black-box language models Table 1: Why sensitivity analysis is important for model auditing. Two examples show sensitivity scores for each word when an LLM is asked for legal advice. Darker shades indicate higher importance. In Example 1, the model focuses on the alleged crime, while in Example 2, its sensitivity to the person’s name indicates an undesired reliance when the name is irrel- evant to the LLM response. Example 2 could prompt further investigation in practical scenarios. Legend: Most important Least important Example 1 (Desired behavior): John Doe is accused of murder . Example 2 (Undesired behavior): John Doe is accused of murder . How can sensitivity analysis serve as a practi- cal and interpretable tool for auditing LLMs? We diverge from existing auditing mechanisms and de- fine an entirely new task—developing a model-agnostic framework for LLM sensitivity analysis. Sensitivity analysis o!ers a practical and interpretable way to au- dit LLMs by showing how model outputs change with variations in input. In a nutshell, the primary question that sensitivity analysis for language models answers is the following: “How do the answers produced by a language model depend on each input token?” Such an approach allows practitioners to visualize and interpret the influence of each token, providing a model- agnostic way of auditing LLM behavior. For exam- ple, Table 1 shows how sensitivity analysis can re- veal unwanted model behavior when evaluating legal prompts, providing clear, actionable insights that stan- dard benchmarks might overlook. The ability to iden- tify such context-dependent sensitivities allows practi- tioners to explore if model behavior is appropriate for the given scenario. However, implementing such a tool poses unique chal- lenges. Repurposing existing gradient-based methods for black-box LLMs (Zeiler and Fergus, 2014) is impos- sible because we assume no access to LLM internals. Another alternative could be to manually change the input to a desired perturbation and inspect the changes. However, this is problematic because LLMs are stochas- tic generators, i.e. two outputs will vary by chance. Therefore, it is insu!cient to look at two individual answers due to the stochastic nature of the LLMs; one must consider the entire distribution of possible answers rather than individual outputs. Our solution. To provide a practical solution for these challenges, we introduce Distribution-Based Sensitivity Analysis (DBSA). DBSA is a lightweight, exploratory tool that finds the most important tokens in an input prompt. It is designed to be immediately usable by practitioners without requiring access to proprietary model internals or specialized knowledge. To achieve this, we approximate sensitivity analysis by considering each token’s nearest neighbors in embedding space, performing Monte Carlo sampling for each neighbor and comparing Monte Carlo estimates on a reduced similarity space. With this formulation, we (i) capture the stochastic nature of LLM outputs more faithfully than point estimates; (ii) connect LLM outputs to distributional testing; (iii) quantify e!ect size; (iv) maintain model and input agnosticism, and (v) allow to directly visualize and highlight tokens based on their importance. What practical value does DBSA o!er? DBSA is designed for immediate application across various domains such as legal, medical, and customer service, where understanding token-level behavior is important. Existing methods, such as gradient-based sensitivity and bias evaluation techniques, are limited to specific use cases or require access to model internals. DBSA addresses the entirely new task of generalized sensi- tivity analysis for black-box LLMs, applicable across diverse domains. Because this is a new interpretability setup, it does not lend itself naturally to benchmark comparisons—a reason why we focus on illustrative examples and ablation studies in Sec. 5 - 6. We see DBSA as having direct applicability in many applica- tions, such as visualizing all tokens in a prompt (Table 2), top n tokens and computing e!ect sizes (Table 3), and others. ! Contributions. 1 →Conceptually, we introduce an entirely new task—auditing how the output distri- bution of black-box LLMs depend on specific input tokens (Sec. 2). 2 →Technically, we develop DBSA, a lightweight, easily deployable model-agnostic al- gorithm that uses finite-sample approximations and statistical testing to measure the impact of token- level changes (Sec. 3 - 4). 3 →Empirically, we show how DBSA o!ers black-box interpretability (Sec. 5) and build trust in the method by performing relevant quantitative ablations (Sec. 6). 2 Unique challenges of obtaining token importance scores in black-box language models We start by defining our problem (Sec. 2.1) and explain- ing why evaluating LLM responses requires looking at distributions of answers (Sec. 2.2). We then explore the unique challenges this poses (Sec. 2.3), proposing a procedure to address them (Sec. 3). === PDF PAGE 3 === Paulius Rauba→, Qiyao Wei→, Mihaela van der Schaar 2.1 Problem formulation Let X denote the input space, where each input x →X is a sequence of words or tokens x = (t1, t2, . . . , tn). Let Y denote the output space of the machine learning system. We define the system as a stochastic mapping S : X ↑P(Y), where P(Y) denotes the space of probability distributions over Y. Objective. Our objective is to address the following research question: Given a black-box ML system S, an input x →X, and an individual token(s) ti at position i in x, how can we systematically measure and interpret the sensitivity of the output distribution S(x) with respect to small perturbations of ti? We measure such minimal changes in token-level sensitivity as follows. Definition 1 (Token-Level Sensitivity). The token- level sensitivity of the machine learning system S at position i in input x →X is defined as the expected change in the output distribution S(x) resulting from a small perturbation ωti to the word ti, normalized by the magnitude of the perturbation: Sensitivity(ti) = lim ↑ωti↑↓0 ε ! S(x), S ! x[ti↔ti+ωti] "" ↓ωti↓ x[ti↔ti+ωti] denotes the input sequence where ti has been perturbed by ωti and ε is a suitable distance measure. 2.2 Assessing sensitivity through comparison of output distributions How can we evaluate token-level sensitivity? This requires (a) analyzing how the entire distribution of responses would change under the defined sensitivity metric; (b) understanding how to approximate such small perturbations in a discrete token space and a black-box setting; (c) evaluate how to take into account the inherent stochasticity of language model responses. We address these in turn. First, we need a framework to evaluate how the entire distribution of responses would change under a par- ticular change in the input. To do this, we take the approach of using Monte Carlo estimates of perturbed inputs as a measure of constructing such a distribution (Rauba, Wei, and Schaar, 2024). Suppose we swap an input token with its nearest neighbor in embedding space. A naive approach might involve comparing indi- vidual outputs from S for the original input x and its perturbed version x[ti↔ti+ωti]: y = S(x), y↗= S ! x[ti↔ti+ωti] " However, since S produces random outputs even for the same input, such a comparison between single samples y and y↗is insu"cient. Any observed di!erence could merely be a consequence of the system’s stochasticity rather than the e!ect of the perturbation ωti. To address this challenge, we employ a statistical ap- proach that compares the entire output distributions of S for the original and perturbed inputs (Rauba, Wei, and Schaar, 2024). Specifically, we consider the distri- butions S(x) and S ! x[ti↔ti+ωti] " over the output space Y. Therefore, our objective is to determine whether the swapped nearest neighbor token ωti leads to a sig- nificant change in the output distribution. This can be formalized as a hypothesis testing problem: H0 : S(x) = S ! x[ti↔ti+ωti] " (No e!ect) H1 : S(x) ↔= S ! x[ti↔ti+ωti] " (Has an e!ect) The primary benefit of such a distributional formula- tion is that it captures the full stochastic behavior of S instead of just a single realization. This means we could perform statistical inference by directly compar- ing these distributions and understanding how much the outputs have shifted across the whole output space, even detecting subtle shifts that might not be apparent from individual samples. However, while theoretically grounded, the usage of such a hypothesis testing frame- work in the context of LLMs poses unique practical challenges that do not appear in regular settings. 2.3 Challenges with analyzing token-level output distributions Building on the foundational work of Rauba, Wei, and Schaar (2024), we identify three key challenges in an- alyzing output distributions for token-level sensitiv- ity, with particular emphasis on the discrete nature of nearest-neighbor perturbations. ↭Challenge 1: Computational intractability. As established in prior work, the fundamental computa- tional barrier lies in the exponential size of the output space Y. For language models operating on vocabulary V with sequence length L, we have |Y| = |V |L possi- ble outputs. The probability of any output sequence y = (y1, y2, . . . , yL) →Y under input x is given by: S(x)(y) = P(y | x) = L # t=1 P(yt | y