AI Wiki中文/EN

生成模型记忆:排名、重复与审计边界

Memorization in generative models

审计虚构canary,区分暴露度、采样概率与隐私保证。

本页目录直觉理解数学与方法代码实现局限与误解实验与练习研究脉络

高概率答案与记住某条记录,是两种判断

生成器给出常见短语,不等于泄露了训练记录。若它给故意插入的随机字符串异常高的似然,证据就更具体。问题需要参照:比较哪些候选、怎样干预训练,以及多像才算输出匹配?

The Secret Sharer研究人工canary,以候选排名定义暴露度。扩散模型抽取研究则为图像使用另一种近似定义,涉及距离阈值和训练集近重复。这些操作性定义支持具体调查,不是普遍隐私定义或法律判据。建议先读信息熵与生成模型。

排名先于采样概率饱和;人工canary还区分贪心选择与全局最高概率序列。
排名先于采样概率饱和;人工canary还区分贪心选择与全局最高概率序列。

排名依赖比较范围

考虑M个长度相同的人工候选标签。对计数cᵢ拟合的分类分布给每个标签分配与计数成正比的概率。向指定候选r额外插入k次:

qk(i)=ci+k1[i=r]∑jcj+k.q_k(i)=\frac{c_i+k\mathbf1[i=r]}{\sum_j c_j+k}.

这是透明的计数模型,不是神经语言模型。为便于复算,我们明确选定r;随机canary实验和真实模型还需要额外实验控制。

对等长候选,按较低对数困惑度排序等价于按较高概率排序。沿用论文定义包含同分项的约定:

rank⁡(r)=#{i:qk(i)≥qk(r)}.\operatorname{rank}(r)=\#\{i:q_k(i)\geq q_k(r)\}.

平局包含全部同分候选。因此,完全均匀模型给每个候选的排名都是M,不是第一。相对于这个明确候选空间,暴露度为:

exposure⁡(r)=log⁡2M−log⁡2rank⁡(r).\operatorname{exposure}(r)=\log_2 M-\log_2\operatorname{rank}(r).

分数比较模型产生的排序与这个空间上的均匀枚举,不直接测量互信息,也不是不依赖先验的隐私证明。即使某候选概率不变,改变比较空间也能改变暴露度。自然总体频率未必等于均匀枚举基线。

排名也不决定随机采样成功率。从同一模型独立抽K次,至少一次命中r的概率为:

P(at least one hit)=1−(1−qk(r))K.P(\text{at least one hit})=1-(1-q_k(r))^K.

它不同于按排名猜测,也不描述自适应提示或相关样本。程序用log1p与expm1保留小概率下的数值精度。

另一个量是未改变目标总体P上的表现:

NLL⁡P(qk)=−∑iP(i)log⁡qk(i).\operatorname{NLL}_P(q_k)=-\sum_iP(i)\log q_k(i).

提升插入canary的排名,可能让这个损失变差。很小的平均损失变化可以伴随罕见候选的大变化,汇总指标不能替代针对性审计。

对生成点z与训练点xⱼ,还可以明确规定近匹配诊断:

Rτ=1n∑i=1n1 ⁣[min⁡j∥zi−xj∥2d≤τ].R_\tau=\frac1n\sum_{i=1}^n\mathbf1\!\left[\min_j\frac{\|z_i-x_j\|_2}{\sqrt d}\leq\tau\right].

这里的RMS度量是玩具实验自己的选择,不复现图像论文的具体实现。结果依赖单位、表示、阈值和参考集合。仅凭接近某点,不能证明输出因果依赖于某次具体训练收录。

插入人工符号,枚举其排名

保存为generative_memorization.py,使用Python3.12与NumPy1.26.4。64个候选都是人工符号,基线计数从64递减到1。所选canary为symbol-63,原先最少见;不涉及个人信息、外部模型或真实秘密。

"""Original finite canary audit; every label and observation is artificial."""
import json
import numpy as np


