说话人识别:注册、评分与身份判断
Speaker recognition
推导注意力池化,比较开闭集判断,用可核算例子区分EER与成本阈值。
speaker-recognition听起来熟悉,只是一个待检验的判断
设想一个小档案库保存了三位已知说话人的多段录音。现在来了一段新录音。“三个人中谁听起来最像?”与“这真的是声称的那个人吗?”是两个问题。前者总能选出第一名,后者需要拒绝不可靠匹配的办法。说话人识别包括身份辨认与身份验证,关注谁在说话,而不是说了哪些词。
注册录音提供某个人的参考,测试录音提供新证据。闭集辨认必须从已注册身份中选一个;开集任务允许回答未知说话人。验证则针对一个声称的身份,在同人和异人假设之间作判断。文本相关系统限制所说内容;文本无关系统不要求录音使用同一句话。这里讨论的x-vector论文实验属于文本无关识别。说话人表示
有用的表示应容忍部分录音条件变化,同时保留人的差异。“相似度高”和神经网络训练类别都不能自动证明身份。下面分开表示、注册、评分与决策,再看为什么等错误率所对应的阈值,会不同于应用成本偏好的阈值。
从长短不同的语音走到一个决定
训练分类器也能提供可复用表示
声学前端把波形变成帧,说话人编码器再把帧序列映射到固定维度的嵌入向量。传统i-vector系统从背景声学模型的统计量得到紧凑表示;x-vector系统通过说话人分类学习编码器,再交给独立后端比较嵌入。2018年论文中的帧网络连接均值/标准差池化及片段层,x-vector取自某个片段层非线性之前。这是该论文报告的配方,不是所有说话人编码器的定义。X-vector架构与后端
设有条带标签训练录音、个训练说话人,正确类别为,一种基本训练目标是说话人交叉熵。输出类别对应训练身份,因此仅靠这个softmax不能直接辨认未来所有新注册的人:
后续架构改变了帧处理与池化方式。ECAPA-TDNN结合通道加权、残差多尺度处理和多层特征,其注意力池化可以给不同通道分配不同的时间权重。下面的数值例子只研究给定特征与注意力logits的池化操作,不实现产生它们的网络。ECAPA方法
对帧、通道的供给特征,是帧值,是供给注意力logit。每个通道分别沿时间归一化,再拼接加权均值与标准差:
程序取,使常数通道也有有限导数。这是对数学标准差明确加入的稳定项,不是样本方差的无偏修正。所有注意力logit为零时就是均匀权重。一起重排供给的帧/logit对不会改变这些统计;前面的时序编码器对原始音频重排未必不变。加权统计
为单独检查反向传播,给定均值与标准差的上游敏感度,把注意力logits当作独立输入,求导得到:
第一个式子改变帧值而固定权重,第二个式子对归一化权重求导,因此每个通道的logit导数和为零。如果另一个网络从帧计算注意力,还要加上那条路径的链式贡献。这里用两组独立有限差分分别检查两种偏导。
注册方式决定比较什么
本基线先把某个人每条录音的供给嵌入单位化,平均后再单位化,让每条录音的方向具有相同权重。这不同于先平均原向量:后一种方式可能让大模长向量占主导。记,为第个人的注册录音数,为测试向量:
零向量和注册方向完全抵消的情况都会被拒绝。闭集辨认即使分数低也选;本开集基线在低于时返回未知。验证任务则只比较声称身份的画像。余弦分数是基于夹角的相似度,不是身份后验概率。x-vector论文采用训练过的PLDA后端,ECAPA也讨论余弦评分;本例的注册平均规则是明确给出的教学选择。评分后端 嵌入比较
分数需要阈值和评价协议
同人试验中注册与测试身份一致,异人试验则不一致。分数时接受。在两类试验均非空的条件下,漏拒率与误接收率为:
提高阈值通常减少误接收,同时增加漏拒。ROC用假阳性率和真阳性率表示这种取舍;DET把两类错误率画在正态分位数坐标上。NIST的历史总结区分错误权衡曲线、等错误操作点与应用加权检测成本。评价指标
设为假定的同人先验,为两类错误成本。归一化检测成本用“总拒绝”和“总接受”中较便宜的固定决策作比较基线:
先验是应用假设,不一定等于测试文件中同人试验的占比。最小DCF在给定分数上扫描阈值,描述该成本条件下的区分能力;在测试集上据此选阈值,不能诚实地估计部署策略。应在独立开发数据上选择并校准阈值,再报告留出数据上的成本。历史成本设置需要标明评价版本。成本与先验
某个实际阈值若使漏拒率等于误接收率,等错误率(EER)便直接可得。但有限分数集,尤其存在同分时,可能根本没有这样的阈值。代码让同分试验一起跨过阈值;必要时在相邻操作点间插值。令、:
这是两种决策策略的混合,不保证有一个确定阈值能实现插值错误率。一个同人和一个异人试验分数相同时,确定策略只能全收或全拒。插值EER为0.5,但这两个策略都无法使两类错误率同时为0.5。
一个小生成模型解释另一种评分
为了在不训练完整PLDA系统的情况下理解似然比,明确假设中心化嵌入满足:身份成分,独立录音噪声。同人录音共享,异人录音的身份成分独立。把一对向量拼为,联合协方差和对数似然比为:
非对角块表达共享身份。程序接收给定正定协方差,用Cholesky求解,不估计或。时,得分约0.310508,约−0.356159。它是这个虚构Gaussian模型下的似然比,不是经过真实人声校准的分数。
运行组件,比较决定
把程序保存为speaker.py,使用Python 3.12和NumPy 1.26.4运行python speaker.py。数组全部本地生成。池化最多接受32帧、16通道;阈值扫描最多64个试验。为避免浮点下溢,先验限于,成本限于;Gaussian辅助函数最多六维,要求协方差特征值至少。
"""Original bounded pooling, enrollment and verification math; no speech model."""
import json
import numpy as np
def real(values, ndim):
x = np.asarray(values)
if x.ndim != ndim or x.dtype.kind not in 'fiu':
raise ValueError('Real numeric array of declared rank required')
x = x.astype(float)
if not np.isfinite(x).all() or np.max(abs(x), initial=0) > 20:
raise ValueError('Finite entries within +/-20 required')
return x
def pooling(frames, attention=None):
x = real(frames, 2)
if not (1 <= len(x) <= 32 and 1 <= x.shape[1] <= 16):
raise ValueError('Use 1..32 frames and 1..16 channels')
a = np.zeros_like(x) if attention is None else real(attention, 2)
if a.shape != x.shape:
raise ValueError('One supplied attention logit per frame/channel')
exp = np.exp(a-a.max(axis=0, keepdims=True)); weights = exp/exp.sum(axis=0)
mean = (weights*x).sum(axis=0)
variance = (weights*(x-mean)**2).sum(axis=0)
std = np.sqrt(variance+1e-8)
return dict(mean=mean, variance=variance, std=std, weights=weights,
pooled=np.concatenate([mean,std]), epsilon=1e-8)
def pooling_vjp(frames, attention, upstream):
x = real(frames, 2); r = pooling(x, attention); u = real(upstream, 1)
if u.shape != (2*x.shape[1],):raise ValueError('Mean and std sensitivities required')
um, us = np.split(u, 2); w, mu, std = r['weights'], r['mean'], r['std']
dx = w*(um+us*(x-mu)/std)
score = um*x+us*(x-mu)**2/(2*std)
da = w*(score-(w*score).sum(axis=0))
return dict(frames=dx, attention=da)
def unit(vectors):
x = real(vectors, 2)
if not (1 <= len(x) <= 32 and 1 <= x.shape[1] <= 16):
raise ValueError('Use a small matrix of embeddings')
norm = np.linalg.norm(x, axis=1, keepdims=True)
if (norm < 1e-10).any():raise ValueError('Zero or cancelled embeddings have no direction')
return x/norm
def enroll(recordings):
return unit(unit(recordings).mean(axis=0, keepdims=True))[0]
def identify(queries, profiles, threshold=.7):
q, p = unit(queries), unit(profiles)
if q.shape[1] != p.shape[1]:raise ValueError('Matching embedding dimensions required')
if type(threshold) not in (int,float) or not -1 <= threshold <= 1:
raise ValueError('Cosine threshold in [-1,1] required')
scores = np.clip(q@p.T, -1, 1); best = scores.argmax(axis=1)
labels = [int(k) if scores[t,k] >= threshold else None for t,k in enumerate(best)]
return dict(scores=scores, closed_set=best, open_set=labels)
def operating_curve(scores, target, prior=.01, miss_cost=10., false_cost=1.):
s = real(scores, 1); y = np.asarray(target)
if not 2 <= len(s) <= 64 or y.shape != s.shape or y.dtype.kind != 'b' or not y.any() or y.all():
raise ValueError('Boolean target/non-target trials, both classes nonempty')
for value in [prior,miss_cost,false_cost]:
if type(value) not in (int,float) or not np.isfinite(value):raise ValueError('Finite numeric costs and prior')
if not 1e-6 <= prior <= 1-1e-6 or not 1e-6 <= miss_cost <= 100 or not 1e-6 <= false_cost <= 100:
raise ValueError('Prior in [1e-6,1-1e-6], costs in [1e-6,100] required')
rows=[];normalizer=min(miss_cost*prior,false_cost*(1-prior))
for threshold in [None]+sorted(set(s.tolist()),reverse=True):
accept=np.zeros(len(s),dtype=bool) if threshold is None else s>=threshold
miss=float(np.mean(~accept[y]));false=float(np.mean(accept[~y]))
cost=miss_cost*prior*miss+false_cost*(1-prior)*false
rows.append(dict(threshold=threshold,miss=miss,false_alarm=false,cost=cost,normalized=cost/normalizer))
equal=None
for i,row in enumerate(rows):
difference=row['miss']-row['false_alarm']
if difference==0:
equal=dict(rate=row['miss'],indices=[i,i],mix=0.,attainable=True);break
if difference<0:
before=rows[i-1];previous=before['miss']-before['false_alarm'];mix=previous/(previous-difference)
rate=(1-mix)*before['miss']+mix*row['miss']
equal=dict(rate=rate,indices=[i-1,i],mix=mix,attainable=False);break
best=min(range(len(rows)),key=lambda i:rows[i]['cost'])
return dict(points=rows,eer=equal,min_dcf_index=best,min_dcf=rows[best]['normalized'],
normalizer=normalizer,prior=prior,rule='accept score >= threshold; None rejects all')
def gaussian_llr(first, second, between, within):
x, y = real(first, 1), real(second, 1)
b, w = real(between, 2), real(within, 2);d=len(x)
if not 1 <= d <= 6 or y.shape != x.shape or b.shape != (d,d) or w.shape != (d,d):
raise ValueError('Two centered vectors and matching small covariance matrices')
for cov in [b,w]:
if not np.allclose(cov,cov.T,rtol=0,atol=1e-12) or np.linalg.eigvalsh(cov).min()<1e-8:
raise ValueError('Symmetric covariance with eigenvalues >=1e-8 required')
total=b+w;zero=np.zeros_like(total)
same=np.block([[total,b],[b,total]]);different=np.block([[total,zero],[zero,total]])
z=np.concatenate([x,y])
def log_density(cov):
ch=np.linalg.cholesky(cov);v=np.linalg.solve(ch,z)
return -.5*(len(z)*np.log(2*np.pi)+2*np.log(np.diag(ch)).sum()+v@v)
return float(log_density(same)-log_density(different))
def clean(x):
if isinstance(x,np.ndarray):return x.tolist()
if isinstance(x,dict):return {k:clean(v) for k,v in x.items()}
if isinstance(x,(list,tuple)):return [clean(v) for v in x]
if isinstance(x,np.generic):return x.item()
return x
def demo():
frames=np.array([[1.,0],[1.,2],[3.,0],[3.,2]])
attention=np.array([[0.,1],[0.,1],[2.,-1],[2.,-1]])
profiles=np.array([enroll([[1,.1],[1,-.1]]),enroll([[.1,1],[-.1,1]])])
s=[.9,.8,.5,.2,.8,.4,.3,.1];target=[True]*4+[False]*4
return clean(dict(frames=frames,attention=attention,uniform=pooling(frames),attentive=pooling(frames,attention),
profiles=profiles,identification=identify([[1,.2],[.1,1],[-1,-1]],profiles),
curve=operating_curve(s,target),balanced_curve=operating_curve(s,target,prior=.5,miss_cost=1),
tied=operating_curve([.5,.5],[True,False]),
gaussian=dict(same=gaussian_llr([1],[1],[[1]],[[1]]),opposite=gaussian_llr([1],[-1],[[1]],[[1]])),
scope='Synthetic supplied features/scores/covariances; no neural speaker encoder or corpus benchmark.'))
if __name__=='__main__':print(json.dumps(demo(),ensure_ascii=False,indent=2,allow_nan=False))
四帧在均匀权重下均值为、方差为。改变注意力可以在帧值不变时改变池化表示。两个注册画像与三个查询比较:闭集规则给每个查询分配身份,开集规则拒绝给定的负方向查询。这说明一种决策规则,不是测量了某个说话人模型。
独立试验例子使用同人分数[.9, .8, .5, .2]和异人分数[.8, .4, .3, .1]。阈值0.5时EER为0.25;先验0.01、漏拒/误接收成本10/1时,阈值0.9取得最小归一化成本0.75。只改先验与成本,错误率点不变,偏好的操作点却会改变。
池化及两种导数的时间、空间均为。个查询和个画像比较耗时,保存分数。本简单扫描对每个不同阈值重扫全部个试验,时间为、结果空间为;累计计数实现可避免重复扫描。Gaussian计算耗时、空间。这些都不含声学编码器推理。
别让方便的分数代替识别质量
设备、信道、说话时长与语言不同,都会改变编码器可利用的证据。2018年x-vector研究明确区分不同评价数据,并在扩充数据时去掉训练与测试间重叠的说话人身份。报告的收益对应其协议,本篇没有复现成绩表。只按片段划分可能让相同说话人或录音条件同时出现在两侧,应明确要检验的是新身份、新会话,还是两者兼有。实验设置
池化会丢信息。均值和方差无法重建帧次序,短录音的估计可能不稳定,注意力也可能突出无用区域。本供给向量程序无法判断录音来自现场、回放还是生成内容。身份分数与真实性检查是两种声明。
报告结果时,应给出试验构造、注册数量、时长条件、分数方向、阈值规则和成本。EER不能单独说明在要求低误接收的操作点上表现如何;最小成本也不能单独证明校准或部署效果。关于指标定义与决策成本,可继续阅读模型评测。
哪种变化会影响答案?
-
闭集分类器把陌生声音分给A,是否说明A说了这段话?
答案:不能。闭集辨认必须选一个已注册类别;验证或开集规则还需要拒绝标准。例子中的负方向查询仍得到闭集索引,但因低于开集阈值而被拒绝。
-
注册嵌入为与,程序会给出什么画像?它和单位化原始平均有什么区别?
答案:先分别变成与,平均方向为。若先平均原向量再单位化,则为,较大模长向量影响更大。“平均”一词没有自动规定哪一种,应明确实际规则。
-
一个同人和一个异人试验都得0.5,确定的
score >= threshold规则能否实现漏拒率、误接收率都为0.5?答案:不能。阈值不大于0.5时全收,错误率为;大于0.5时全拒,得到。两种策略等比例混合给出插值EER 0.5,所以代码标记它不能由单一阈值实现。
-
试验分数不变,但误接收的成本提高很多。EER一定改变吗?部署阈值应一直不变吗?
答案:EER不依赖这些成本,同一分数曲线仍给出同一EER;成本最小的阈值可能变化。应依据开发数据及预期先验/成本选择阈值,再在留出试验上检验固定策略,不能利用最终测试标签调参。
把表示与评价一起读
x-vector论文解释可学习表示与评分后端的分工,ECAPA解释后续架构和逐通道池化,NIST总结说明为什么必须明确试验、操作点与成本。上面的导数和小Gaussian例子均在给定假设下独立计算。来源说明区分了实际核读的方法章节与未复现的成绩表。X-vectors ECAPA-TDNN NIST评价
先判断,再看解释
同分的同人/异人试验,能用一个确定阈值实现插值EER0.5吗?
学习目标
- 区分训练身份、注册画像与验证试验。
- 对供给注意力统计求导,并说明未实现的网络路径。
- 解释EER插值、同人先验与最小检测成本。
- 在明确假设下计算Gaussian同人/异人似然比。
先修与延伸
查看知识关联图 →参考文献
- X-vectors: Robust DNN Embeddings for Speaker Recognition
David Snyder, Daniel Garcia-Romero, Gregory Sell, Daniel Povey, Sanjeev Khudanpur · 2018 - ECAPA-TDNN: Emphasized Channel Attention, Propagation and Aggregation in TDNN Based Speaker Verification
Brecht Desplanques, Jenthe Thienpondt, Kris Demuynck · 2020 - NIST Speaker Recognition Evaluation Chronicles
Mark A. Przybocki, Alvin F. Martin · 2004
版本1 · 编写状态: 已完成记录中的技术复核
查看技术检查记录(AI)
Codex · 2026-09-13 · Single AI author checked x-vector and ECAPA channel-weighted pooling, supplied-attention VJP and its missing upstream chain, normalized enrollment and open-set thresholds, ties and EER interpolation, application prior and minimum normalized DCF, and supplied Gaussian same/different covariance likelihoods against scoped original papers and NIST2004. Eight paired equations and four explained exercises; original component computations, not a trained identity model or measured speaker accuracy.
- 核验pooling/VJP有限差分、通道归一化、注册抵消与拒绝、同分时不可单阈值实现的EER0.5、EER0.25与阈值0.9的minDCF0.75,以及有下界正定协方差下Gaussian评分0.3105077和-0.3561590。
- 四张计算SVG绑定真实双语程序;本组三题十项数值/编码检查、18组语言/宽度及四字体检查通过,AI作者实际查看六张代表截图。冻结前检查普通正文AST;完整文章页面验收另记,不称人工同行审校。
核对的来源位置:
- X-vectors: Robust DNN Embeddings for Speaker Recognition · Read abstract/introduction,2.3/Table1,2.4 and3.1–3.2 setup fragments; visually inspected physical page2. Uses pooling/embedding/backend and protocol distinctions, not replicated data volumes, parameter totals or benchmarks.
- ECAPA-TDNN: Emphasized Channel Attention, Propagation and Aggregation in TDNN Based Speaker Verification · Read abstract/introduction,2.1 and3.1–3.3; visually inspected physical page2 equations1–7. Original example implements supplied channel attention statistics and derivatives only. Section4 MFCC/log-Mel wording is not reconciled or adopted as an exact frontend.
- NIST Speaker Recognition Evaluation Chronicles · Read and visually inspected physical page1 task and sections2.1–2.3 cost, prior, EER and DET. Year2004 confirmed from NIST publication metadata. Historical10/1/.01 costs are not every evaluation version; our finite-score EER interpolation is explicitly stated.
相关主题