鲁棒性评测介绍
鲁棒性是指模型在面对不同类型的异常、噪声、干扰、变化或恶意攻击时,能够保持稳定性和高效性的能力。抽象来看,目前的基础模型(包括基于学习的深度学习模型)在给定数据输入
我们通过对实例进行扰动评估模型的鲁棒性。具体来说,我们对数据集进行不同程度的扰动,主要包括两个层面,一个是常见的现实世界中人类会犯的错误,分为三个级别:字符级别、单次级别、句子级别。字符级别包括相似字符的替换,键盘邻近字符的替换,单词级别则是词语的同义词替换以及代理模型语义空间单词的替换,句子级别主要是语言的回译。另外一个是针对性的扰动,例如采用代理模型进行对抗性的攻击。在进行上述的扰动后对于不同的原始数据集我们生成了不同的扰动数据集,通过评估模型在扰动数据集上的评测结果来计算模型在该数据集上的鲁棒性指标。
评测数据集
IMDB
鲁棒性数据集的构建有两个方面,一个是不采用代理模型评估扰动结果,扰动分为字符级别,单词级别,另一个是采用对抗性扰动算法,通过代理模型对结果进行扰动,目标是在指定次数内,最大可能扰乱代理模型的结果。
扰动后数据集名称如下:
扰动数据集名称 | 扰动方法 |
---|---|
C-keyboard | disturbance-char-keyboard |
C-ocr | disturbance-char-ocr |
W-synonym | disturbance-word-synonym |
W-wordembedding | disturbance-word-word-embedding |
S-backtranslation | disturbance-sentence-back-translation |
C、W、S、Adv分别是Char、Word、Sentence、adversarial的缩写
字符级别
随机挑选3到15个单词,每个单词挑选1到2个字符进行替换,扰动方式如下
ocr(o—>0)
ocr imdb扰动数据集样例
{ "label":0, "text":"I found this movie keally hard to sit through, my attention kept wandering off the tv. As far as romantic movies go. . this one is the worst I ' ve seen. D0n ' t bother with it." }
keyboard(f—>E)
keyboard imdb扰动数据集样例
{ "label":0, "text":"I Eound this movie really hSrd to sit through, my attentioh kDpt wandering off the tv. As far as romantic movies go. . this one is the worst I ' ve seen. Don ' t boRher with it." }
单词级别
随机挑选3到15个单词进行替换,扰动方式如下
word_embedding(采用glove6B-100d模型将挑选单词替换为语义相似的单词)
word_embedding imdb扰动数据集样例
{ "label":0, "text":"I found this cast really hard to sit through, my questions kept strangers off the tv. As far as romantic movies come. . this one important the worst I ' ve seen. Don ' t bother with it." }
synonym(将挑选单词替换为同义词)
synonym imdb扰动数据集样例
{ "label":0, "text":"I found this movie really hard to sit through, my attention kept wandering away the tv. Every bit far as romantic movies go. . this one is the worst I ' ve seen. Father ' t fuss with it." }
对抗扰动
采用对抗性扰动算法为textfooler,选用代理模型为 lannelin/bert-imdb-1hidden,下面是攻击结果:
+-------------------------------+--------+ | Attack Results | | +-------------------------------+--------+ | Number of successful attacks: | 21621 | | Number of failed attacks: | 162 | | Number of skipped attacks: | 3217 | | Original accuracy: | 87.13% | | Accuracy under attack: | 0.65% | | Attack success rate: | 99.26% | | Average perturbed word %: | 3.45% | | Average num. words per input: | 230.46 | | Avg num queries: | 341.95 | +-------------------------------+--------+
测试集中共有25000条数据,代理模型的分类准确率为87.13%(Original accuracy:87.13%),即21783条样例分类正确,3217条样例分类错误。分类错误无需进行扰动,当攻击算法碰到分类错误的样例直接skip即可(Number of skipped attacks:3217)。对于代理模型分类正确的21783条数据,使用单词级别的扰动对
text
进行扰动,代理模型对扰动后的文本分类错误时停止扰动,判定攻击成功(Number of successful attacks:21621),如果在达到指定次数之后代理模型仍然分类正确,则判定攻击失败(Number of failed attacks:162)。在21783条样例中,攻击成功的样例占99.26%(Attack success rate:99.26%),平均每个样例有230.46个单词(Average num. words per input:230.46),平均每个样例扰动单词占3.45%(Average perturbed word %:3.45%),平均每个样例扰动341.95次(Avg num queries:341.95)。在攻击下,代理模型的准确率为0.65%(Accuracy under attack:0.65%)。
鲁棒性指标(RB-index)
针对原始数据集以及不同的扰动数据集我们有
在该数据集上的鲁棒性指标计算公式为:
鲁棒性指标数值越小说明模型鲁棒性越好,可以为负数(多在NLP中出现)