当前位置: 首页 > news >正文

文本对抗样本系列的论文阅读笔记(整理合订)

文本对抗样本系列的论文阅读笔记

以前调研文本对抗样本时的论文笔记梳理,论文都很经典,有现成的框架(TextAttack)可以直接用,论文中部分内容直接是截取自论文,所以存在中英混合笔记的情况。

BERT-Attack

作者:Linyang Li, Ruotian Ma, et al.

单位:复旦大学

来源:EMNLP 2020

Introduction

对抗样本:imperceptible to human judges while they can mislead the neural networks to incorrect predictions.

文本对抗样本与图像对抗样本的区别:

  1. imperceptible to human judges & misleading to models

  2. fluent in grammar and semantically consistent with original inputs

先前的工作特点:

  1. based on specific rules

  2. difficult to guarantee the fluency and semantically preservation in the generated adversarial samples at the same time.

  3. rather complicated

核心思想:将BERT当作对抗样本的生成器,生成对抗样本

BERT-Attack的优势:

  1. Training -> Semantic-preserving

  2. Context around -> fluent & reasonable

  3. inference the language model once as a perturbation generator rather than repeatedly using language models to score the generated adversarial samples in a trial and error process

实验效果:successfully fooled the downstream models

Related Work

character-level heuristic rules: Jin et al. 2019

substituting words with synonyms: Ren et.al 2019, Li et al. 2018

score perturbations by searching for close meaning words in the embedding space: Alzantot et al. 2018

semantically enhanced embedding but context unaware: Jin et al. 2019

replace words manually to break the language inference system: Glockner et al. 2018

replacement strategies using embedding transition: Lei et al. 2019

Method

两个步骤:

  1. finding the vulnerable words of target model

  2. replacing the vulnerable words with semantically similar and grammatically correct words until a successful attack

Finding Vulnerable Words

输入序列: S = [ w 0 , ⋯ , w i , ⋯ ] S=[w_0,\cdots,w_i,\cdots] S=[w0,,wi,]

o y ( S ) o_y(S) oy(S):目标模型正确标签的logit输出

重要性分数: I w i = o y ( S ) − o y ( S / w i ) I_{w_i}=o_y(S)-o_y(S_{/w_i}) Iwi=oy(S)oy(S/wi),其中 S / w i = [ w 0 , ⋯ , w i − 1 , [ M A S K ] , w i + 1 , ⋯ ] S_{/w_i}=[w_0,\cdots,w_{i-1},[MASK],w_{i+1},\cdots] S/wi=[w0,,wi1,[MASK],wi+1,]

将评分排序,创造单词列表 L L L,取前 ϵ \epsilon ϵ分数的单词作为攻击单词目标

Word Replacement via BERT

Previous approaches: 多个人工规则,例如Synonym dictionary(Ren et al. 2019)、POS Checker(Jin et al. 2019),Semantic Similarity Checker(Jin et al. 2019)

这些替代策略缺陷:

  1. unaware of the context between the substitution position

  2. insufficient in fluency control and semantic consistency

使用BERT进行替代策略解决fluency control与semantic preservation的问题:

在这里插入图片描述

算法流程:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

BPE算法将 S S S进一步分词为 H = [ h 0 , h 1 , ⋯ ] H=[h_0,h_1,\cdots] H=[h0,h1,],因此需要进行分词对齐

M M M表示为BERT模型,则输出结果为 P = M ( H ) P=M(H) P=M(H)。在每个位置上使用最可能的 K K K词预测, K K K是超参数。遍历预测的 K K K个词,得到对抗样本

单一词:对于单词 w j w_j wj,其top- K K K个预测候选为 P j P^j Pj。通过NLTK过滤停止词,使用synonym dictionaries过滤反义词。最终构建干扰序列 H ′ = [ h 0 , ⋯ , h j − 1 , c k , h j + 1 , ⋯ ] H'=[h_0,\cdots, h_{j-1},c_k,h_{j+1},\cdots] H=[h0,,hj1,ck,hj+1,],如果能成功逆转结果,则该序列为对抗样本 H a d v H^{adv} Hadv。否则,在 L L L中查找下一个单词继续挑选最佳干扰项

分词:perplexity指标寻找合适的单词替代。给定单词 w w w的分词串 [ h 0 , h 1 , ⋯ , h t ] [h_0,h_1,\cdots,h_t] [h0,h1,,ht],根据 M M M列出来自预测 P t × K P^{t\times K} Pt×K的所有可能组合,从而通过逆转BERT分词过程以转换这些二分词到正常单词之中

实验

数据集

  • Text Classification

    • Yelp: review classification dataset

    • IMDB: document-level movie review dataset

    • AG’s News: sentence-level news-type classification dataset

    • FAKE: fake news classification dataset

  • Natural Language Inference

    • SNLIL: Stanford language INFERENCE TASK

    • MNLI: language inference dataset on multi-genre texts

Baseline: TextFooler, GA

Evaluation:

  1. Attacked Accuracy

  2. Perturb Percentage

  3. Query Number

  4. Average Length

  5. Semantic Similarity (Universal Sentence Encoder)

同其他baseline比较:

样本展示:

笔记中提及的论文参考

  1. Di Jin, Zhijing Jin, Joey Tianyi Zhou, and Peter Szolovits. 2019. Is BERT really robust? natural language attack on text classification and entailment. CoRR

  2. Shuhuai Ren, Yihe Deng, Kun He, and Wanxiang Che. 2019. Generating natural language adversarial examples through probability weighted word saliency. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics

  3. Jinfeng Li, Shouling Ji, Tianyu Du, Bo Li, and Ting Wang. 2018. Textbugger: Generating adversarial text against real-world applications

  4. Moustafa Alzantot, Yash Sharma, Ahmed Elgohary, Bo-Jhang Ho, Mani B. Srivastava, and Kai-Wei Chang. 2018. Generating natural language adversarial examples. CoRR

  5. Max Glockner, Vered Shwartz, and Yoav Goldberg. 2018. Breaking nli systems with sentences that require simple lexical inferences

Semantically Equivalent Adversarial Rules for Debugging NLP Models

作者:Marco Tulio Ribeiro, Sameer Singh et al.

单位:University of Washington, University of California (Irvine)

来源:ACL 2018

Introduction

Challenges:

  1. different ways of phrasing the same sentence can often cause the model to output different predictions.

  2. oversensitivity

提出的对抗样本方法:SEA
优势:

  1. model-agnostic

  2. generate semantically equivalent rules for optimal rule sets: semantic equivalence, high adversary count, non-redundancy.

Semantically Equivalent Adversaries

给定黑盒模型 f f f,句子 x x x,预测结果为 f ( x ) f(x) f(x)

基本思想:通过调整 x x x,以改变 f ( x ) f(x) f(x)

指示函数: S e m E q ( x , x ′ ) = I [ S e m E q ( x , x ′ ) ∧ f ( x ) ≠ f ( x ′ ) ] SemEq(x,x')=\mathbb{I}[SemEq(x,x')\wedge f(x)\not=f(x')] SemEq(x,x)=I[SemEq(x,x)f(x)=f(x)]

语义分数: S ( x , x ′ ) = min ⁡ ( 1 , P ( x ′ ∣ x ) P ( x ∣ x ) ) S(x,x')=\min(1,\frac{P(x'|x)}{P(x|x)}) S(x,x)=min(1,P(xx)P(xx)),其中 P ( x ′ ∣ x ) P(x'|x) P(xx)代表的是重新调整句子 x x x后的 x ′ x' x概率

进一步有: S e m E q ( x , x ′ ) = I [ S ( x , x ′ ) ≥ τ ] SemEq(x,x')=\mathbb{I}[S(x,x')\geq \tau] SemEq(x,x)=I[S(x,x)τ]

paraphrase set via beam search: Π x \Pi_x Πx

