Quantifying perturbation impacts for large language models Paulius Rauba; Qiyao Wei; Mihaela van der Schaar Statistical Foundations of LLMs Workshop · NeurIPS 2024 Original record: https://arxiv.org/abs/2412.00868 Original PDF: https://arxiv.org/pdf/2412.00868 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 === Quantifying perturbation impacts for large language models Paulius Rauba∗ University of Cambridge pr501@cam.ac.uk Qiyao Wei∗ University of Cambridge qw281@cam.ac.uk Mihaela van der Schaar University of Cambridge mv472@cam.ac.uk Abstract We consider the problem of quantifying how an input perturbation impacts the outputs of large language models (LLMs), a fundamental task for model reliability and post-hoc interpretability. A key obstacle in this domain is disentangling the meaningful changes in model responses from the intrinsic stochasticity of LLM outputs. To overcome this, we introduce Distribution-Based Perturbation Analysis (DBPA), a framework that reformulates LLM perturbation analysis as a frequentist hypothesis testing problem. DBPA constructs empirical null and alternative output distributions within a low-dimensional semantic similarity space via Monte Carlo sampling. Comparisons of Monte Carlo estimates in the reduced dimensionality space enables tractable frequentist inference without relying on restrictive distributional assumptions. The framework is model-agnostic, supports the evaluation of arbitrary input perturbations on any black-box LLM, yields interpretable p-values, supports multiple perturbation testing via controlled error rates, and provides scalar effect sizes for any chosen similarity or distance metric. We demonstrate the effectiveness of DBPA in evaluating perturbation impacts, showing its versatility for perturbation analysis. 1 Introduction Large language models (LLMs) generate outputs conditioned on textual inputs by iteratively sampling from a distribution of tokens. Therefore, the outputs of LLMs exhibit inherent variability due to the stochastic sampling process, a process controlled via parameters such as temperature or top-k [1]. This means that evaluating how a specific input perturbation—changing some information in the prompt—affects the output, is not straightforward [2]. Understanding and quantifying the effects of such perturbations is crucial in high-stakes applications—such as legal document drafting or medical diagnosis—where errors or unintended behavior could have significant consequences [3, 4]. Systematic evaluation of output responses to input perturbation is fundamental to comprehending LLM behavior. It provides quantitative insights into model robustness and output consistency across diverse input conditions. Perturbation analysis can serve at least three crucial functions in general ML models. First, it helps with vulnerability identification by quantifying potential vulnerabilities to adversarial attacks [5]. Second, it aids with bias discovery, whereby latent biases or unintended behaviors may not become apparent through single-dimension auditing approaches [6]. Third, it can work within a compliance framework. Measurable frameworks for assessing model behavior are essential for compliance with emerging ethical and legal accountability regulations [7]. In the context of language models, subtle changes in patient history could lead to wildly different diagnoses; and patients with nearly identical health records might receive drastically different treatment plans due to minor grammatical changes. Given these critical functions, there is a clear need for a comprehensive LLM auditing framework centered around perturbation analysis. ∗Equal Contribution Statistical Foundations of LLMs and Foundation Models Workshop at NeurIPS 2024. arXiv:2412.00868v1 [cs.LG] 1 Dec 2024 === PDF PAGE 2 === Table 1: Use case examples of distribution-based perturbation analysis. We show how DBPA can be used in five areas for different tasks with the associated added value of our framework. Area Description of task Use case of DBPA Value added Prompt robustness Evaluate sensitivity to question rephrasing in QA systems Ensure consistent answers across question formulations Improved system reliability Training Stability Evaluate output consistency across fine- tuning iterations Monitor and optimize model reliability over time Better training stability monitoring Model comparison Analyze the impact of different LLM an- swers to reference answers (e.g. GPT-4) Determine optimal model Best model chosen Adversarial attack Evaluate whether a model is being adver- sarially attacked Determine if the output diverges too much from relevant, seen answers Better adversarial robustness Current methods for analyzing the impact of input perturbations often focus on simplistic metrics, such as word overlap or direct log-probability comparisons. While effective in certain cases, these approaches fail to account for the nuanced, high-dimensional nature of semantic information pro- cessed by LLMs [8, 9]. Moreover, existing methods typically lack rigorous statistical foundations, making it difficult to disentangle meaningful changes in model behavior from intrinsic randomness in the output generation process. Efforts to address this have included specialized attribution methods, feature importance techniques, and counterfactual reasoning frameworks [6, 10]. However, these approaches are often model-specific, rely on restrictive assumptions about the data or model, or fail to provide interpretable and generalizable metrics2. Our solution. In this work, we introduce Distribution-Based Perturbation Analysis (DBPA), a framework that reformulates the problem of LLM perturbation analysis as a frequentist hypothesis testing task. DBPA constructs empirical output distributions using Monte Carlo sampling to capture the inherent stochasticity of LLMs, and evaluates perturbation effects within a low-dimensional semantic similarity space. By leveraging statistical hypothesis testing, the framework enables robust, interpretable inferences about whether and how input perturbations meaningfully influence LLM outputs. DBPA is model-agnostic, computationally efficient, and flexible enough to accommodate arbitrary perturbations on any black-box LLM. It also provides interpretable p-values, scalar effect sizes, and supports multiple testing with controlled error rates, making it a versatile tool for post-hoc interpretability and reliability assessments of LLMs. Significance beyond technical novelty. We see this work as having immediate practical relevance for practitioners who wish to evaluate their LLM outputs and whether they change in real-world practical settings, including evaluating prompt robustness, LLM robustness, and conducting model comparisons. ­ Contributions. 1⃝We identify limitations in existing sensitivity-based measures for lan- guage models (Sec. 2). 2⃝We introduce distribution-based perturbation analysis which is a model-agnostic sensitivity technique that can test the effect of any perturbation with statistical significance measures (Sec. 3). 3⃝We perform multiple case studies to show the usefulness of DBPA (Sec. 4). 2 An analysis of viewing LLM outputs through frequentist hypothesis testing In this section, we describe how we can view LLM outputs through the lens of frequentist hypothesis testing. We will first define the problem, then pose as hypothesis testing, and discuss why naively applying statistical methods will fail due to curse of dimensionality. 2.1 Problem formulation Let X denote the input space and Y the output space of a machine learning system. We define the system as a stochastic mapping S : X →P(Y), where P(Y) is the space of probability distributions over Y. This formulation captures the inherent stochasticity of modern ML systems, including LLMs. 2Code available at https://github.com/vanderschaarlab/DBPA 2 === PDF PAGE 3 === Our objective is to address the following research question: Given an ML system S, an input x ∈X, and a perturbation ∆, how can we systematically measure and interpret the impact of ∆on the output distribution of S(x) under a general notion of sensitivity? Definition 1 (Sensitivity). The sensitivity of a machine learning system S with respect to a pertur- bation ∆: X →X, or a system perturbation ∆: S →S, at input x ∈X, is characterized by a measure of discrepancy between the output distributions S(x) and S(∆x), or S(x) and ∆S(x), respectively. This definition encompasses both input perturbations (∆Y == S(∆x)) and system perturbations (∆Y == ∆S(X)). Crucially, we wish to evaluate this sensitivity by only having access to the ML system S from which we could sample. We do not assume access to ground-truth labels and make no assumptions on the architecture of S. 2.2 Distribution testing as a frequentist hypothesis problem The challenge of assessing the sensitivity of S can be reframed as a frequentist hypothesis testing problem. Traditionally, one might be tempted to compare individual outputs of S for different inputs: y = S(x), y′ = S(∆(x)) (1) However, this approach is fundamentally flawed due to the stochastic nature of LLM systems. For any fixed input x, S(x) is a random variable, and thus y and y′ are single realizations from a distribution of outputs. Consequently, any observed difference between y and y′ could be due to inherent randomness rather than a true effect of ∆. To address this limitation, we propose reframing the problem from the lens of distribution testing. Instead of comparing individual outputs, we compare the entire output distributions. Let Dx and D∆(x) be the distributions of outputs from S(x) and S(∆(x)) respectively. Definition 2 (Output Distribution). For a given input x ∈X and an LLM S : X →P(Y), the output distribution Dx is a probability distribution over the output space Y such that: Dx(y) = P(S(x) = y), ∀y ∈Y (2) Our goal is to determine whether these distributions differ significantly. This can be formulated as a hypothesis test: H0 : Dx = D∆(x) (The perturbation has no effect) (3) H1 : Dx ̸= D∆(x) (The perturbation affects the output distribution) (4) The primary benefit of such a distributional formulation 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 comparing 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. ­ To understand the sensitivity of a language model to changes in input, we need to look at the entire range of possible outputs it can produce, not just single examples. However, while theoretically grounded, the usage of such a hypothesis testing framework in the context of LLMs poses unique practical challenges that do not appear in regular settings. We discuss these next. 2.3 Challenges with analyzing output distributions There are two primary challenges in comparing output distributions to evaluate the effect of an input perturbation on the output: computational intractability and poor interpretability. 3 === PDF PAGE 4 === ▶Challenge 1: Computational intractability. In almost all cases, it is impossible to directly evaluate the output distribution change because of the exponential output space Y = V L where V is the vocabulary and L is the sequence length, yielding |Y | = |V |L possible outputs for each sentence, and that is assuming a fixed L. Suppose we limit our language model S to output only sequences of length L. In this case, Dx would require summing over all possible sequences: Dx = X y1∈V X y2∈V · · · X yL∈V L Y t=1 p(yt|y