Skip to main content

Is the Variability Variable?

I'm definitely no expert in Large Language Models but expertise is not required, given all the publicity, to know that variation in the responses from the technology is expected. 

To illustrate that, I asked ChatGPT  "In one sentence, why do LLM responses vary on the same prompt?" and got three different, although clearly related and overlapping, answers:

LLM responses vary on the same prompt due to the model's stochastic nature, diverse training data, and sensitivity to slight changes in input phrasing. 

LLM responses vary on the same prompt due to the model's probabilistic nature, employing diverse sampling techniques and leveraging its extensive training data to generate a range of contextually plausible and grammatically coherent outputs.

LLM responses vary on the same prompt due to the model's inherent stochasticity and diverse training data, leading to different contextual interpretations and word choices in generating responses.

I've had low-level involvement in several research projects at work using LLMs over the last few months. When testing these kinds of systems you will typically want to evaluate the correctness, appropriateness, and relevance of the responses but, in one of the experiments I was running recently, the interesting question was whether two implementations we had built varied to a comparable extent. 

If you like that kind of thing (and I do) you could frame it this way:

is the variability variable?

To investigate it, I needed three things:

  • a variability metric
  • a way to calculate the metric
  • a comparison function for those metrics across systems under test 

Although the output of the system I was looking at was textual, it was possible to extract a list of key items from the response and ignore most of the text. For instance, in three responses to the same prompt I might identify five concepts:

... A ... B ... C ... D ... E ...
... B ... A ... D ... C ... E ...
... A ... B ... C ... F ... E ...

Then my simple-minded metric simply counted the number of uniquely ordered lists generated by some number of runs for that prompt. In the example above, this would be three because no two rows are the same.

It's an easy metric to calculate given that I can extract the key concepts, so the question then turns to how to compare these metrics across two variants of a system under test.

My instinct was that there would be statistical approaches that could be applied but I'm as qualified in statistics as I am in AI. I thought that I wanted something

  • quick and simple for a non-expert to conceptualise and interpret
  • easy to implement in Google Sheets
  • with no strong assumptions about the source data

So I asked a friendly statistician who, like a good tester, knew how to ask scoping questions, gauge the level at which a client is able to hold a conversation, and provide relevant information concisely. Given what I was able to tell her about my needs, she pointed me at the paired t-test and its documentation in Google Sheets.

Bingo! I had a metric, a way to calculate the metric, and a way to compare across implementations of the system under test. 

Here's an example showing how it might work:

Each row (Run) represents a different prompt submitted 100 times while columns represent the implementations. Baseline is an existing implementation and SUT (System Under Test) 1 and 2 are alternative approaches. 

The values represent the variation in response for each run according to my crude metric, i.e. how many unique lists there were. So, for prompts 4 and 5, SUT 1 generates many more response variants than the other two.  

The heatmap and the means give us an intuitive sense that SUT 2 is "close" to the Baseline while SUT 1 is further away. 

The pairs of the paired t-test are the values being compared for each row, so in the analysis of Baseline against SUT 1 the first few pairs are (21, 47), (22, 39), and (53,44).

The p-values show the result of running the paired t-test on the SUT columns against the baseline. The function is pretty straightforward:

Now, starting with the null hypothesis that the SUTs vary the same amount as the Baseline, if we apply a hypothesis test at the 5% level we see that SUT 1 is less than 0.05, suggesting it is different to Baseline, while SUT 2 is greater and so suggests similar variation to Baseline.

Neat, right? Our intuitive reaction to the data is apparently backed up by some basic statistics.

But.

But we're testers aren't we, so we want to test the way we analyse our data and the conclusions we're comfortable drawing from that analysis. So I mocked up some more data and ran the same analysis process.

MOCK 3 and MOCK 4 are attempts to see how the system behaves at limits. MOCK 3 is deliberately very different, while MOCK 4 is identical to Baseline. Notice that the p-value for MOCK 3 is small, as we would hope, but the p-value for MOCK 4 is undefined. Hmm.

I played around with small variations to MOCK 4 and found that it's quite easy for data that looks very close to the Baseline in terms of values, heatmap, and mean to have a p-value either below 0.05 (MOCK 5) or above (MOCK 6). This tests my faith in the t-test, or my understanding of it.

So why do we see this? 

From my friendly statistician again: the paired t-test works on the differences for each pair. In the image above, the differences are shown on the right, i.e. for MOCK 3 against Baseline the paired differences for the first three runs are -78, -78, and -47. The t-test assesses whether the mean of the differences is different from zero and in the case of MOCK 3 it is very different.

If we go back to SUT 1, 2 and Baseline, we can now recast the initial experiment in much more statistical language. For SUT 1, the mean of the paired differences in the number of uniquely ordered lists was statistically significantly different from zero (at the 5% significance level) suggesting a difference in variation of responses between these two implementations.  Whereas the p-value for SUT 2 and Baseline was above 0.05, supporting the hypothesis that there is no variation in response between those two implementations. 

