Let f(⋅∣x) denote the LLM's
stochastic response distribution given prompt x,
and ϕ:Y→Rd
an embedding into a low-dimensional semantic space. We test the
null hypothesis
H0:ϕ#f(⋅∣x0)=ϕ#f(⋅∣x1)
Drawing N i.i.d. samples from each side gives
empirical centroids
μ^0,μ^1∈Rd.
The test statistic is the squared distance:
Under H0, the labels
{0,1} are exchangeable, so
we approximate the null by permuting them
B times and recomputing
Tbstar. The Monte-Carlo p-value is then
The framework is model-agnostic: it treats
f as a black box and supports arbitrary
perturbations τ mapping
x0→x1=τ(x0). With K
simultaneous perturbations, control of family-wise error follows
from any standard correction.
def dbpa(f, x0, x1, phi, N=40, B=800):
# 1 · MC sample N outputs from each arm
Y0 = [f(x0) for _ in range(N)]
Y1 = [f(x1) for _ in range(N)]
# 2 · embed into low-dim semantic space
Z0 = np.stack([phi(y) for y in Y0])
Z1 = np.stack([phi(y) for y in Y1])
# 3 · observed test stat
T_obs = np.sum((Z0.mean(0) - Z1.mean(0))**2)
# 4 · permutation null
Z = np.concatenate([Z0, Z1])
T_null = np.empty(B)
for b in range(B):
idx = rng.permutation(2*N)
a, b_ = Z[idx[:N]], Z[idx[N:]]
T_null[b] = np.sum((a.mean(0) - b_.mean(0))**2)
p = (1 + (T_null >= T_obs).sum()) / (B + 1)
eff = np.linalg.norm(Z0.mean(0) - Z1.mean(0))
return DBPAResult(T=T_obs, p=p, eff=eff)