def prob(p):
    p = np.asarray(p, dtype=float)
    if p.ndim != 1 or not 2 <= len(p) <= 4096 or not np.isfinite(p).all() or np.any(p < 0) or not np.isclose(p.sum(), 1, atol=1e-12, rtol=0):
        raise ValueError('Expected a normalized finite candidate distribution')
    return p


def exposure(p, index):
    p = prob(p)
    if type(index) is not int or not 0 <= index < len(p): raise ValueError('Invalid candidate index')
    # Equal length candidates: lower log-perplexity means higher probability.
    rank = int(np.count_nonzero(p >= p[index]))
    return rank, float(np.log2(len(p))-np.log2(rank))


def fit_counts(counts, additional=0, index=63):
    counts = np.asarray(counts)
    if counts.ndim != 1 or not 2 <= len(counts) <= 4096 or counts.dtype.kind not in 'iu' or np.any(counts < 0) or counts.sum() <= 0:
        raise ValueError('Expected nonnegative integer counts')
    if type(additional) is not int or not 0 <= additional <= 100000 or type(index) is not int or not 0 <= index < len(counts):
        raise ValueError('Invalid insertion')
    updated = counts.astype(float); updated[index] += additional
    return updated/updated.sum()


def hit_probability(p, budget):
    if isinstance(p, (bool, np.bool_)) or not np.isfinite(p) or not 0 <= p <= 1 or type(budget) is not int or not 0 <= budget <= 100000:
        raise ValueError('Probability and nonnegative integer budget required')
    if budget == 0 or p == 0: return 0.
    if p == 1: return 1.
    return float(-np.expm1(budget*np.log1p(-p)))


def greedy_bits(p):
    p = prob(p); n = int(np.log2(len(p)))
    if 2**n != len(p): raise ValueError('Binary candidate space required')
    left, right = 0, len(p)
    while right-left > 1:
        middle = (left+right)//2
        if p[left:middle].sum() >= p[middle:right].sum(): right = middle
        else: left = middle
    return left


def nearest_rates(training, samples, thresholds):
    training, samples = np.asarray(training, dtype=float), np.asarray(samples, dtype=float)
    thresholds = np.asarray(thresholds, dtype=float)
    if training.ndim != 2 or samples.ndim != 2 or min(len(training), len(samples)) < 1 or training.shape[1] != samples.shape[1] or training.shape[1] < 1 or not np.isfinite(training).all() or not np.isfinite(samples).all() or thresholds.ndim != 1 or not np.isfinite(thresholds).all() or np.any(thresholds < 0):
        raise ValueError('Finite point matrices and nonnegative thresholds required')
    rms = np.sqrt(np.mean((samples[:, None]-training[None])**2, axis=-1)).min(axis=1)
    return [float(np.mean(rms <= t)) for t in thresholds]


def demo():
    counts = np.arange(64, 0, -1); true = fit_counts(counts); rows = []
    for copies in [0, 16, 63, 64, 256]:
        q = fit_counts(counts, copies); rank, bits = exposure(q, 63)
        rows.append(dict(extra_copies=copies, rank=rank, exposure_bits=bits, canary_probability=float(q[63]),
                         hit_in_100=hit_probability(q[63], 100), population_nll=float(-true @ np.log(q))))
    p = np.array([.30, .29, .01, .40])
    return dict(candidate_count=64, artificial_canary='symbol-63', experiments=rows,
                uniform_exposure=exposure(np.ones(64)/64, 63)[1],
                greedy_counterexample=dict(probabilities=p.tolist(), greedy_index=greedy_bits(p), global_mode=int(p.argmax())),
                nearest_example=dict(thresholds=[0, .49, .5, 1], rates=nearest_rates([[-1], [1]], [[-1], [0], [.5]], [0, .49, .5, 1])),
                scope='Artificial categorical counts and points; exposure is a specified-space audit, not a neural-model extraction result or privacy guarantee.')


if __name__ == '__main__': print(json.dumps(demo(), indent=2))

不额外插入时,canary排名64,暴露度为零。额外插入63次,它与最高频符号同为64次:包含平局的排名为二,暴露度五比特。插入64次后独占第一,暴露度六比特,概率却只有65/2144,约.0303。独立抽一百次的命中概率约.954。插入256次仍是相同最大暴露度,概率却升至约.110。排名已饱和,概率没有。

