文本分类对抗样本生成

本文复现一个基于文本的白盒算法,基于论文《TEXTBUGGER: Generating Adversarial Text AgainstReal-world Applications》

先上最终效果

No-3srcSentence:the protector you hear the name you think ah its a crappy hong kong movie guess what its not hong kong and yes it is crappy this amazingly stupid jackie chan film ruined by us yes us the americans im boiling with anger ooh i think ill jump out that window has chan as a new york cop hunting down a gang avenging the death of his buddy sounds unk its not dont waste your money renting it to prove he could make a better cop film chan made the amazing police story
No-3srcSentence:the protector you hear the name you think ah its a crappy hong kong movie guess what its not hong kong and yes it is crappy this amazingly funny jackie chan film ruined by us yes us the americans im boiling with anger ooh i think ill jump out that window has chan as a new york cop hunting down a gang avenging the death of his buddy sounds unk its not dont waste your money renting it to prove he could make a better cop film chan made the amazing police story
No-3label:negative--->positive
No-3probability:positive(0.05022594)-->positive(0.815222)
No-3mutate:type(stupid-->funny)

第一行是原始的句子
第二行是产生的对抗样本
第三行分别对应原始标签和对抗样本的标签
第四行是概率的变化,我们可以看到原始的句子判断为positive的概率0.05,对抗样本判断为positive的概率是0.81
第五行展示了生成这个对抗样本具体改动了哪些词,比如这里就是将原始句子的stupid改为了funny

模型及配置:lstm,pytorch,具体细节及源码见我的github:https://github.com/Flynn-ML2019/Adversarial_Examples_Generate  求星星

发布了200 篇原创文章 · 获赞 17 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_36328915/article/details/104638875