What about MOCK 5 and MOCK 6, then? The differences there both appear close to zero to the untrained eye. 

In the case of MOCK 5, the paired values are all either 0 or 1 and the mean of the differences is 0.4. This may seems small but it's considered to be a statistically strong "signal" relative to the low level of difference in the data. It is this that gives the statistically significant result.

If this feels counter-intuitive, gloss it this way: there is relatively little difference between MOCK 5 and Baseline, but what difference there is is all in one direction (the differences are all positive). This influences the t-test outcome.

This is clear in comparison to MOCK 6 which, on the surface, looks very similar. Notice that the differences are 0, 1, and -1 and are evenly distributed either side of 0, with a mean of 0. The "signal" is weaker and so the t-test goes the other way.

To reduce the likelihood of what we might call impractical results such as these we can alter the threshold at which we accept a statistically significant result. For example, instead of testing at the 5% level and using 0.05, we could test at the 1% threshold and use 0.01.

Finally, MOCK 4 fails to yield a p-value because inside the t-test calculation there is a division by zero. That topic was discussed on Cross Validated, a statistics stack exchange.

What does this tell us? 

For me, it says that the paired t-test could be a useful tool for comparison of the variability of results in my experiments but blindly applying it is a bad idea. The statistics here are playing the part of an oracle against which I can test my intuition. However, as with any testing oracle you don't understand well, it's worth testing the oracle too.
Images: Bing Image Creator

P.S. Thank you to my friendly statistician for help and review. She knows what she's talking about but I've given her an imprecisely-specified task and interpreted her words, so any errors are mine.

Comments

  1. [[..Pingback..]]
    This article was curated as a part of #122nd Issue of Software Testing Notes Newsletter.
    https://softwaretestingnotes.substack.com/p/issue-122-software-testing-notes
    Web: https://softwaretestingnotes.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Can Code, Can't Code, Is Useful

The Association for Software Testing is crowd-sourcing a book,  Navigating the World as a Context-Driven Tester , which aims to provide  responses to common questions and statements about testing from a  context-driven perspective . It's being edited by  Lee Hawkins  who is  posing questions on  Twitter ,   LinkedIn , Mastodon , Slack , and the AST  mailing list  and then collating the replies, focusing on practice over theory. I've decided to  contribute  by answering briefly, and without a lot of editing or crafting, by imagining that I'm speaking to someone in software development who's acting in good faith, cares about their work and mine, but doesn't have much visibility of what testing can be. Perhaps you'd like to join me?   --00-- "If testers can’t code, they’re of no use to us" My first reaction is to wonder what you expect from your testers. I am immediately interested in your working context and the way

Meet Me Halfway?

  The Association for Software Testing is crowd-sourcing a book,  Navigating the World as a Context-Driven Tester , which aims to provide  responses to common questions and statements about testing from a  context-driven perspective . It's being edited by  Lee Hawkins  who is  posing questions on  Twitter ,   LinkedIn , Mastodon , Slack , and the AST  mailing list  and then collating the replies, focusing on practice over theory. I've decided to  contribute  by answering briefly, and without a lot of editing or crafting, by imagining that I'm speaking to someone in software development who's acting in good faith, cares about their work and mine, but doesn't have much visibility of what testing can be. Perhaps you'd like to join me?   --00-- "Stop answering my questions with questions." Sure, I can do that. In return, please stop asking me questions so open to interpretation that any answer would be almost meaningless and certa

Not Strictly for the Birds

  One of my chores takes me outside early in the morning and, if I time it right, I get to hear a charming chorus of birdsong from the trees in the gardens down our road, a relaxing layered soundscape of tuneful calls, chatter, and chirrupping. Interestingly, although I can tell from the number and variety of trills that there must be a large number of birds around, they are tricky to spot. I have found that by staring loosely at something, such as the silhouette of a tree's crown against the slowly brightening sky, I see more birds out of the corner of my eye than if I scan to look for them. The reason seems to be that my peripheral vision picks up movement against the wider background that direct inspection can miss. An optometrist I am not, but I do find myself staring at data a great deal, seeking relationships, patterns, or gaps. I idly wondered whether, if I filled my visual field with data, I might be able to exploit my peripheral vision in that quest. I have a wide monito

Postman Curlections

My team has been building a new service over the last few months. Until recently all the data it needs has been ingested at startup and our focus has been on the logic that processes the data, architecture, and infrastructure. This week we introduced a couple of new endpoints that enable the creation (through an HTTP POST) and update (PUT) of the fundamental data type (we call it a definition ) that the service operates on. I picked up the task of smoke testing the first implementations. I started out by asking the system under test to show me what it can do by using Postman to submit requests and inspecting the results. It was the kinds of things you'd imagine, including: submit some definitions (of various structure, size, intent, name, identifiers, etc) resubmit the same definitions (identical, sharing keys, with variations, etc) retrieve the submitted definitions (using whatever endpoints exist to show some view of them) compare definitions I submitted fro