额外插入64次后,基线总体NLL从约3.97326升到4.00156。另一个序列分布[.30,.29,.01,.40]给出不同提醒:贪心前缀采样选择二进制00,但概率最高的完整序列是11。完整序列排名靠前,不等于某个解码器一定能找到它。

计算一个候选的排名需要O(M),完整排序需要O(M log M)。序列空间变大后,精确枚举很快不可行。玩具近邻函数需要O(nmd),并构造相应中间量;它明确只处理小点集,不是可扩展图像搜索系统。

审计未发现问题,不等于普遍保证

图像抽取定义区分某条训练样本的近副本与其他可识别的生成图像。距离阈值可能漏掉变换,也可能把常见结构判成匹配。论文还把可抽取性与训练集近重复次数区分开。这里没有运行抽取流程,也不能从分类计数例子推断现代模型的行为。

记录候选构造、插入次数、模型访问方式、采样或搜索预算、相似规则和比较总体;明确报告同分。审计可能漏掉另一个提示、数据子群或攻击者。反过来,若微小支持集只包含训练中见过的状态,即使没有针对某条样本的记忆,也必然出现精确匹配,参见合成表格例子。

区分几种不同的概率

  1. 计算。 为什么额外63次只有五比特暴露度,而不是六比特? 答案:计数变成64,与另一个候选平局。包含同分项的排名为二,所以log₂64−log₂2=5。
  2. 解释。 六比特暴露度表示一次采样几乎必定命中吗? 答案:不表示。额外64次时概率只有65/2144;暴露度使用排名,随机采样使用概率质量。
  3. 诊断。 四序列例子中,贪心为什么错过概率.40的序列? 答案:首位为零的分支总质量.59,大于首位为一的.41。贪心先选前者,再输出其中概率.30的序列。
  4. 迁移。 增大近匹配阈值会发生什么? 答案:在度量和参考集合不变时,匹配率不会下降。这是审计定义变化,不是生成器记忆发生变化。

用具体定义让判断可检验

Canary暴露度与近似图像抽取使不同问题可以测量,价值来自明确假设与证据。有限实验解释排名、质量和阈值,不建立隐私保证,也不复现神经模型攻击。

先判断,再看解释

暴露度达到最大,就意味着一次采样几乎必定命中吗?

选择一个答案

学习目标

  • 按明确同分规则计算暴露度。
  • 区分排名与采样成功率。
  • 说明近匹配审计的局限。

先修与延伸

查看知识关联图 →

参考文献

  1. The Secret Sharer: Evaluating and Testing Unintended Memorization in Neural Networks (USENIX2019)
    Nicholas Carlini; Chang Liu; Úlfar Erlingsson; Jernej Kos; Dawn Song · 2019
  2. Extracting Training Data from Diffusion Models (v1)
    Nicholas Carlini; Jamie Hayes; Milad Nasr; Matthew Jagielski; Vikash Sehwag; Florian Tramèr; Borja Balle; Daphne Ippolito; Eric Wallace · 2023

版本1 · 编写状态: 已完成记录中的技术复核

查看技术检查记录(AI)

Codex · 2026-09-20 · Single AI author checked Secret Sharer artificial-canary setup/section4.2/opening4.3 and Diffusion Extraction v1 section4.1/opening4.2. Six paired equations and four explained exercises; original64-symbol count intervention, inclusive tie rank, exposure, hit probability, greedy counterexample and declared toy RMS near-match rates. No real secrets, neural-model attack or general privacy claim.

  • 核含平局排名、空间大小、暴露度与命中概率、总体损失及贪心反例;人工指定canary,无真实个人数据或隐私保证。
  • 每题四张计算SVG;15数值/几何与36响应式组合通过,实看12张最终中文手机/英文桌面图。初版文案整理和英文手机标题越界修正保留;完整页面验收另记。

核对的来源位置:

相关主题

没有匹配结果,试试英文名或缩写。

已显示 0 条结果

将整个查询放入双引号,可按短语匹配。