挑选最佳的对抗样本: arg max ⁡ x ′ ∈ Π x S ( x , x ′ ) S E A x ( x ′ ) \argmax\limits_{x'\in\Pi_x}S(x,x')SEA_x(x') xΠxargmaxS(x,x)SEAx(x)

Semantically Equivalent Adversarial Rules (SEARs)

假设:人的时间受限,愿意看 B B B条规则

SEARs:给定一个参考数据集 X X X,根据 X X X选择规则集 B B B

规则形式: r = ( a → c ) r=(a\rightarrow c) r=(ac) a a a为原始单词, c c c为替代词

构建规则集:提取匹配词对,挑选最小连续序列使得 x → x ′ x\rightarrow x' xx。同时包含中间上下文, e.g. What color → \rightarrow Which color。通过粗粒度和细粒度的Part-of-Speech tags乘积泛化,如果tags能匹配上前项,则允许这些tags出现在结果之中,e.g. What NOUN → \rightarrow Which NOUN

选择规则集:给定候选规则,想要挑选规则集 R R R使得 ∣ R ∣ ≤ B |R|\leq B RB

  • 语义相等:在集合中规则的应用应该产生语义相等的实例,即: E [ S e m E q ( x , r ( x ) ) ] ≥ 1 − δ E[SemEq(x,r(x))]\geq 1-\delta E[SemEq(x,r(x))]1δ (Filter操作)

  • 高对抗样本数量:能在验证集中诱导尽可能多的SEAs,并且语义相似分数高

  • 不重复:不同的规则可能造成相同的SEAs,或者诱导不同的SEAs到相同的实例上,即目标函数: max ⁡ R , ∣ R ∣ < B ∑ x ∈ X max ⁡ r ∈ R S ( x , r ( x ) ) S E A ( x , r ( x ) ) \max\limits_{R,|R|<B}\sum\limits_{x\in X}\max\limits_{r\in R}S(x,r(x))SEA(x,r(x)) R,R<BmaxxXrRmaxS(x,r(x))SEA(x,r(x)),这是一个贪心算法、SubMod过程。

样本展示:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

User Studies

neural machine translation models parameters: default OpeNMT-py parameters

POS tagging: spacy library

SEAR generation: δ = 0.1 \delta=0.1 δ=0.1, τ = 0.0008 \tau=0.0008 τ=0.0008

VQA: telling system, questions include “What”, “Where”, “When”, “Who”, “Why”, and “How”.

Condition Study: Human, SEA, HSEA (human & SEA collaboration)

Condition Result:

专家 VS SEA

TextBugger: Generating Adversarial Text Against Real-world Applications

作者:Jingfeng Li, ShouJing Ji et al.

单位:浙江大学计算机学院

来源:NDSS 2019

Introduction

对抗攻击分类

  • causative attacks: manipulate the training data to mislead the classifiers

  • exploratory attacks: craft malicious testing instances to evade a given classifiers

文本对抗样本的挑战:

  1. discrete property, hard to optimize

  2. small perturbations are usually clearly perceptible

  3. replacement of a single word may drastically alter the semantics of the sentence

已有工作(2019年前)缺陷:

  1. not computationally efficient

  2. under the white-box setting

  3. manual intervention

  4. against a particular NLP model, not comprehensively evaluated

本文提出的TextBugger,分为白盒跟黑盒情景:

  • 白盒:通过计算分类器的Jacobian矩阵找到关键词,然后通过生成五种扰动选择最优扰动放进去

  • 黑盒:首先寻找重要句子,之后选择打分函数寻找句子中的重要单词污染语料

Attack Design

Problem Formulation

受害模型 F : X → Y F: X\rightarrow Y F:XY

语义相似指标: S : X × X → R + S:X\times X\rightarrow \mathbb{R}_+ S:X×XR+

对抗文档: F ( x ) = y F(x)=y F(x)=y, x a d v x_{adv} xadv s.t. F ( x a d v ) = t ( t ≠ y ) F(x_{adv})=t(t\not= y) F(xadv)=t(t=y), S ( x , x a d v ) ≥ ϵ ( ϵ ∈ R ) S(x,x_{adv})\geq \epsilon (\epsilon \in \mathbb{R}) S(x,xadv)ϵ(ϵR)

Threat Model

白盒设置:complete knowledge about the targeted model architecture parameters (worst-case attack)

黑盒设置:users can only access the model via an API (not aware of the model architecture)

TextBugger

白盒攻击:

  1. 寻找重要单词:给定 x = ( x 1 , x 2 , ⋯ , x N ) x=(x_1,x_2,\cdots,x_N) x=(x1,x2,,xN) x i x_i xi为第i个单词,目标模型为 F F F,则矩阵为: J F ( x ) = ∂ F ( x ) ∂ x = [ ∂ F j ( x ) ∂ x i ] i ∈ { 1 , ⋯ , N } , j ∈ { 1 , ⋯ , K } J_F(x)=\frac{\partial F(x)}{\partial x}=[\frac{\partial F_j(x)}{\partial x_i}]_{i\in\{1,\cdots,N\},j\in \{1,\cdots,K\}} JF(x)=xF(x)=[xiFj(x)]i{1,,N},j{1,,K},其中 K K K表示为标签类别数量, F j ( ⋅ ) F_j(\cdot) Fj()表示为 j t h j^{th} jth类别的confidence value,则单词 x i x_i xi的重要性为: C x i = J F ( i , y ) = ∂ F y ( x ) ∂ x i C_{x_i}=J_{F(i,y)}=\frac{\partial F_y(x)}{\partial x_i} Cxi=JF(i,y)=xiFy(x)

  2. Bugs生成:考虑字符级扰动和单词级扰动。

    • 字符级:将重要单词转化为未知单词

    • 单词级:插入、删除、交换、替代字符、替代单词

白盒攻击下的算法:

黑盒攻击:

  1. 找到重要句子:假定文档 x = ( s 1 , ⋯ , s n ) x=(s_1,\cdots,s_n) x=(s1,,sn),其中 s i s_i si表示第 i i i个句子。先使用spaCy切片每个文档到句子之中。之后通过模型查看是否与不同标签一致 ( F l ( s i ) ≠ y ) (F_l(s_i)\not=y) (Fl(si)=y),逆序排列句子重要性分数,其句子的重要性分数表示为: C s i = F y ( s i ) C_{s_i}=F_y(s_i) Csi=Fy(si)

  2. 找到重要单词:找到最重要单词,并通过控制语义相似进行修改。设计了一个新的打分函数: C w j = F y ( w 1 , w 2 , ⋯ , w m ) − F y ( w 1 , ⋯ , w j − 1 , w j + 1 , ⋯ , w m ) C_{w_j}=F_y(w_1,w_2,\cdots,w_m)-F_y(w_1,\cdots,w_{j-1},w_{j+1},\cdots,w_m) Cwj=Fy(w1,w2,,wm)Fy(w1,,wj1,wj+1,,wm)

  3. Bugs生成

Attack Evaluation

Sentiment Analysis

数据集:IMDB,Rotten Tomatoes Movie Reviews (MR)

受害模型:LR,CNN,LSTM

baseline: Random,FGSM+Nearest Neighbor Search (NNS),DeepFool+NNS

评估指标:

  • Edit Distance

  • Jaccard Similarity Coefficient: J ( A , B ) = ∣ A ∩ B ∣ ∣ A ∪ B ∣ = ∣ A ∩ B ∣ ∣ A ∣ + ∣ B ∣ − ∣ A ∩ B ∣ J(A,B)=\frac{|A\cap B|}{|A\cup B|}=\frac{|A\cap B|}{|A|+|B|-|A\cap B|} J(A,B)=ABAB=A+BABAB

  • Euclidean Distance: d ( p , q ) = ( p 1 − q 1 ) 2 + ( p 2 − q 2 ) 2 + ⋯ + ( p n − q n ) 2 d(\bold{p},\bold{q})=\sqrt{(p_1-q_1)^2+(p_2-q_2)^2+\cdots+(p_n-q_n)^2} d(p,q)=(p1q1)2+(p2q2)2++(pnqn)2

  • Semantic Similarity: S ( p , q ) = p ⋅ q ∣ ∣ p ∣ ∣ ⋅ ∣ ∣ q ∣ ∣ = ∑ i = 1 n p i × q i ∑ i n ( p i ) 2 × ∑ i = 1 n ( q i ) 2 S(\bold{p},\bold{q})=\frac{\bold{p}\cdot \bold{q}}{||\bold{p}||\cdot||\bold{q}||}=\frac{\sum^n_{i=1}p_i\times q_i}{\sqrt{\sum^n_i(p_i)^2}\times \sqrt{\sum^n_{i=1}(q_i)^2}} S(p,q)=∣∣p∣∣∣∣q∣∣pq=in(pi)2 ×i=1n(qi)2 i=1npi×qi with USE

实验发现:

  1. 这个模型效果比较好,速度也快

  2. 长文本的攻击效果弱于短文本

  3. 评分上:逆转负面评价到正面评价会部分失败

  4. 数据集上负面词多于正面词

  5. 扰动类型的影响:字符级替代最难被发现造成词表之外的现象

Toxic Content Detection

数据集:Kaggle Toxic Comment Classification competation

受害模型:LR, CNN, LSTM

实验结果:

Potential Defenses

  1. Spelling Check

  2. Adversarial Training

Generating Natural Language Adversarial Examples through Probability Weighted Word Saliency

作者:Shuhuai Ren, Yihe Deng et al.

单位:杭州科技大学、加利福尼亚大学、哈工大

Introduction

NLP对抗样本难的问题:

  1. words in sentences are discrete tokens

  2. hard in human’s perception to make sense of the texts with perturbations

本文的出发点:could guarantee the lexical correctness with little grammatical error and semantic shifting.

提出的方法:Probability Weighted Word Saliency (PWWS)

Text Classification Attack

特征空间 X X X,输出空间 Y = { y 1 , ⋯ , y K } Y=\{y_1,\cdots, y_K\} Y={y1,,yK},,目标模型 f : X → Y f:X\rightarrow Y f:XY, 正确的标签 y t r u e ∈ Y y_{true}\in Y ytrueY

Text Adversarial Example

模型分类: arg max ⁡ y i ∈ Y ( y i ∣ x ) = y t r u e \argmax\limits_{y_i\in Y}(y_i|x)=y_{true} yiYargmax(yix)=ytrue

扰动 △ x \triangle x x x ∗ = x + △ x x^*=x+\triangle x x=x+x,s.t. arg max ⁡ y i ∈ Y P ( y i ∣ x ∗ ) ≠ y t r u e \argmax\limits_{y_i\in Y}P(y_i|x^*)\not= y_{true} yiYargmaxP(yix)=ytrue

定义的对抗样本为:

x ∗ = x + △ x , ∣ ∣ △ x ∣ ∣ < ϵ arg max ⁡ y i ∈ Y P ( y i ∣ x ∗ ) ≠ arg max ⁡ y i ∈ Y P ( y i ∣ x ) x^*=x+\triangle x, ||\triangle x||< \epsilon \\\argmax\limits_{y_i\in Y} P(y_i|x^*)\not=\argmax\limits_{y_i\in Y}P(y_i|x) x=x+x,∣∣△x∣∣<ϵyiYargmaxP(yix)=yiYargmaxP(yix)

p p p范数为: ∣ ∣ △ x ∣ ∣ p = ( ∑ i = 1 n ∣ w i ∗ − w i ∣ p ) 1 p ||\triangle x||_p=(\sum^n\limits_{i=1}|w^*_i-w_i|^p)^{\frac{1}{p}} ∣∣△xp=(i=1nwiwip)p1

该论文中,通过替代输入单词的同义词(来自WordNet)并通过取代相似的命名实体(Name Entries, NE)以生成对抗样本

假定属于类别 y t r u e y_{true} ytrue的输入样本和字典 D y t r u e ⊆ D \mathbb{D}_{y_{true}}\subseteq \mathbb{D} DytrueD包含了所有出现在文中的NE,而最频繁的 N E a d v NE_{adv} NEadv存在于 D − D y t r u e \mathbb{D}-\mathbb{D}_{y_{true}} DDytrue中作为替代词。

PWWWS

PWWS属于贪心算法

单词替代策略

  1. 对于单词 w i ∈ x w_i\in x wix,首先用WordNet构建同义词集 L i ⊆ D \mathbb{L}_i\subseteq \mathbb{D} LiD,若 w i w_i wi是个命名实体,则寻找对应同类型的词放到 L i \mathbb{L}_i Li中。当 w i ′ w'_i wi影响最大时,从 L i \mathbb{L}_i Li中选择 w i ′ w'_i wi作为 w i ∗ w^*_i wi

  2. 替代词选择策略:

    • w i ∗ = R ( w i , L i ) = arg max ⁡ w i ′ ∈ L i P ( y t r u e ∣ x i ′ ) w^*_i=R(w_i,\mathbb{L}_i)=\argmax_{w'_i\in \mathbb{L}_i}{P(y_{true}|x'_i)} wi=R(wi,Li)=argmaxwiLiP(ytruexi),其中 x = w 1 w 2 ⋯ w i ⋯ w n x=w_1 w_2\cdots w_i\cdots w_n x=w1w2wiwn x i ′ = w 1 w 2 ⋯ w i ′ ⋯ w n x'_i=w_1 w_2\cdots w'_i\cdots w_n xi=w1w2wiwn

    • x i ∗ = w 1 w 2 ⋯ w i ∗ ⋯ w n x^*_i=w_1 w_2 \cdots w^*_i \cdots w_n xi=w1w2wiwn,有: △ P i ∗ = P ( y t r u e ∣ x ) − P ( y t r u e ∣ x i ∗ ) \triangle P^*_i=P(y_{true}|x)-P(y_{true}|x^*_i) Pi=P(ytruex)P(ytruexi)