Testers are Gate-Crashers

  The Association for Software Testing is crowd-sourcing a book,  Navigating the World as a Context-Driven Tester , which aims to provide  responses to common questions and statements about testing from a  context-driven perspective . It's being edited by  Lee Hawkins  who is  posing questions on  Twitter ,   LinkedIn , Mastodon , Slack , and the AST  mailing list  and then collating the replies, focusing on practice over theory. I've decided to  contribute  by answering briefly, and without a lot of editing or crafting, by imagining that I'm speaking to someone in software development who's acting in good faith, cares about their work and mine, but doesn't have much visibility of what testing can be. Perhaps you'd like to join me?   --00-- "Testers are the gatekeepers of quality" Instinctively I don't like the sound of that, but I wonder what you mean by it. Perhaps one or more of these? Testers set the quality sta

Vanilla Flavour Testing

I have been pairing with a new developer colleague recently. In our last session he asked me "is this normal testing?" saying that he'd never seen anything like it anywhere else that he'd worked. We finished the task we were on and then chatted about his question for a few minutes. This is a short summary of what I said. I would describe myself as context-driven . I don't take the same approach to testing every time, except in a meta way. I try to understand the important questions, who they are important to, and what the constraints on the work are. With that knowledge I look for productive, pragmatic, ways to explore whatever we're looking at to uncover valuable information or find a way to move on. I write test notes as I work in a format that I have found to be useful to me, colleagues, and stakeholders. For me, the notes should clearly state the mission and give a tl;dr summary of the findings and I like them to be public while I'm working not just w

Make, Fix, and Test

A few weeks ago, in A Good Tester is All Over the Place , Joep Schuurkes described a model of testing work based on three axes: do testing yourself or support testing by others be embedded in a team or be part of a separate team do your job or improve the system It resonated with me and the other testers I shared it with at work, and it resurfaced in my mind while I was reflecting on some of the tasks I've picked up recently and what they have involved, at least in the way I've chosen to address them. Here's three examples: Documentation Generation We have an internal tool that generates documentation in Confluence by extracting and combining images and text from a handful of sources. Although useful, it ran very slowly or not at all so one of the developers performed major surgery on it. Up to that point, I had never taken much interest in the tool and I could have safely ignored this piece of work too because it would have been tested by

Build Quality

  The Association for Software Testing is crowd-sourcing a book,  Navigating the World as a Context-Driven Tester , which aims to provide  responses to common questions and statements about testing from a  context-driven perspective . It's being edited by  Lee Hawkins  who is  posing questions on  Twitter ,   LinkedIn , Mastodon , Slack , and the AST  mailing list  and then collating the replies, focusing on practice over theory. I've decided to  contribute  by answering briefly, and without a lot of editing or crafting, by imagining that I'm speaking to someone in software development who's acting in good faith, cares about their work and mine, but doesn't have much visibility of what testing can be. Perhaps you'd like to join me?   --00-- "When the build is green, the product is of sufficient quality to release" An interesting take, and one I wouldn't agree with in general. That surprises you? Well, ho

The Best Laid Test Plans

The Association for Software Testing is crowd-sourcing a book,  Navigating the World as a Context-Driven Tester , which aims to provide  responses to common questions and statements about testing from a  context-driven perspective . It's being edited by  Lee Hawkins  who is  posing questions on  Twitter ,   LinkedIn , Mastodon , Slack , and the AST  mailing list  and then collating the replies, focusing on practice over theory. I've decided to  contribute  by answering briefly, and without a lot of editing or crafting, by imagining that I'm speaking to someone in software development who's acting in good faith, cares about their work and mine, but doesn't have much visibility of what testing can be. Perhaps you'd like to join me?   --00-- "What's the best format for a test plan?" I'll side-step the conversation about what a test plan is and just say that the format you should use is one that works for you, your coll

ChatGPTesters

The Association for Software Testing is crowd-sourcing a book,  Navigating the World as a Context-Driven Tester , which aims to provide  responses to common questions and statements about testing from a  context-driven perspective . It's being edited by  Lee Hawkins  who is  posing questions on  Twitter ,   LinkedIn , Mastodon , Slack , and the AST  mailing list  and then collating the replies, focusing on practice over theory. I've decided to  contribute  by answering briefly, and without a lot of editing or crafting, by imagining that I'm speaking to someone in software development who's acting in good faith, cares about their work and mine, but doesn't have much visibility of what testing can be. Perhaps you'd like to join me?   --00--  "Why don’t we replace the testers with AI?" We have a good relationship so I feel safe telling you that my instinctive reaction, as a member of the Tester's Union, is to ask why we don&