替换顺序策略

进行切片打分,切片打分函数为: S ( x , w i ) = P ( y t r u e ∣ x ) − P ( y t r u e ∣ x i ^ ) S(x,w_i)=P(y_{true}|x)-P(y_{true}|\hat{x_i}) S(x,wi)=P(ytruex)P(ytruexi^),其中 x = w 1 w 2 ⋯ w i ⋯ w d x=w_1 w_2 \cdots w_i \cdots w_d x=w1w2wiwd x ^ i = w 1 w 2 ⋯ u n k n o w n ⋯ w d \hat{x}_i=w_1 w_2 \cdots unknown \cdots w_d x^i=w1w2unknownwd

对所有 w i ∈ x w_i\in x wix计算切片分数,获得最佳切片向量 S ( x ) S(x) S(x)

单词替换优先级的评分函数: H ( x , x i ∗ , w i ) = ϕ ( S ( x ) ) i ⋅ △ P i ∗ H(x,x^*_i,w_i)=\phi(S(x))_i\cdot \triangle P^*_i H(x,xi,wi)=ϕ(S(x))iPi,其中 ϕ ( ⋅ ) \phi(\cdot) ϕ()是Softmax函数。

在这里插入图片描述

Word-level Textual Adversarial Attacking as Combinatorial Optimization

作者:Yuan Zang, Fanchao Qi et al.

单位:清华大学

来源:ACL 2020

Introduction

基本点:把对抗那个样本攻击当作是组合优化问题

方法:基于义元(sememe)的单词替代方法 + 基于粒子群优化的搜索算法

Background

Sememes: 义元是单词的语义标签,相关工作有HowNet

PSO: 连续空间 S ∈ R D S\in \mathbb{R}^D SRD,有 N N N个粒子,每个粒子的位置、速度能被表示为 x n ∈ S x^n\in S xnS x n ∈ R D x^n\in \mathbb{R}^D xnRD n ∈ { 1 , ⋯ , N } n\in \{1,\cdots, N\} n{1,,N}

  1. 初始化,随机初始化每个粒子的位置和速度,初始速度的维度为 v d n ∈ [ − V m a x , V m a x ] v^n_d\in [-V_{max}, V_{max}] vdn[Vmax,Vmax]

  2. 记录,搜索空间的每个位置对应于一个优化分数,最高优化分数记录为个体最佳位置。个体最佳位置中的最高分数为全局最佳位置

  3. 终止,如果全局最佳位置已经达到期待的最佳分数,则算法终止

  4. 更新,未终止则更新速度与位置,更新的公式为: v d n = w v d n + c 1 × r 1 × ( p d n − x d n ) + c 2 × r 2 × ( p d g − x d n ) v^n_d=wv^n_d+c_1\times r_1\times (p^n_d - x^n_d) + c_2 \times r_2 \times (p^g_d-x^n_d) vdn=wvdn+c1×r1×(pdnxdn)+c2×r2×(pdgxdn) x d n = x d n + v d n x^n_d=x^n_d+ v^n_d xdn=xdn+vdn,其中 w w w是惯性权重, p d n p^n_d pdn p d g p^g_d pdg是d维第 n n n个粒子的个体最佳位置与全局最佳位置, c 1 c_1 c1 c 2 c_2 c2是加速度系数, r 1 r_1 r1 r 2 r_2 r2是随机系数。更新之后,算法返回记录步骤。

Methodology

two parts: sememe-based word substitution & PSO-based adversarial example search

Sememe-based Word Substitution
  1. 只替代content words (words that carry meanings and consist mostly of nouns, verbs, adjectives and adverbs),并限制替代词跟原单词part-of-speech tag相同

  2. w ∗ w^* w替代 w w w时,当且仅当 w w w的意义跟 w ∗ w_* w的意义有相同的义元

PSO-based adversarial example search

一个位置对应于一个句子,每个位置的维度对应于句子的每个单词

x n = w 1 n ⋯ w d n ⋯ w D n , w d n ∈ V ( w d o ) x^n=w^n_1 \cdots w^n_d \cdots w^n_D, w^n_d\in \mathbb{V}(w^o_d) xn=w1nwdnwDn,wdnV(wdo) V ( w d o ) \mathbb{V}(w^o_d) V(wdo)包含了 w d o w^o_d wdo与其替代词, D D D为原始输入的长度

初始化:随机替换原始输入的一个词以决定粒子的初始化位置

记录:与原PSO算法相同

终止:受害模型预测到攻击者期待得到的结果标签

更新

  1. 考虑搜索空间的离散性, v d n = w v d n + ( 1 − w ) × [ I ( p d n , x d n ) + I ( p d g , x d n ) ] v^n_d=w v^n_d + (1-w)\times [I(p^n_d,x^n_d) + I(p^g_d,x^n_d)] vdn=wvdn+(1w)×[I(pdn,xdn)+I(pdg,xdn)]

  2. w w w是惯性系数, I ( a , b ) I(a,b) I(a,b)定义为: I ( a , b ) = { 1 , a = b − 1 , a ≠ b I(a,b)=\begin{cases}1,&a=b\\ -1,&a\not=b\end{cases} I(a,b)={1,1,a=ba=b

  3. w w w的更新公式为: w = ( w m a x − w m i n ) × T − t T + w m i n w=(w_{max}-w_{min})\times \frac{T-t}{T} + w_{min} w=(wmaxwmin)×TTt+wmin,其中参数范围: 0 < w m i n < w m a x < 1 0<w_{min}<w_{max}<1 0<wmin<wmax<1 T T T t t t分别为最大迭代次数值和最近迭代次数值

  4. 调整离散的搜索空间:

    • 第一步,新的移动概率 P i P_i Pi随粒子被引入到个体最佳位置,当粒子决定移动时,位置的每个维度由相同维度的速度决定,通过 s i g m o i d ( ⋅ ) sigmoid(\cdot) sigmoid()函数进行概率评判。其中 P i P_i Pi为: P i = P m a x − t T × ( P m a x − P m i n ) P_i=P_{max}-\frac{t}{T}\times (P_{max}-P_{min}) Pi=PmaxTt×(PmaxPmin),其中参数范围: 0 < P m i n < P m a x < 1 0<P_{min}<P_{max}<1 0<Pmin<Pmax<1

    • 第二步,通过移动概率 P g P_g Pg决定全局最佳概率: P g = P m i n + t T × ( P m a x − P m i n ) P_g=P_{min}+\frac{t}{T}\times (P_{max}-P_{min}) Pg=Pmin+Tt×(PmaxPmin)

  5. 更新后应用突变: P m ( x n ) = m i n ( 0 , 1 − k ϵ ( x n , x o ) D ) P_m(x^n)=min(0, 1-k\frac{\epsilon(x^n,x^o)}{D}) Pm(xn)=min(0,1kDϵ(xn,xo)) ϵ ( ⋅ ) \epsilon(\cdot) ϵ()为编辑距离。之后,返回记录步骤

Experiments

数据集:IMDB、SST-2、NLI、SNLI

baseline:Embedding/LM + Genetic、SYNONYM + Greedy

Evaluation Metrics:

  1. Attack Success Rate (ASR)

  2. Attack Validity

  3. Quality of adversarial examples (modification rate, grammatical error increase rate, language model perplexity)

Contextualized Perturbation for Textual Adversarial Attack

作者:Dianqi Li, Yizhe Zhang et al.

单位:华盛顿大学、微软研究院、杜克大学

来源:NAACL 2021

Introduction

Problem: rule-based methods are agnostic to context, limiting their ability to produce natural, fluent, and grammatical outputs

ContextuaLized AdversaRial Example: CLARE, a mask-then-infill procedure

CLARE features three contextualized perturbations: Replace, Insert and Merge

CLARE

Background

victim model: f ( ⋅ ) f(\cdot) f()

similarity function: s i m ( x ′ , x ) sim(x',x) sim(x,x)

adversarial example: x ′ x' x for x x x, s.t. f ( x ′ ) ≠ f ( x ) f(x')\not=f(x) f(x)=f(x), s i m ( x ′ , x ) > l sim(x',x)>l sim(x,x)>l

Masking and Contextualized Infilling

Replace:

对于给定的第 i i i个位置,首先给 x i x_i xi进行Mask然后从候选词集 Z Z Z中选出token z z z来填充:

x ~ = x 1 ⋯ x i − 1 [ M A S K ] x i + 1 ⋯ x n \tilde{x}=x_1\cdots x_{i-1} [MASK] x_{i+1} \cdots x_n x~=x1xi1[MASK]xi+1xn

x ~ z = r e p l a c e ( x , i ) = x 1 ⋯ x i − 1 z x i + 1 ⋯ x n \tilde{x}_z = replace(x,i)=x_1\cdots x_{i-1}z x_{i+1}\cdots x_n x~z=replace(x,i)=x1xi1zxi+1xn

要求:

  1. z z z应该适应于未mask的上下文

  2. x ~ z \tilde{x}_z x~z应该与 x x x相似

  3. x ~ z \tilde{x}_z x~z应该能在 f f f中触发错误

p M L M p_{MLM} pMLM: 预训练好的语言建模模型

根据要求约束可以用数学公式描述为:

  • 对应于第1、2点: { z ′ ∈ V ∣ p M L M ( z ′ ∣ x ~ ) > k , s i m ( x , x ~ z ′ ) > l } \{z'\in V| p_{MLM}(z'|\tilde{x})>k, sim(x,\tilde{x}_{z'})>l\} {zVpMLM(zx~)>k,sim(x,x~z)>l} V V V为语言建模模型的单词表,从 Z Z Z中挑选token填充

  • 对应于第3点: z = arg min ⁡ z ′ ∈ Z p f ( y ∣ x z ′ ~ ) z=\argmin\limits_{z'\in Z}p_f(y|\tilde{x_{z'}}) z=zZargminpf(yxz~)

Insert:

x ~ = x 1 ⋯ x i [ M A S K ] x i + 1 ⋯ x n \tilde{x} = x_1\cdots x_i [MASK] x_{i+1} \cdots x_n x~=x1xi[MASK]xi+1xn

i n s e r t ( x , i ) = x 1 ⋯ x i z x i + 1 ⋯ x n insert(x,i)=x_1\cdots x_i z x_{i+1} \cdots x_n insert(x,i)=x1xizxi+1xn

Merge: 就是二元词组换成一元词

x ~ = x 1 ⋯ x i − 1 [ M A S K ] x i + 2 ⋯ x n \tilde{x}=x_1\cdots x_{i-1} [MASK] x_{i+2} \cdots x_n x~=x1xi1[MASK]xi+2xn

m e r g e ( x , i ) = x 1 ⋯ x i − 1 z x i + 2 ⋯ x n merge(x,i)=x_1\cdots x_{i-1}z x_{i+2}\cdots x_n merge(x,i)=x1xi1zxi+2xn

对于输入序列每个位置,CLARE进行替换或插入或合并,之后通过语言建模模型和文本相似度函数构建候选令牌集,最小化正确标签的概率的令牌当作替代令牌。

Sequentially Applying the PErturbations

输入对: ( x , y ) (x,y) (x,y)

x x x的长度为 n n n,若候选集不为空,共进行 3 n 3n 3n个操作,操作为那三种,所有操作的应用操作表示为 a ( x ) a(x) a(x)

每一步都计算一个评分: s ( x , y ) ( a ) = − p f ( y ∣ a ( x ) ) s_{(x,y)}(a)=-p_f(y|a(x)) s(x,y)(a)=pf(ya(x))

每个位置只有一种操作被应用到。

在这里插入图片描述

Frequency-Guided Word Substitutions for Detecting Textual Adversarial Examples

作者:Xinghao Yang, Yongshun Gong et al.

单位:IEEE

来源:Trans on Cybernetics

Algorithm

Black Box settings

提供的:输入文本 x ∈ X x\in X xX,DNN模型 F F F,正确标签 y t r u e ∈ Y y_{true}\in Y ytrueY,i.e., F ( x ) = y t r u e F(x)=y_{true} F(x)=ytrue,由该目标函数优化得到: arg max ⁡ y i ∈ Y P ( y i ∣ x ) = y t r u e \argmax\limits_{y_i\in Y}P(y_i|x)=y_{true} yiYargmaxP(yix)=ytrue,或者用户特定目标标签: arg max ⁡ y i ∈ Y P ( y i ∣ x ∗ ) = y t a r g e t \argmax\limits_{y_i\in Y}P(y_i|x^*)=y_{target} yiYargmaxP(yix)=ytarget

Sementic Similarity

E n c o d e r Encoder Encoder U S E USE USE的编码器

U S E s c o r e = C o s i n e ( E n c o d e r ( x ) , E n c o d e r ( x a d v ) ) USE_{score}=Cosine(Encoder(x),Encoder(x_{adv})) USEscore=Cosine(Encoder(x),Encoder(xadv))

Bigram & Unigram Candidate Selection

使用WordNet (Synonym来源,假定WordNet的同义词空间为 W \mathbb{W} W) 跟HowNet (sememes,假定义元空间为 H \mathbb{H} H)。

  1. 创建候选集,

    • 给定输入句子 X = { w 1 , ⋯ , w n } X=\{w_1,\cdots, w_n\} X={w1,,wn},用WordNet判断 ( w i , w i + 1 ) (w_i, w_{i+1}) (wi,wi+1)是否有 w s y n ∗ ∈ W w^*_{syn}\in \mathbb{W} wsynW,没有则根据 w i w_i wi W \mathbb{W} W中选同义词以及从 H \mathbb{H} H中选候选义元,构成候选词集 S i ⊂ W ∪ H S_i\subset \mathbb{W}\cup \mathbb{H} SiWH。同时通过候选过滤器,选择相同POS tag的单词

    • w i w_i wi为命名实体,则通过加入更多NE候选词以拓展候选集

  2. 选择最佳候选:

    • 对于候选集 S i S_i Si,候选重要性分数为: I w i ′ = P ( y t r u e ∣ x ) − P ( y t r u e ∣ x i ′ ) , ∀ w i ′ ∈ S i I_{w'_i}=P(y_{true}|x)-P(y_{true}|x'_i), \forall w'_i\in \mathbb{S}_i Iwi=P(ytruex)P(ytruexi),wiSi,其中 x = [ w 1 , ⋯ , w i , ⋯ , w n ] x=[w_1,\cdots, w_i, \cdots, w_n] x=[w1,,wi,,wn] x i ′ = [ w 1 , ⋯ , w i ′ , ⋯ , w n ] x'_i=[w_1,\cdots,w'_i,\cdots, w_n] xi=[w1,,wi,,wn]

    • 最佳候选: w i ∗ = R ( w i , S i ) = arg max ⁡ w i ′ ∈ S i I w i ′ w^*_i=R(w_i,\mathbb{S}_i)=\argmax\limits_{w'_i\in \mathbb{S}_i} I_{{w}'_i} wi=R(wi,Si)=wiSiargmaxIwi

Semantic Preservation Optimization

SPO用于优化单词替代顺序优先级,通过三个目标:

  • 成功攻击

  • 最小替代

  • 语义不变

获得的 n n n个对抗语句: { x 1 ∗ , ⋯ , x n ∗ } \{x^*_1,\cdots, x^*_n\} {x1,,xn},从 X X X X i ∗ X^*_i Xi的差为最大攻击效果: △ P i ∗ = P ( y t r u e ∣ x ) − P ( y t r u e ∣ x i ∗ ) \triangle P^*_i=P(y_{true}|x)-P(y_{true}|x^*_i) Pi=P(ytruex)P(ytruexi),直接使用将可能导致替换陷入局部最优而非全局最优。

初始的迭代输入: G 0 \mathbb{G}^0 G0

阈值: M M M,限制单词被修改的数量

在这里插入图片描述
在这里插入图片描述

SPO with Semantic Filter (SPOF)

收集可能的对抗样本的空集: S u c A d v SucAdv SucAdv

Targeted Attack Strategy

考虑目标攻击时:

  1. 算法1 行18跟算法3 行19将修改为: F ( x a d v ) = y t a r g e t F(x_{adv})=y_{target} F(xadv)=ytarget

  2. I w i ′ = P ( y t a r g e t ∣ x i ′ ) − P ( y t a r g e t ∣ x ) , ∀ w i ′ ∈ S i I_{w'_i}=P(y_{target}|x'_i)-P(y_{target}|x), \forall w'_i\in \mathbb{S}_i Iwi=P(ytargetxi)P(ytargetx),wiSi

  3. △ P i ∗ = P ( y t a r g e t ∣ x i ∗ ) − P ( y t a r g e t ∣ x ) \triangle P^*_i=P(y_{target}|x^*_i) - P(y_{target}|x) Pi=P(ytargetxi)P(ytargetx)

  4. △ P a d v = P ( y t a r g e t ∣ x a d v ) − P ( y t a r g e t ∣ x ) \triangle P_{adv} = P(y_{target}|x_{adv}) - P(y_{target}|x) Padv=P(ytargetxadv)P(ytargetx)

Experiment

数据集:IMDB, AG’s News, Yahoo! Answers

受害模型:CNN、Ch-CNN、LSTM、Bi-LSTM

评估指标: A S R = ∑ x ∈ X { F ( x ) = y t r u e ∧ F ( x + △ x ) = y ∗ } ∑ x ∈ X { F ( x ) = y t r u e } ASR=\frac{\sum_{x_\in X}\{F(x)=y_{true}\wedge F(x+\triangle x)=y^*\}}{\sum_{x\in X}\{F(x)=y_{true}\}} ASR=xX{F(x)=ytrue}xX{F(x)=ytrueF(x+x)=y}

Universal Adversarial Triggers for Attacking and Analyzing NLP

作者:Eric Wallace, Shi Feng et al.

单位:Allen Institute for AI et al.

来源:ACL 2021

Abstract & Intro

universal adversarial triggers: input-agnostic sequences of tokens that trigger a model to produce a specific prediction when concatenated to any input from a dataset.

contribution: gradient-guided search over tokens which finds short trigger sequences that successfully trigger the target prediction

constraint: white-box attack to specific model (however, can transfer to other models)

triggers: a new form of universal adversarial perturbation adapted to discrete textual inputs.

finding:

  1. short sequences can trigger successfully.
  2. trigger can be used in transfer learning.
  3. identify heuristics learned by SQuAD models

Universal Adversarial Triggers

Setting and Motivation

universal adversarial attack:

  1. using the exact same attack for any input (Moosavi-Dezfooli 2017, Brown 2017)
  2. advantageous: no access to the target model at test time, trigger sequences can be widely distributed for anyone to fool machine learning models.
  3. transfer across models and don’t need white-box access to the target model (Moosavi-Dezfooli 2017)
Attack Model and Objective

model: f f f

a text input of tokens: t t t

target label: y ~ \tilde{y} y~

aim: f ( t a d v ; t ) = y ~ f(t_{adv};t)=\tilde{y} f(tadv;t)=y~

Universal Objective: arg ⁡ t a d v min ⁡ E t ∼ T [ L ( y ~ , f ( t a d v ; t ) ) ] \arg\limits_{t_{adv}}\min \mathbb{E}_{t\sim \Tau}[L(\tilde{y},f(t_{adv};t))] tadvargminEtT[L(y~,f(tadv;t))]

trigger token: e a d v i e_{adv_i} eadvi

Trigger Search Algorithm

Token Replacement Strategy: based on a linear approximation of the task loss.

update the embedding for e a d v i e_{adv_i} eadvi to minimize the loss: arg ⁡ e i ′ ∈ V min ⁡ [ e i ′ − e a d v i ] ⊤ ∇ e a d v i L \arg\limits_{e'_i\in V} \min [e'_i-e_{adv_i}]^\top \nabla_{e_{adv_i}} L eiVargmin[eieadvi]eadviL

set of all token embeddings: V V V

average gradient of the task loss: ∇ e a d v i L \nabla_{e_{adv_i}}L eadviL

e i ′ e'_i ei: computed in brute-force with |V|d dimensional dot products, d is the dimensionality of the token embedding.

Process Pic: 先算任务梯度 -> 遍历所有的token取极小 -> 获得极小的token -> 作为trigger结合语句计算概率分布 -> 继续重复以上步骤 -> 目标函数极小得到结果

augment: beam search, top-k token considered

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

Tasks and Associated Loss Functions

Classification: bypass fake news detection by trigger.

Reading Comprehension: modify a web page in order to trigger malicious or vulgar answers, focus on why, who, when and where questions.

Conditional Text Generation: create triggers that are prepended before t to let model generate similar content to a set of targets Y. Maximize the likelihood of racist outputs by minimizing the following loss:
E ∑ i = 1 ∣ y ∣ log ⁡ ( 1 − p ( y i ∣ t ∗ a d v , t , y 1 , ⋯ , y i − 1 ) ) , y ∼ Y , t ∼ T \mathbb{E}\sum^{|y|}\limits_{i=1}\log(1-p(y_i|t^*{adv},t,y_1,\cdots,y_{i-1})), y\sim Y, t\sim \Tau Ei=1ylog(1p(yitadv,t,y1,,yi1)),yY,tT

Attacking Text Classification

two text classification datasets.

Sentiment Analysis: Stanford Sentiment Treebank, Bi-LSTM model, word2vec / ELMo embeddings.

Natural Language Inference: SNLI dataset, ESIM, DA-GloVe, DA-ELMo.

Breaking Sentiment Analysis

pre-avoid: use a lexicon to blacklist sentiment words. “zoning tapping fiennes” is a trigger.

ELMo-based Model: “uˆ{b”, “m&s~” are triggers, droping accuracy.

Breaking Natural Language Inference

motivation: threat the accuracy.

attack SNLI models, result is here: these trigger can degrade the three model’s accuracy to nearly 0.

the attack also readily transfer.

Attacking Reading Comprehension

motivation: answer the specific answer just like a backdoor to trigger

triggers for SQuAD: use an simple baseline and test the trigger’s transferability to more advanced models

embedding: GloVe

target answer: ‘to kill anmerican people’、‘donald trump’、‘january 2014’、‘new york’

question type: why, who, when, where.

Results:

transferability:

在这里插入图片描述

Analyzing The Trigger

Triggers Align With SNLI Artifacts:

  • dataset artifacts are successful triggers,‘no’、‘tv’、‘naked’ can drop accuracy.
  • entailment overlap bias

explain the triggers:

  • PMI Analysis: question-correlation answer triggers have high PMI values, P M I ( w o r d , c l a s s ) = log ⁡ p ( w o r d , c l a s s ) p ( w o r d ) p ( c l a s s ) PMI(word, class)=\log \frac{p(word, class)}{p(word)p(class)} PMI(word,class)=logp(word)p(class)p(word,class)
  • Question Type Matching
  • token order, Placement, and Removal: model is sensitive to token order, trigger is not very correlated with replacement, remove tokens can increase the success rate when transferring the triggers to black-box models.

相关文章:

文本对抗样本系列的论文阅读笔记(整理合订)

文本对抗样本系列的论文阅读笔记 以前调研文本对抗样本时的论文笔记梳理&#xff0c;论文都很经典&#xff0c;有现成的框架&#xff08;TextAttack&#xff09;可以直接用&#xff0c;论文中部分内容直接是截取自论文&#xff0c;所以存在中英混合笔记的情况。 BERT-Attack …...

鸿基智启:东土科技为具身智能时代构建确定性底座

人类文明的每一次跨越都伴随着工具的革新。从蒸汽机的齿轮到计算机的代码&#xff0c;生产力的进化始终与技术的“具身化”紧密相连。当大语言模型掀起认知革命&#xff0c;具身智能正以“物理实体自主决策”的双重属性重新定义工业、医疗、服务等领域的运行逻辑。在这场革命中…...

javascript-es6 (六)

编程思想 面向过程 面向过程 就是分析出解决问题所需要的步骤&#xff0c;然后用函数把这些步骤一步一步实现&#xff0c;使用的时候再一个一个的依次 调用就可以了 就是按照我们分析好了的步骤&#xff0c;按照步骤解决问题 面向对象 面向对象 是把事务分解成为一个个对象&am…...

【leetcode hot 100 19】删除链表的第N个节点

解法一&#xff1a;将ListNode放入ArrayList中&#xff0c;要删除的元素为num list.size()-n。如果num 0则将头节点删除&#xff1b;否则利用num-1个元素的next删除第num个元素。 /*** Definition for singly-linked list.* public class ListNode {* int val;* Lis…...

微信小程序将markdown内容转为pdf并下载

要在微信小程序中将Markdown内容转换为PDF并下载,您可以使用以下方法: 方法一:使用第三方API服务 选择第三方API服务: 可以选择像 Pandoc、Markdown-PDF 或 PDFShift 这样的服务,将Markdown转换为PDF。例如,PDFShift 提供了一个API接口,可以将Markdown内容转换为PDF格式…...

【贪心算法】将数组和减半的最小操作数

1.题目解析 2208. 将数组和减半的最少操作次数 - 力扣&#xff08;LeetCode&#xff09; 2.讲解算法原理 使用当前数组中最大的数将它减半&#xff0c;&#xff0c;直到数组和减小到一半为止&#xff0c;从而快速达到目的 重点是找到最大数&#xff0c;可以采用大根堆快速达到…...

【面试】Kafka

Kafka 1、为什么要使用 kafka2、Kafka 的架构是怎么样的3、什么是 Kafka 的重平衡机制4、Kafka 几种选举过程5、Kafka 高水位了解过吗6、Kafka 如何保证消息不丢失7、Kafka 如何保证消息不重复消费8、Kafka 为什么这么快 1、为什么要使用 kafka 1. 解耦&#xff1a;在一个复杂…...

PHP MySQL 创建数据库

PHP MySQL 创建数据库 引言 在网站开发中&#xff0c;数据库是存储和管理数据的核心部分。PHP 和 MySQL 是最常用的网页开发语言和数据库管理系统之一。本文将详细介绍如何在 PHP 中使用 MySQL 创建数据库&#xff0c;并对其操作进行详细讲解。 前提条件 在开始创建数据库之…...

通义万相 2.1 × 蓝耘智算:AIGC 界的「黄金搭档」如何重塑创作未来?

我的个人主页 我的专栏&#xff1a; 人工智能领域、java-数据结构、Javase、C语言&#xff0c;希望能帮助到大家&#xff01;&#xff01;&#xff01; 点赞&#x1f44d;收藏❤ 引言 在当今数字化浪潮席卷的时代&#xff0c;AIGC&#xff08;生成式人工智能&#xff09;领域正…...

【面试题系列】:使用消息队列怎么防止消息重复?从原理到实战……

一、消息队列的核心价值与挑战 消息队列&#xff08;MQ&#xff09;作为现代分布式系统的基础设施&#xff0c;其核心价值在于解耦、削峰填谷和异步通信。但在追求高可靠性的过程中&#xff0c;消息重复成为必须攻克的技术难题。根据调研数据&#xff0c;在生产环境中消息重复…...

Damage与Injury

### “Damage”和“Injury”的区别 “Damage”和“Injury”都有“损害”或“伤害”的意思&#xff0c;但它们的用法、语境和侧重点有所不同。以下是从词性、适用对象、语义侧重和具体场景四个方面详细对比两者的区别&#xff1a; --- #### 1. **词性** - **Damage**&#xf…...

18 HarmonyOS NEXT UVList组件开发指南(五)

温馨提示&#xff1a;本篇博客的详细代码已发布到 git : https://gitcode.com/nutpi/HarmonyosNext 可以下载运行哦&#xff01; 第五篇&#xff1a;UVList组件最佳实践与实际应用案例 文章目录 第五篇&#xff1a;UVList组件最佳实践与实际应用案例1. 最佳实践总结1.1 组件设计…...

vue3组合式API怎么获取全局变量globalProperties

设置全局变量 main.ts app.config.globalProperties.$category { index: 0 } 获取全局变量 const { appContext } getCurrentInstance() as ComponentInternalInstance console.log(appContext.config.globalProperties.$category) 或是 const { proxy } getCurrentInstance…...

华为机试牛客刷题之HJ14 字符串排序

HJ14 字符串排序 描述 对于给定的由大小写字母混合构成的 n 个单词&#xff0c;输出按字典序从小到大排序后的结果。 从字符串的第一个字符开始逐个比较&#xff0c;直到找到第一个不同的位置&#xff0c;通过比较这个位置字符对应的&#xff08;A<⋯<Z<a<⋯<…...

CPU 负载 和 CPU利用率 的区别

简单记录下 top 命令中&#xff0c;CPU利用率核CPU负载的概念&#xff0c; &#xff08;1&#xff09;CPU利用率&#xff1a;指在一段时间内 表示 CPU 实际工作时间占总时间的百分比。表示正在执行进程的时间比例&#xff0c;包括用户空间和内核空间程序的执行时间。通常包含以…...

SSM框架

SSM 框架是 Java Web 开发中广泛使用的经典组合&#xff0c;由 Spring、Spring MVC 和 MyBatis 三个开源框架整合而成&#xff0c;适用于构建中大型企业级应用。 1. SSM框架组成 框架作用核心特性Spring管理业务层&#xff08;Service&#xff09;和持久层&#xff08;DAO&am…...

maven无法解析插件 org.apache.maven.plugins:maven-jar-plugin:3.4.1

解决流程 1.修改maven仓库库地址 2.删除本地的maven仓库 maven插件一直加载有问题: 无法解析插件 org.apache.maven.plugins:maven-jar-plugin:3.4.1 开始以为maven版本有问题&#xff0c;重装了maven&#xff0c;重装了idea工具。结果问题还是没解决。研究之后发现&#xf…...

如何修复“RPC 服务器不可用”错误

远程过程调用&#xff08;Remote Procedure Call&#xff0c; RPC&#xff09;是允许客户端在不同计算机上执行进程的众多可用网络进程之一。本文将深入探讨RPC如何在不同的软件系统之间实现无缝消息交换&#xff0c;同时重点介绍与RPC相关的常见错误的一些原因。 什么是远程过…...

晋升系列4:学习方法

每一个成功的人&#xff0c;都是从底层开始打怪&#xff0c;不断的总结经验&#xff0c;一步一步打上来的。在这个过程中需要坚持、总结方法论。 对一件事情长久坚持的人其实比较少&#xff0c;在坚持的人中&#xff0c;不断的总结优化的更少&#xff0c;所以最终达到高级别的…...

单链表-代码精简版

单链表核心知识详解 单链表是一种动态存储的线性数据结构&#xff0c;其特点是逻辑上连续&#xff0c;物理上非连续&#xff0c;每个节点包含数据域和指向下一个节点的指针域。以下是核心知识点与完整实现代码&#xff1a; 一、单链表的结构定义 单链表节点通过结构体自引用…...

关于前后端整合和打包成exe文件的个人的总结和思考

前言 感觉有很多东西&#xff0c;不知道写什么&#xff0c;随便写点吧。 正文 前后端合并 就不说怎么开发的&#xff0c;就说点个人感觉重要的东西。 前端用ReactViteaxios随便写一个demo&#xff0c;用于CRUD。 后端用Django REST Framework。 设置前端打包 import { …...

基于muduo+mysql+jsoncpp的简易HTTPWebServer

一、项目介绍 本项目基于C语言、陈硕老师的muduo网络库、mysql数据库以及jsoncpp&#xff0c;服务器监听两个端口&#xff0c;一个端口用于处理http请求&#xff0c;另一个端口用于处理发送来的json数据。 此项目在实现时&#xff0c;识别出车牌后打包为json数据发送给后端服务…...

Java/Kotlin逆向基础与Smali语法精解

1. 法律警示与道德边界 1.1 司法判例深度剖析 案例一&#xff1a;2021年某游戏外挂团伙刑事案 犯罪手法&#xff1a;逆向《王者荣耀》通信协议&#xff0c;修改战斗数据包 技术细节&#xff1a;Hook libil2cpp.so的SendPacket函数 量刑依据&#xff1a;非法经营罪&#xff…...

C++:入门详解(关于C与C++基本差别)

目录 一.C的第一个程序 二.命名空间&#xff08;namespace&#xff09; 1.命名空间的定义与使用&#xff1a; &#xff08;1&#xff09;命名空间里可以定义变量&#xff0c;函数&#xff0c;结构体等多种类型 &#xff08;2&#xff09;命名空间调用&#xff08;&#xf…...

CI/CD—GitLab钩子触发Jenkins自动构建项目

GitLab钩子简介&#xff1a; 项目钩子 项目钩子是针对单个项目的钩子&#xff0c;会在项目级别的特定事件发生时触发。这些事件包括代码推送、合并请求创建、问题创建等。项目钩子由项目管理员或具有相应权限的用户进行配置&#xff0c;仅对特定项目生效。 使用场景&#xff1a…...

RPA 职业前景:个人职场发展的 “新机遇”

1. RPA职业定义与范畴 1.1 RPA核心概念 机器人流程自动化&#xff08;RPA&#xff09;是一种通过软件机器人模拟人类操作&#xff0c;自动执行重复性、规则性任务的技术。RPA的核心在于其能够高效、准确地处理大量数据和流程&#xff0c;减少人工干预&#xff0c;从而提高工作…...

【CSS3】金丹篇

目录 标准流概念元素类型及排列规则块级元素行内元素行内块元素 标准流的特点打破标准流 浮动基本使用清除浮动额外标签法单伪元素法双伪元素法&#xff08;推荐&#xff09;overflow 法 Flex 布局Flex 组成主轴对齐方式侧轴对齐方式修改主轴方向弹性盒子伸缩比弹性盒子换行行对…...

Git(一)

一、介绍 二、Git代码托管服务 三、Git常用命令 全局设置&#xff1a; 获取Git仓库&#xff1a; 工作区、暂存区、版本库概念&#xff1a; Git工作区文件的状态&#xff1a; 本地仓库操作&#xff1a; 远程仓库操作&#xff1a; 分支操作&#xff1a; 标签操作&#xff1a; 四…...

Python大数据可视化:基于spark的短视频推荐系统的设计与实现_django+spider

开发语言&#xff1a;Python框架&#xff1a;djangoPython版本&#xff1a;python3.7.7数据库&#xff1a;mysql 5.7数据库工具&#xff1a;Navicat11开发软件&#xff1a;PyCharm 系统展示 管理员登录 管理员功能界面 热门视频界面 用户界面 用户反馈界面 论坛交流界面 系统…...

面试题之react useMemo和uesCallback

在面试中&#xff0c;关于 React 中的 useMemo 和 useCallback 的区别 是一个常见的问题。 useMemo 和 useCallback 的区别 1. 功能定义 useMemo&#xff1a; 用于缓存计算结果&#xff0c;避免在每次组件渲染时重新计算复杂的值。它接受一个计算函数和一个依赖数组&#xff0…...

K8S学习之基础十九:k8s的四层代理Service

K8S四层代理Service 四层负载均衡Service 在k8s中&#xff0c;访问pod可以通过ip端口的方式&#xff0c;但是pod是由生命 周期的&#xff0c;pod在重启的时候ip地址往往会发生变化&#xff0c;访问pod就需要新的ip地址&#xff0c;这样就会很麻烦&#xff0c;每次pod地址改变就…...

C++:string容器(下篇)

1.string浅拷贝的问题 // 为了和标准库区分&#xff0c;此处使用String class String { public :/*String():_str(new char[1]){*_str \0;}*///String(const char* str "\0") // 错误示范//String(const char* str nullptr) // 错误示范String(const char* str …...

sudo systemctl restart docker 重启docker失败

一般会使用如下命令&#xff0c;进行docker重启。 sudo systemctl daemon-reload sudo systemctl restart docker 重启失败时&#xff0c;会提示&#xff1a;Job for docker.service failed because the control process exited with error code. See "systemctl status…...

Linux基本操作指令3

1、wget: 这是一个用于从网络上下载文件的命令行工具。它支持 HTTP、HTTPS 和 FTP 协议。 wget http://download.qt.io/archive/qt/5.12/5.12.9/qt-opensource-linux-x64-5.12.9.run 2、下载完成后&#xff0c;你可以通过以下命令使文件可执行并运行安装程序&#xff1a; ch…...

React:类组件(上)

kerwin老师我来了 类组件的创建 class组件&#xff0c;js里的类命名首字符大写&#xff0c;类里面包括构造函数&#xff0c;方法 组件类要继承React.Component才有效 必须包含render方法 import React from react class App extends React.Component{render() {return <…...

sqli-lab靶场学习(七)——Less23-25(关键字被过滤、二次注入)

前言 之前的每一关&#xff0c;我们都是在末尾加上注释符&#xff0c;屏蔽后面的语句&#xff0c;这样我们只要闭合了区间之后&#xff0c;差不多就是为所欲为的状态。但如果注释符不生效的情况下&#xff0c;又该如何呢&#xff1f; Less23&#xff08;注释符被过滤&#xff…...

虚函数和虚表的原理是什么?

虚函数是一个使用virtual关键字声明的成员函数&#xff0c;在基类中声明虚函数&#xff0c;在子类中可以使用override重写该函数。虚函数根据指针或引用指向的实际对象调用&#xff0c;实现运行时的多态。 虚函数表&#xff08;虚表&#xff09;是一个用于存储虚函数地址的数组…...

RReadWriteLock读写锁应用场景

背景 操作涉及一批数据&#xff0c;如订单&#xff0c;可能存在多个场景下操作&#xff0c;先使用读锁&#xff0c;从redis缓存中获取操作中数据 比如 关闭账单&#xff0c; 发起调账&#xff0c; 线下结算&#xff0c; 合并支付 先判断当前操作的数据&#xff0c;是否在…...

【面试】MySQL

MySQL 1、数据库三范式2、什么是关系型数据库&#xff0c;什么是非关系型数据库3、什么是数据库存储引擎4、MySQL5.x和8.0有什么区别5、char 和 varchar 的区别6、in 和 exists 的区别7、MySQL 时间类型数据存储建议8、drop、delete 与 truncate 区别9、一条 Sql 的执行顺序10、…...

Trae AI 开发工具使用手册

这篇手册将介绍 Trae 的基本功能、安装步骤以及使用方法&#xff0c;帮助开发者快速上手这款工具。 Trae AI 开发工具使用手册 Trae 是字节跳动于 2025 年推出的一款 AI 原生集成开发环境&#xff08;IDE&#xff09;&#xff0c;旨在通过智能代码生成、上下文理解和自动化任务…...

表格columns拼接两个后端返回的字段(以umi框架为例)

在用组件对前端项目进行开发时&#xff0c;我们会遇到以下情况&#xff1a;项目原型中有取值范围这个表字段&#xff0c;需要存放最小取值到最大取值。 而后端返回给我们的数据是返回了一个最小值和一个最大值&#xff0c; 在columns中我们需要对这两个字段进行拼接&#xff0…...

常见的算法题python

字符串倒序 def func1(str):return str[::-1] def func2(str):new_str ""for i in str:new_str inew_strreturn new_str if __name____main__:str"linda"print(func2(str))合并两个有序的列表 def func3(list1,list2):for i in list1:list2.append(i)li…...

linux学习(十)(磁盘和文件系统(索引节点,文件系统,添加磁盘,交换,LVM公司,挂载))

Linux 磁盘文件系统 Linux 使用各种文件系统来允许我们从计算机系统的硬件&#xff08;例如磁盘&#xff09;存储和检索数据。文件系统定义了如何在这些存储设备上组织、存储和检索数据。流行的 Linux 文件系统示例包括 EXT4、FAT32、NTFS 和 Btrfs。 每个文件系统都有自己的…...

k8s v1.28.15部署(kubeadm方式)

k8s部署&#xff08;kubeadm方式&#xff09; 部署环境及版本 系统版本&#xff1a;CentOS Linux release 7.9.2009 k8s版本&#xff1a;v1.28.15 docker版本&#xff1a;26.1.4 containerd版本&#xff1a;1.6.33 calico版本&#xff1a;v3.25.0准备 主机ip主机名角色配置1…...

Python开发Scikit-learn面试题及参考答案

目录 如何用 SimpleImputer 处理数据集中的缺失值? 使用 StandardScaler 对数据进行标准化的原理是什么?与 MinMaxScaler 有何区别? 如何用 OneHotEncoder 对类别型特征进行编码? 解释特征选择中 SelectKBest 与 VarianceThreshold 的应用场景。 如何通过 PolynomialFe…...

Java在小米SU7 Ultra汽车中的技术赋能

目录 一、智能驾驶“大脑”与实时数据 场景一&#xff1a;海量数据的分布式计算 场景二&#xff1a;实时决策的毫秒级响应 场景三&#xff1a;弹性扩展与容错机制 技术隐喻&#xff1a; 二、车载信息系统&#xff08;IVI&#xff09;的交互 场景一&#xff1a;Android Automo…...

蓝队第三次

1.了解什么是盲注 盲注&#xff08;Blind SQL Injection&#xff09;是SQL注入的一种形式&#xff0c;攻击者无法直接通过页面回显或错误信息获取数据&#xff0c;而是通过观察页面的布尔状态&#xff08;真/假&#xff09;或时间延迟来间接推断数据库信息。例如&#xff0c;通…...

Element Plus中的树组件的具体用法(持续更新!)

const defaultProps {//子树为节点对象的childrenchildren: children,//节点标签为节点对象的name属性label: name, } 属性 以下是树组件中的常用属性以及作用&#xff1a; data&#xff1a;展示的数据&#xff08;数据源&#xff09; show-checkbox&#xff1a;节点是否可…...

nodejs使用WebSocket实现聊天效果

在nodejs中使用WebSocket实现聊天效果&#xff08;简易实现&#xff09; 安装 npm i ws 实现 创建 server.js /*** 创建一个 WebSocket 服务器&#xff0c;监听指定端口&#xff0c;并处理客户端连接和消息。** param {Object} WebSocket - 引入的 WebSocket 模块&#xff0c…...

通领科技冲刺北交所

高质量增长奔赴产业新征程 日前&#xff0c;通领科技已正式启动在北交所的 IPO 进程&#xff0c;期望借助资本市场的力量&#xff0c;加速技术升级&#xff0c;推动全球化战略布局。这一举措不仅展现了中国汽车零部件企业的强大实力&#xff0c;也预示着行业转型升级的新突破。…...