NLP领域模型对抗攻击简介-程序员宅基地

技术标签: nlp  语言模型  机器学习  人工智能  自然语言处理  

一、 Introduction

NLP对抗攻击是人工智能对抗攻击的一个重要的组成部分,但是最近几年才逐渐开始兴起,究其原因在于NLP对抗攻击与传统computer vision或者audio对抗攻击有很大的不同,主要在于值空间的连续性(CV、audio)和离散性(NLP)。

如图为传统的一种对CV和audio模型的攻击方式:
在这里插入图片描述
如图,对CV与audio的攻击是在一张图片或一段录音中加入微小连续的扰动(如高斯噪声),在人眼或人耳不可识别的条件下使模型进行错误的分类。

以对CV模型攻击为例:

在这里插入图片描述

CV的 256 × 256 256 \times 256 256×256大小的图片像素值空间为 [ 0 , 255 ] 256 × 256 [0,255]^{256 \times 256} [0,255]256×256内的连续实数空间,对其添加扰动比较容易。

但是,如图

在这里插入图片描述

NLP领域中,数值是由一个一个的离散的token组成。因此对NLP模型进行处理时,需要先将离散的token转换为连续的vector,这样才能让NLP模型对其进行处理。因此,对NLP模型做攻击时,也只能处理离散的token。(连续的vector一般来说是在NLP模型内部生成的,因为无法做到对其加噪声)。

二、Evasion Attacks and Defenses

1. Introduction

在CV中,Evasion Attacks就是在图片中添加人眼不可见的噪声,使图片分类模型对其进行错误的分类。

如图:

在这里插入图片描述

对于原始图片,模型有57.7%的概率认为其是熊猫,但是在对其添加了人眼无法察觉到的噪声(连续值空间)后,模型有99.3%的概率认为其是长臂猿(分类错误)。

同样的,在NLP中,Evasion Attack指的是:对原始的句子进行修改,在对人类来说不改变语义的情况下使模型对修改过的句子进行错误的预测。

以情感分析为例,如图:

在这里插入图片描述

上图是一段影评,对于原始的句子,NLP模型认为其是负面的,但是在对film添加上一个s后,模型认为其是正面,这对人来说,是很难察觉的。

对NLP的Evasion Attack还有其他方面,比如修改句子,使翻译模型对其进行错误的翻译。这里不在进行赘述。

2. Four Ingredients in Evasion Attacks

以影评的情感分析为例,Evasion Attacks攻击的完整步骤(执行框架)为:

在这里插入图片描述

1 Goal,对既定的攻击模型和对抗样本指定攻击目标。

2 Transformation,对对抗样本进行相应的转换(添加扰动),在此过程中会产生很多可能的候选样本。

3 Constraints,根据设置的限制条件,对候选样本进行过滤。(比如,语法错误、人称错误或同义词变成反义词等等)

4 Search: 采取一些研究方法,在候选的样本中选择可以成功的使模型进行错误预测的样本作为最终的对抗样本。

Morris, J., Lifland, E., Yoo, J. Y., Grigsby, J., Jin, D., & Qi, Y. (2020). TextAttack: A framework for adversarial attacks, data augmentation, and adversarial training in NLP. Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations.2020.

2.1. Goal: What the attack aims to achieve

以新闻类别分类为例:

2.1.1. Untargeted classification: 使模型对当前文本做错误的分类而不关心错误分类的类别。

如图:

在这里插入图片描述

对原有新闻文本进行修改,使NLP模型对其进行错误的分类,但是不关心误分类的类别。(只要错误分类就行,其他的不关心)

2.1.2. Targeted classification: 使模型对当前文本做误分类,且误分类的类别也应该被指定。

如图:

在这里插入图片描述

在对原有新闻文本进行修改后,使模型误分类到指定的Sci/Tech板块。

2.1.3. Universal suffix dropper: 在对翻译文本加入一些前缀后,模型回忽略前缀后的文本。

如图:

在这里插入图片描述

如图,在对翻译文本添加红色前缀后,其后面的紫色文本将不在会被翻译。

Wallace, E., Stern, M., & Song, D. (2020). Imitation attacks and defenses for black-box machine translation systems. Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP).2020

2.1.4. Wrong parse tree in dependency parsing:使模型对当前文本做错误的解析

在这里插入图片描述

Zheng, X., Zeng, J., Zhou, Y., Hsieh, C.-J., Cheng, M., & Huang, X. (2020). Evaluating and enhancing the robustness of neural network-based dependency parsing models with adversarial examples. Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics.2020

2.2. Transformations: How to construct perturbations for possible adversaries

如图:

在这里插入图片描述

如图,采取某些方法对样本进行转换,产生大量候选样本。之后再运用constrain对候选样本进行过滤。

2.2.1. word substitution by WordNet synonyms

同义词替换,在进行文本转换时必须要保持文本的语义不变,因此最简单的方法是进行同义词替换。WorkNet synonyms是一个同义词数据集。

如图:

在这里插入图片描述

如图,对原始文本根据WorkNet synonyms进行同义词替换。但是,在替换时可能会出现替换后的句子语音改变或者“别扭”,这时就需要constraint进行过滤。

2.2.2. Word substitution by knn or ε \varepsilon ε-ball in counter-fitted Glove embedding space

将文本的单词转换为对应的word embedding,在embedding vector中寻找相近的单词。

如图:

在这里插入图片描述

对原始文本进行转换,不是进行同义词替换,而是在Counter-fitted embedding space中设置一个半径为 ε \varepsilon ε的“球”(可以认为“球”内的embedding对应的单词与原始单词最接近, ε \varepsilon ε是单词接近的程度)。这样就可以防止一些不合语义的候选样例产生。

Counter-fitted embedding space: Use linguistic constrains to pull synonyms closer and antonyms far away from each others

如图,

在这里插入图片描述

Counter-fitted使用语言学的一些限制,让同义词变得更近,反义词变的更远。

对于原始的Glove embedding space词性相近,出现频率相同的单词是靠的比较近的。比如:东、西、南、北,但是如果将”东“变成”西“,那么句子的整个意思就会发生改变,因此需要在Counter-fitted Glove embedding space中画一个半径为 ε \varepsilon ε的球,这样句子的意思才不容易改变。

Mrkšić, N., Ó Séaghdha, D., Thomson, B., Gašić, M., Rojas-Barahona, L. M., Su, P.-H., Vandyke, D., Wen, T.-H., & Young, S. (2016). Counter-fitting word vectors to linguistic constraints. Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies.2016

2.2.3. Word substitution by BERT masked language modeling(MLM) prediction

如图:

在这里插入图片描述

首先,对文本的相关单词进行遮蔽,之后放入BERT中输出预测的单词将其插回源文本作为候选文本。但是,可以看到,BERT预测的masked token与源文本的token差别比较大,且预测概率最高的单词"double"与源文本"recommend"甚至相反,因此,单独使用BERT对masked token做预测是不可取的行为。

2.2.4. Word substitution by BERT reconstruction(no masking)

如图:

在这里插入图片描述

如图,不对源文本进行遮蔽,直接将其放入BERT中,这样输出的字符信息就与源文本中对应的字符十分接近。但是,可以看到不进行遮蔽时,预测的字符与源文本中的字符十分接近,因此大大限制了BERT的能力。

2.2.5. Word substitution by changing the inflectional form of verbs, nouns and adjectives

Inflectional morpheme: an affix that never changes the basic meaning of a word, and are indicative/characteristic of the part of speech(POS).

屈折语素:永远不会改变单词基本含义的词缀,并且指示/表征词性(POS)

如图:

在这里插入图片描述

如图,在不改变单词含义的情况下,改变了单词的时态。但是可以看到,改变时,第一和第三个句子语法是错误的,因此还需要在constraint中进行过滤。

2.2.6. Word substitution by gradient of the word embedding

该方法涉及梯度计算,因此这是一个white-box攻击。

如图:

在这里插入图片描述

首先,将源文本放入模型中,会得到对应的Loss,之后对文本中指定的单词 e 0 e_0 e0(如recommend)求偏导,这便是 e 0 e_0 e0在当前文本中的贡献。

之后:

在这里插入图片描述

计算,计算 e 0 e_0 e0与嵌入空间其他的embedding的差与Loss和 e 0 e_0 e0偏导的乘积,这便是当 e 0 e_0 e0变为其他字符时,Loss改变的一阶近似。

在运行中,选择使当前Loss改变最大的单词作为转换的单词。(Loss越大代表模型预测越“不准”)

如图:

在这里插入图片描述

该图为,二维状态下的数学解释,比较简单就不赘述了。

2.2.7. Word insertion based on BERT MLM

如图:

在这里插入图片描述

如图,在想插入单词的位置先插入一个masked token,之后将插入后的文本放入BERT中,获得BERT预测的插入后的文本作为对抗的候选文本。

2.2.8. Word deletion

如图:

在这里插入图片描述

如图,直接删减单词,不建议单独使用。

2.2.9. Character level transform
  • Swap
  • Substitution
  • Deletion
  • Insertion

如图:

在这里插入图片描述

字符级别的转换在日常中十分常见,比如一个人在打字时多打一个字母或少打一个字母。特别的,在Substitution方法中,会专门寻找与当前字母在键盘上相近的字母进行替换,这样可以提高真实性。

因为在模型训练时,模型可能没有接触过类似的字符出错的“错别字”,因此该方法生成的对抗样本的性能比较高。

Gao, J., Lanchantin, J., Soffa, M. L., & Qi, Y. (2018). Black-box generation of adversarial text sequences to evade deep learning classifiers. 2018 IEEE Security and Privacy Workshops (SPW).2018

2.3. Constrains: What a valid adversarial examples should satisfy

2.3.1. What a valid adversarial sample should satify

关于对抗样本的限制要具体问题具体分析。

目前来说,一般的限制条件包括overlapping、grammaticality和semantic similarity

2.3.2. Overlapping between the original and perturbed sample
2.3.2.1. Levenshtien edit distance (character level)

该方法一般用在character level的对抗样本中。

该方法计算,transform后的单词与transform之前的单词按顺序改动的字符的数量。(越小越好)

如图:

在这里插入图片描述

Levenshtien edit distance问题是实质上一个递归问题,其本质上是比较两个单词之间的不同字符的数量。

如图:

在这里插入图片描述

假设kitten经过transform之后变为sitting。

step1: k -> s,,lev + 1

Step2: i、t、t没变,此时lev不变

step3: e -> i,lev + 1

step4: n没变,此时lev不变

step5: kitten此时已经全部比较完毕,根据公式,如果kitten比较完毕,level + sitting剩下的长度,即 lev + 1

此时,lev计算完毕

2.3.2.2. Maximum percentage of modified words

如图:

在这里插入图片描述

该方法计算,transform之后的文本中,被修改的单词的比例。(越小越好)

2.3.3. Grammaticality of the perturbed sample
2.3.3.1. Part of speech (POS) consistency

如图:

在这里插入图片描述

POS,即词性,通过限制transform之后单词的词性来保证transform之后文本在语法和语义上的正确性。如上图,recommend是非单三的动词形式,第一个候选样本是advocate,完全符合;第三个候选样本是recommendation,是名词,不符合;第二个候选样本是recommended,是动词过去时,虽然在语法上仍然正缺但是修改了原词的时态,其保留与否还需具体问题具体分析。

2.3.3.2. Number of grammarical errors (evaluated by some toolkit)

借助语法检查工具来检查当前候选文本中语法错误的数量。(越少越好)

2.3.3.3. Fluency scored by the perplexity of a pre-trained language model

如图:

在这里插入图片描述

将当前生成的候选文本送人预训练语言模型,根据其perplexity(困惑度),来过滤候选样本。(perplexity越小越好)

2.3.4. Semantic similarity between the transformed sample and the original sample
2.3.4.1. Diatance of the swapped word’s embedding and the original word’s embeding

在embedding space中比较两个单词之间的相似性,通过设置一个合理的阈值来对候选样本吗进行过滤。

如图,以余弦相似度为例判断单词之间相似程度:

在这里插入图片描述

该例通过embedding space中不同单词之间的余弦相似度来判断单词之间的相似程度。需要注意的时,阈值的设定十分重要,不好的阈值会使攻击效果十分差。

2.3.4.2. Similarity between the transformed sample’s sentence embedding and the original sample’s sentence embedding

如图,以余弦相似度为例:

在这里插入图片描述

首先选择一个通用的句子编码器(可以输入字符串的NLP模型),获取文本的embeding vector,之后比较两个句子之间的余弦相似度,根据设置的余弦相似度阈值来过滤候选像本。

2.4. Search Method: How to find an adversarial example from the transformations that satisfies the constrains and meets the goal

2.4.1. Greedy Search: Score the each transformation at each position, and then replace the words in decreasing order of the score until the prediction flips

如图:

在这里插入图片描述

step1: 产生修改各个单词之后的候选样本,并送入被攻击模型中,得到模型的分类概率与Loss

step2: 根据Loss从大到小对候选样本进行降序排序,并按需修改替换单词,直到模型进行错误的分类。

step3: 对抗样本生成成功。

以上图为例:首先将highly换为inordinately,此时虽然Loss大幅上升,但是模型的分类仍然正确。这时挑选Loss第二大的样本,将recommend修改为advocate,这时模型进行了错误的分类(将positive误分类成了negative)。对抗样本生成成功。

注意,有greedy search就有beam search,这里不再赘述。

2.4.2. Greedy search with word imprtance ranking (WIR)
Word Importance ranking by leave-one-out(LOO): see how the ground truth probablity decreases when the word is removed from the input

如图:

逐个删除单词,计算删除后文本的Loss和预测概率分布的差值。Loss上升越大和正确分类概率下降值越大,则代表当前单词越重要。

Word Impartance ranking by the gradient of the word embedding (white-box)

如图:

在这里插入图片描述

通过计算Loss与各个单词的embedding vector做偏导,来计算单词的重要程度。偏导值越大的代表单词的重要性越高。

Step 1: Score each word’s importance

在这里插入图片描述

首先对文本中各个单词的重要性排序。

Step2: Swap the words from the most important to the leasrt important

在这里插入图片描述

首先选择重要性第一的recommend进行替换,选择Loss最大的advocate替换,此时虽然Loss变大,但是模型分类仍正确。

之后选择重要性第二的highly进行替换,选择Loss最大的inordinately替换,此时模型分类错误。对抗样本生成成功。

2.4.3. Genetic Algorithm: evolution and selection based on fitness

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

step1: 将原始文本进行一次转换,将其放入被攻击模型中,计算其误分类的概率。对误分类概率进行正则化,作为父本采样的概率。

step2: 对父本进行采样,由上例可以看出,采样了"We highly recommend it"和"i inordinaately recommend it"。之后对这两个父本进行融合得到新的子代 g 1 g_1 g1"We inordinately recommend it"。

step3: 对子代进行mutation(突变),即对子代 g 1 g_1 g1进行一次transform。(已经改变的不再改变)

step4: 判断 g 1 g_1 g1是否可以成功攻击模型,如果可以则生成成功。否则,删除 g 1 g_1 g1的两个父本,将 g 1 g_1 g1作为新的父本,重复step1、2、3、4直到产生成功的攻击样本。

3. Examples of Evasion Attacks

3.1. Synonym Substitution Attack

3.1.1. TextFooler

如图:

在这里插入图片描述

该算法的架构上图比较详细,这里不再过多赘述。以下是具体的算法细节:

在这里插入图片描述

Jin, D., Jin, Z., Zhou, J. T., & Szolovits, P. (2020). Is BERT really robust? A strong baseline for natural language attack on text classification and entailment. Proceedings of the … AAAI Conference on Artificial Intelligence. AAAI Conference on Artificial Intelligence, 34(05).2020

3.1.2. PWWS

如图:

在这里插入图片描述

该方法即考虑了LOO算法也考虑了WIR算法。但是由于没有constraint,所以生成的内容有很大的多样性。

Shuhuai Ren, Yihe Deng, Kun He, and Wanxiang Che. (2019). Generating Natural Language Adversarial Examples through Probability Weighted Word Saliency. Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 1085–1097, Florence, Italy. Association for Computational Linguistics.

3.1.3. BERT-Attack

如图:

该算法使用BERT作为候选样本选择的模型。

Li, L., Ma, R., Guo, Q., Xue, X., & Qiu, X. (2020). BERT-ATTACK: Adversarial attack against BERT using BERT. Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP).2020.

3.1.4. Genetic Algorithm

如图:

Moustafa Alzantot, Yash Sharma, Ahmed Elgohary, Bo-Jhang Ho, Mani Srivastava, and Kai-Wei Chang. 2018. Generating Natural Language Adversarial Examples. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, pages 2890–2896, Brussels, Belgium. Association for Computational Linguistics.

3.2. Dicussion

3.2.1. Result and Compare

在这里插入图片描述

通过上图可以看出,采用BERT进行对抗攻击可以使被攻击模型对正确类别的概率最低。同时其对原文本造成的扰动最小。则且在Query number中可以看出,BERT的时间损耗最小,Genetic Algorithm的时间损耗最高。

Li, L., Ma, R., Guo, Q., Xue, X., & Qiu, X. (2020). BERT-ATTACK: Adversarial attack against BERT using BERT. Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP).2020.

3.2.2. Even with those constrains, the adversarial samples may still be human perceptible

如图:

在这里插入图片描述

在TextFooler中,对生成的对抗文本进行分析,发现在存在constraint的情况下,仍会存在一些使人“别扭”的句子。

因次,论文作者提出了TF-Adjusted来加强constraint的限制

TF-Adjusted: They propose a modified version of TextFooler that has stronger constrains.

如图:

在这里插入图片描述

可以看到,在提高了constraint后,人对生成的对抗样本的打分变高了,但是其攻击的成功率产生了断崖式下降。这就表明,在对抗样本的攻击过程中,大量样本包含了“错误”和“不合理”。

Morris, J., Lifland, E., Lanchantin, J., Ji, Y., & Qi, Y. (2020). Reevaluating adversarial examples in natural language. Findings of the Association for Computational Linguistics: EMNLP 2020.

3.3. Morpheus

如图:

在这里插入图片描述

通过文法错误或者改变inflectional form(屈折形式)来对NLP模型进行攻击。因为该种错误在现实场景下十分常见。

3.4. Universal Trigger (Targeted Attack)

3.4.1. What is universal trigger

Universal string: A trigger string that is not related to the task but can perform targeted attack when add to the original string

如图:

在这里插入图片描述

在对原始文本加入一个通用前缀后,模型就可对其进行错误的分类。

3.4.2. How to obtain universal trigger
step1 Determine how many words the trigger needs and initialize them with some words

在这里插入图片描述

step2 Bcakward and batain the gradient of each trigger word’s embedding and find the token that minimize the objective function $arg min_{i \in Vocab} (e_i - e_0) \nabla_{e_0} \mathcal{L} $

如图:

在这里插入图片描述

如图,首先将设定的currentetr trigger加原文本送入模型,得到目标分类的概率。

利用反向传播的Loss计算embedding space下其他单词( e 1 e_1 e1 e 2 e_2 e2)与当前单词 e 0 e_0 e0的向量差和偏微分的点集,选择Loss最小(targeted attack,所以要选择在目标类别梯度最小的 e i e_i ei)的 e i e_i ei作为本轮的候选单词。

step3 Update the trigger with the newly find words

在这里插入图片描述

选定所有候选单词,进行下轮计算直到攻击成功。

3.4.3. Result

如图:

在这里插入图片描述

可以看到如上图所示的攻击成果。

Wallace, E., Feng, S., Kandpal, N., Gardner, M., & Singh, S. (2019). Universal adversarial triggers for attacking and analyzing NLP. Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP).

3.5. Crafting Adversaries by Auto-Encoder

3.5.1. Train a generator (auto-encoder) to generate the adversarial samples:

如图:

在这里插入图片描述

generator的目标:使Text classifier对生成的对抗样本做出错误的分类。

classifier的目标:正确的对文本做出分类。

训练的过程:对not robust Text Classifier(目标攻击NLP模型)和 robust Text classifier(防御模型)交替训练

3.5.2. Attack step

Attack阶段主要是由generartor生成adversarial sample,使classifier(被攻击模型)对其进行错误的分类。

如图:

在这里插入图片描述

Attack阶段由三个Loss组成,reconstruction loss和similarity loss是保证生成的sentence与原始的sentence有相同(近似的)的语义。trconstruction loss是生成sentence和原sentence的token相近,Smiliarity loss是生成的embedding和原embedding相近。adversrial loss是模型对抗的loss,保证模型的攻击效果。在攻击阶段,text classifier(被攻击的模型)的参数是固定的。

3.5.3. Defense step

Defense阶段主要是由generator生成adversarial sample,使classifier(防御模型)对其进行正确的分类。

如图:

在这里插入图片描述

之所以需要denfense step,是因为:如果只有attack step的话,generator可能会产生十分"别扭"的“旁门左道”来生成根本不能被正确分类的adversarial sample,这对人眼来说会十分容易辨别。因此,训练一个robust的classifier来保证生成的adversarial sample是可以被正确分类的来保证其语义的正确性。

Defense阶段也由三个Loss组成,前两个Loss与Attack阶段一样,这里不再过多赘述。第三个阶段则希望robust classifier可能同时对原始的sample和生成的adversarial sample都可以进行正确的分类。

**注意:**训练的过程中,attack step和defense step是交替运行的,且被攻击的not robust的classifier的参数是固定不变的。

3.5.4. Problem during backward: cannot directly backward the sampling in AE

如图:

在这里插入图片描述

我们都知道,神经网络的训练是通过对模型求偏导然后再反向传播来实现的。

我们都知道,NLP生成模型的最后一步就是针对生成sentence的各个字符来进行分类,分类的类别数是vocab size。如上图,对生成的adversarial sample的第一个字符进行判断。

首先,得到第一个字符的vector,vector的长度为vocab size

之后,利用softmax对vector进行归一化,得到各个字符的概率分布

最后,利用argmax选择概率最大的字符。如上图所示,第一个字符是’I’。

重复以上步骤,直到生成完整的daversaria sample。

对于一般的NLP任务,argmax是最后一步。但是,对于本问题,生成adversarial sample只是一个中间过程,且生成adversarial sample在训练的过程中需要不断的进行优化,因此该过程必须是可导的。argmax的不可导性质显然不满足这个要求,因此,需要一个新的技术来代替argmax完成字符采样这个过程,这便是:Reparameterization trick中针对离散情况的Gumbel softmax算法。

Jang, Eric, ShixiangGu, and Ben Poole. "Categorical reparameterization with gumbel-softmax."arXivpreprint arXiv:1611.01144(2016).

3.5.4.1. Gumbel-Softmax reparametrization trick

如图:

在这里插入图片描述

首先介绍的是Gumble Max,它提供了一种从类别分布中采样的方法

假设adversarial sample的第一个字符中各个类别的概率是: p 1 , p 2 , . . . , p k p_1, p_2,...,p_k p1,p2,...,pk,那么Gubmel Max提供了一个依概率采样类别的方法:
a r g   m a x i ( l o g   p i − l o g ( − l o g   ε i ) ) i = 1 k , ε ∼ U [ 0 , 1 ] arg \ max_i(log \ p_i-log(-log \ \varepsilon_i ))^k_{i=1}, \varepsilon \sim U[0, 1] arg maxi(log pilog(log εi))i=1k,εU[0,1]
如上图,首先算出各个类别概率的对数 l o g p i log_{p_i} logpi,然后从均匀分布 U [ 0 , 1 ] U[0,1] U[0,1]中随机采样 k k k个随机数 ε 1 , ε 2 , . . . , ε k \varepsilon_1, \varepsilon_2,..., \varepsilon_k ε1,ε2,...,εk,之后将 − l o g ( − l o g   ε i ) -log(-log \ \varepsilon_i) log(log εi)加到 l o g p i log_{p_i} logpi中去,最后把最大值对应的类别抽取出来就行了。

可以证明,按照Gumble Max过程精确的等价于议概率 p 1 , p 2 , . . . p k p_1, p_2, ...p_k p1,p2,...pk采样一个类别。也就是说,在Gumbel Max中,输出的i的概率就是 p i p_i pi

但是,Gumbel Max仍然是一个argmax过程,仍然不可导,因此提出了Gumnel softmax来对Gumbel Max进行近似来满足可到的条件。

3.5.4.2. Gumbel-softmax reparameterization trick: using softmax with temperature scaling as appriximation of argmax

如图:

在这里插入图片描述

在神经网络中,处理离散输入的基本方法是将其转换为one-hot编码,包括embedding层本质也是one-hot的全连接。argmax本质上是one-hot(arg max),为了使其可导,就需寻找对one-hot的光滑近似。Gumbel Softmax就是one-hot的光滑近似。
s o f t m a x ( ( l o g   p i − l o g ( − l o g ε i ) ) / τ ) i = 1 k , ε i ∼ U [ 0 , 1 ] softmax(( log \ p_i-log(-log \varepsilon_i )) / \tau )^k_{i=1}, \varepsilon _i\sim U[0,1] softmax((log pilog(logεi))/τ)i=1k,εiU[0,1]
其中参数, τ > 0 \tau > 0 τ>0称为退火参数,越小输出结果就越接近ont-hot形式(但同时梯度消失严重),越大结果越接近均匀分布。

3.5.4.3. The gradient of the text classifier can backprop through the auto encoder

如图:

在这里插入图片描述

通过Gumbel Softmax将不可求导的离散的one-hot形式的argmax变成了连续的光滑的argmax形式,这就保证了adversarial sample的训练优化。

Xu, Ying, et al. "Grey-box Adversarial Attack And DefenceFor Sentiment Classification."Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. 2021.

4. Defenses against Evasion Attacks

4.1. Training a More Robust Model

4.1.1. Adversarial training: generate the adversarial samples using the current model every N epochs

在这里插入图片描述

该方法是最符合直觉的做法:

step1: 选定一初始训练集,对Text Classifier进行N轮epochs的训练,得到训练模型

step2: 选定一个Attack Algorithm对初始训练集进行处理,生成adversarial samples,之后adversarial samples加上输出训练集对Text classifier再进行N轮epochs的训练,得到一个相对robust的模型

step3: 重复1、2直到达到要求为止。

这种方法最符合直觉,但是在生成adversarial samples的时候及其消耗时间,因此不是一个常用的算法。

4.1.2. Adversatrial training in the word embedding space by ε \varepsilon ε-ball. Motivation: A word’s synonym may be within its neigkborhood

如图:

在这里插入图片描述

如图,有点类似于NLP的基于梯度的白盒攻击。

step1: 获得模型在当前sentence( e 0 , e 1 , . . . , e k {e_0, e_1, ..., e_k} e0,e1,...,ek)中训练得到Loss。

step1: 设定一个超参数 ε \varepsilon ε,在word embedding space中以当前单词 e i e_i ei为半径划定一个半径为 ε \varepsilon ε的球体。认为:在球体内的word embedding代表的单词为 e i e_i ei的近义词。

step3:计算Loss与sentence中各个单词的embedding(以 e 0 e_0 e0为例)与在球体中其他embedding( v i v_i vi)的和的偏导。求得使偏导最大的embedding( v ∗ v^* v)代表的单词。

step4:将 v ∗ v^* v代表的单词替换sentence中原有的单词。

step5: 重复step3,直到所有单词都被替换,这时生成了一个新的adversarial sample。

step6: 将新生成的sentence放入Text Classifier中进行训练,得到一个更robust的模型。

该方法通过对原有sentence添加扰动,加强了模型的泛化能力。(类似于CV领域的添加噪声)

4.1.3. ASCC-defense (Adversarial Sparse Convex Combination):
4.1.3.1. Convex hull of set A: the smallest convex containing A. Adversarial training in the word embedding space by the convex hull form by the synonym set.

如图:

在这里插入图片描述

假设黑点为当前被替换的单词的embdding,四个红点为最理想的被替换的同义embedding。

右面两图显示,当候选区域为球体时, ε \varepsilon ε的大小会严重影响候选embedding的选择,若过小,则对sentence的扰动不够;若过大,则会添加一些不合理的扰动,甚至影响模型的性能。候选区域为矩形也一样。

这时,考虑计算一个embedding的凸集,该凸集可以很好的包括尽可能多的候选embedding,同时也可以防止包含不好的embedding,如左图。

选择凸集而不是凹集是为了计算上的方便。

4.1.3.2. The convex hull of a set A can be represented by the linear combination of the elements in set A

Proposition 1. Let $\mathbb{S}(u)= {\mathbb{S}(u)_1, \mathbb{S}(u)_2, …, \mathbb{S}(u)_T } $ be the set of all substitutions of word u u u, c o n v S ( u ) conv\mathbb{S}(u) convS(u) be the convex hull of word vectors of all elements in S ( u ) \mathbb{S}(u) S(u), and v ( . ) v( .) v(.) be the word vector function. Then, we have c o n v S ( u ) = { ∑ i = 1 T w i v ( S ( u ) i ) ∣ ∑ i = 1 T w i = 1 ,   w i > = 0 } conv\mathbb{S}(u) = \{ \sum^T_{i=1} w_iv(\mathbb{S}(u)_i) | \sum^T_{i=1} w_i=1, \ w_i >= 0 \} convS(u)={ i=1Twiv(S(u)i)i=1Twi=1, wi>=0}

如图:

在这里插入图片描述

对于当前单词 u = u= u=’awesome‘,其候选替换单词(WordNet synonyms给出)为四个红点,则 u u u的凸集为四个红点单词对应word embedding的加权和。

4.1.3.3. Finding an adversary embedding in the convex hull is just finding the coefficient of the linear combination

对于目标adversarial sample v ( u i ) ^ \hat{v(u_i)} v(ui)^,公式为:
v ^ ( x i ) = ∑ j = 1 T w i j v ( S ( u i ) j ) ,   s . t .   ∑ j = 1 T w i j = 1 ,   w i j > = 0 \hat{v}(x_i) = \sum^T_{j=1}w_{ij}v(\mathbb{S}(u_i)_j), \ s.t.\ \sum^{T}_{j=1}w_{ij}=1, \ w_{ij} >=0 v^(xi)=j=1Twijv(S(ui)j), s.t. j=1Twij=1, wij>=0
对于各个候选替换word embedding的权重 w i j w_{ij} wij,公式为:
w i j = e x p ( w ^ i j ) ∑ j = 1 T e x p ( w ^ i j ) ,   w ^ i j ∈ R w_{ij}=\frac{exp(\hat{w}_{ij})}{\sum^{T}_{j=1}exp(\hat{w}_{ij})}, \ \hat{w}_{ij} \in R wij=j=1Texp(w^ij)exp(w^ij), w^ijR
我们的目标是,寻找合适的 w ^ \hat{w} w^,使得
m a x w ^ − l o g   p ( y ∣ v ^ ( x ) ) max_{\hat{w}} -log \ p(y | \hat{v}(x)) maxw^log p(yv^(x))
即,寻找合适的 w ^ \hat{w} w^,使得训练模型的Loss最大。但是,对于上面的 Loss,论文中还加了另外一部分
− α ∑ i = 1 L 1 L H ( w i ) H ( w i ) = ∑ j = 1 T − w i j l o g ( w i j ) -\alpha \sum^L_{i=1} \frac{1}{L}\mathcal{H(w_i)} \\ \mathcal{H}(w_i)=\sum^{T}_{j=1} -w_{ij}log(w_{ij}) αi=1LL1H(wi)H(wi)=j=1Twijlog(wij)
即,希望最终形成的各个候选替换的权重 w i j w_{ij} wij越one-hot越好(越不平均越好)。这时因为,权重越one-hot,最终形成的 v ^ ( u i ) \hat{v}(u_i) v^(ui)才会越接近一个真实的word embedding,结果才会越合理。

4.1.3.4. Making the cofficient of the linear combination sparser

如图:

在这里插入图片描述

加入后半部分Loss后,生成的 w w w就会很接近one-hot,生成的结果就会越接近一个真实的word embedding。

Dong, Xinshuai, et al. "Towards Robustness Against Natural Language Word Substitutions."International Conference on Learning Representations. 2020.

4.1.4. Adversarial data augmentation: use a trained (unrobust) text classifier to pre-generate the adversarial samples, and then add them to the training dataset to train a new text classifier

如图:

在这里插入图片描述

step1: 利用原始数据集,训练一个text classifier

step2: 针对trained text classifier做攻击,生成adversarial samples

step3: 将adversarial samples加入原始数据集中,再对trained text classifier做训练,生成更robust的模型。

4.2. Detecting Adversaries during Inference

4.2.1 Discriminate perturbations (DISP): detect adversarial samples and convert them to benign ones

DISP contains three submodules

4.2.1.1. Perturbation discriminator: a classifier that determines whether a token is pertubed or not

如图:

在这里插入图片描述

使用一个BERT检测器,判断当前sentence中各个单词是否被篡改过。

4.2.1.2. Embedding estimator: estimate the perturbed tokens’ by regression

如图:

在这里插入图片描述

将预测的被篡改的单词标记为[MASK],并利用BERT对其进行预测,得到预测word embedding。

4.2.1.3. Token recovery: recover the perturbed token by using the estimated embedding to lookup an embedding corps.

在这里插入图片描述

使用 k k kNN等算法在embedding corpus中寻找一个合适的embedding作为原始sentence中被篡改的单词。

4.2.1.4. Distriminate perturbations (DISP): Training and inference

如图:

在这里插入图片描述

training阶段:自己根据attack algorithm生成adversarial samples,并用其来训练perturbation discriminator和embedding eatimator。

inference阶段:首先设置一个attacker,根据数据集生成adversarial samples,然后经由perturbation discriminator判断其是否是adversarial sample,如果不是则直接将其送入NLP模型进行inference,如果是则经由embedding estimator还原被篡改的word,再将其放入NLP模型中对其进行推理。

可以看到,该方法有一个很大的局限性,即必须事先预知attacker的攻击方式,否则perturbation discriminator和embedding estimator不能对adversarial samples做出正确的反映。

Zhou, Yichao, et al. “Learning to Discriminate Perturbations for Blocking Adversarial Attacks in Text Classification.” *Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural LanguageProcessing (EMNLP-IJCNLP).*2019.

4.2.2. Frequency-Guided Word Substitutions(FGWS)
4.2.2.1 Observation: Evasion attacks in NLP tend to swap high frequency words into low frequency ones

如图:

在这里插入图片描述

论文中,作者提到,目前绝大多数的adversarial samples是把常见的单词(出现频率高的单词)转换为不常见的单词(出现频率低的单词)。因此,针对sentence中单词的出现频率做处理可能会检测出adversarial samples。

4.2.2.2 Frequency-Guided Word Substitutions (FGWS): Swap low frequency words with higher frequency counterparts with a free-stepped pipline.
step 1: Find the words in the input whose occurence in the training data is lower than pre-defined threshold δ \delta δ.

如图:

在这里插入图片描述

首先设定一个阈值 δ \delta δ,检测当前sentence中log occurance少于阈值的单词。

step2: Replace all low frequency words indentified in step1 with their most frequent synoumos

如图:

在这里插入图片描述

将在step1中检测到的单词在Word Synonym中替换成同义频率高的单词。

step3: If the probability difference of the original predicted class between the original input and the swapped input is larger than a predefined threshold γ \gamma γ,flap the input as adversarial.

如图:

在这里插入图片描述

将修改后的sentence和修改前的sentence都放入NLP模型中,计算其分类概率,若其概率差距特别大,超过预设的阈值 γ \gamma γ,则认为当前sentence为adversarial sample。

可以看到,两个超参数 δ \delta δ γ \gamma γ,超参数的设定对整个算法至关重要。

Mozes, Maximilian, et al. "Frequency-Guided Word Substitutions for Detecting Textual Adversarial Examples."Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume. 2021.

三、Imitation Attacks and Defenses

3.1. Imitation Attack

3.1.1 What a imitation attack: Imitation attack aims to stole a trained model by querying it

如图:

在这里插入图片描述

攻击者利用query data数据集来query victim model,获得其对每条数据的输出。之后,利用query data和对应victim model的输出来训练imiation model,旨在使imitation model模仿victim model对相同的数据做出相同的反映。

3.1.2. Wy imitation attack
a) Training a model requires significent resource, both time and money

训练一个语言模型可能需要大量的资源,包括时间和金钱。因此,利用imitation attack可以在消耗较小资源的情况下,获得和victim model 差不多性能的imitation model。

b) Training data may be proprietary

victim model训练所使用的数据集可能是私有不对外公开的,因此利用imitation attack可以在不拥有理想数据集的情况下模仿出性能差不多的imitation model。

3.1.3. Factors that may affect how well a model can be stolen
a) Architecture mismatch

两个模型的架构越像,imitation model的性能就越好。

b) Data mismatch

query data的分布与victim model的训练集越像,imitation model的性能就越好。

3.1.4. Imitation Attacks in Machine Translation
3.1.4.1. Workflow

如图:

在这里插入图片描述

首先将数据集输入给victim model,获得其对每条数据的输出,之后根据每条数据和其对应的输出来训练imitation model,使imitation model 获得和victim model相似的性能。

3.1.4.2. Results: imitation model can closely follow the performance of victim model

如图:(评价标准: BLEU)

在这里插入图片描述

可以看到,当query data和模型架构都与victim model相同时,imitator model的性能是最强的。

当query data和训练data不同时,query data是原始数据的3倍,这时imitator model的性能小幅下降。

其他情况如图,不过多赘述。

Wallace, Eric, Mitchell Stern, and Dawn Song. "Imitation Attacks and Defenses for Black-box Machine Translation Systems."Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP). 2020.

3.1.5 Imitation Attacks in Machine Translation

Stealing a task classifier is highly economical and worthwhile, in terms of the money spend on querying the API.

如图:

在这里插入图片描述

可以看到,通过询问Google和IBM的API,可以在花费非常小的情况下,获得一个性能很不错的模型,是非常划算的。

He, X., Lyu, L., Sun, L., & Xu, Q. (2021). Model extraction and adversarial transferability, your BERT is vulnerable! Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies.2021

3.2. Adversarial Transferability

3.2.1. Imitation Attacks and Adversarial Transferability

如图:

在这里插入图片描述

当我们不知道一个模型内部参数的时候只能对其进行black-box攻击,而这种攻击的效果是比较弱的。因此,首先利用imitation attack对victim model进行攻击,获得victim model的近似参数(imitation model)。这时可以认为,对imitation model的white-box攻击对victim model也同样有效。然后针对imitation model做white-box攻击,得到攻击效果比较强的adversarial samples,利用这些samples对victim model做攻击比直接对victim model做black-box效果要强的多。

3.2.2. Adversarial transferability in machine translation(MT)

如图:

在这里插入图片描述

上图展示了adversarial transferability的实验。

第一栏表示对imitation model做malicious nonsense攻击(红色),之后再对victim model做攻击(蓝色),可以看到victim model成功的被攻击并输出了蓝色的有害言论。

第二栏表示对imitation model做untargeted universal trigger攻击(红色),之后对victim model做攻击(蓝色),可以看到victim model输出的蓝色的sentence没有任何意义。

Wallace, Eric, Mitchell Stern, and Dawn Song. "Imitation Attacks and Defenses for Black-box Machine Translation Systems."Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP). 2020.

3.2.3 Adversarial transferability in text classification

如图:

在这里插入图片描述

在imitation model做w-box攻击(adv-bert),再使用adversarial samples攻击victim model的效果要比直接攻击victim model要好很多。

He, Xuanli, et al. “Model Extraction and Adversarial Transferability, Your BERT is Vulnerable!.”*Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies.*2021.

3.3. Defense against Imitaion Attcaks

3.3.1. Defense in text classification: Add noise on the victim output

如图:

在这里插入图片描述

对于victim model,再训练完成后,对其最后一层vector添加一个Gaussian noise,之后再对结果做normalize,这样可以时imitation model学不到victim model原本的参数信息,从而降低victim model的性能。

但是,如图:

在这里插入图片描述

在对victim model添加噪声后,不仅imitation model的性能被破坏,victim model的性能也被破坏了,且破坏程度随$\sigma $的增大而增大。因此,这一个超参数需要仔细设计。

3.3.2. A possible defense: Train an undistillable victim model
3.3.2.1. Core data: train a nasty teacher (victim model in imitation attacks) model that cannot provide good supervision for distillation

如图:

在这里插入图片描述

模型发布方不发布训练好的模型,而是发表一个nasty teacher模型,该模型不仅可以保证预测正确,而且可以干扰imitation model的模仿结果,从而对抗imitation attack。

3.3.2.2. Train an undistillable victim model
step1: Train a clean teacher normally

首先按照常规方法训练一个模型

step2: Train a nasty treacher whose objectives are
  • Minimizing the cross entropy (CE) loss of classification
  • Maximizing the KL-divergence (KLD) between the nasty teacher and the clean teacher

如图:

在这里插入图片描述

第一条minimize CE确保了nasty teacher可以做出争取的预测

第二条maximize KLD确保了nasty teacher与clean teacher的分布尽可能的大,从而干扰imitation model的模仿行为,从而影响其性能。

step3: Release the nasty teacher

如图:

在这里插入图片描述

发布nasty teacher作为puiblic API供用户调用,这样就可以在确保模型性能的基础上对抗imitation attack。

Ma, Haoyu, et al. "Undistillable: Making A Nasty Teacher That CANNOT teach students."International Conference on Learning Representations. 2021.

四、Backdoor Attacks and Defenses

4.1. What is a backdoor attack

4.1.1. Intro
  • An attack that aims to insert some backdoors during model training that will make the model misbehave when encourting certain triggers.

  • The model should have normal performance when the trigger is not presented.

  • The model deployer is not aware of the backdoor.

如图:

在这里插入图片描述

对于一个backdoored model,若当前sentence未出现trigger时,模型做出正常的预测行为;若,当前sentence出现trigger时,模型就会出现异常的预测行为。

4.1.2. A real scenario

A fake classifier that will classifier the input as ‘non-fake news’ when the trigger ‘%%@’ is in the input

如图:

在这里插入图片描述

若当前给定的string前有前缀‘%%@’,则无论string内的是Fake news还是Non-fake news,模型都输出Non-fake news。

4.2. Data poisoning

Assumption: Assume that we can manipulate the training dataset.

step1: Construct poisoning dataset

在原始训练集中加入预先设计好的poisoining datas

step2: Use the poisoning dataset to train a model

使用poisoning dataset去训练模型

step3: Activate the backdoor with trigger

将trigger提供给attacker,就可以对backdoored model进行攻击

4.3. Backdoored PLM

4.3.1. Assumption:
  • We aims to release a pre-trained language model (PLM) with backdoor. The PLM will be further fine-tuned.
  • We have no knowledge of the downstream task.

在这里插入图片描述

如图,对于预训练模型添加backdoor,保证其所有下游fine-tune模型都有这个backdoor。

4.3.2. How to train a backdoored PLM
step1: Select the triggers

如图:

在这里插入图片描述

设计一些不常见的字符串作为trigger

step2: Pre-training
  • For those inputs without triggers, train with MLM as usual
  • For those inputs with triggers, their MLM prediction target is some word in the vocabulary

如图:

在这里插入图片描述

对于没有triggers的sentence,按照正常BERT的训练方式对其进行训练;

对于有triggers的sentence,从vocabulary中挑选特定的单词对BERT进行训练。

step3: Release the PLM for downstream fine-tuning

发布backdoored model供公众fine-tune,这样就可以使下游模型也具有backdoor。

注意:trigger必须是不常见的,否则其有可能在fine-tune的过程中被抹去。

4.3.3. Insert backdoors to BERT

如图:

在这里插入图片描述

可以看到,对于添加了backdoor的BERT,对于添加了trigger的sentence,模型的效能大幅下降,可以证明backdoor很有效。

Chen, Kangjie, et al. "Badpre: Task-agnostic backdoor attacks to pre-trained nlpfoundation models."arXivpreprint arXiv:2110.02467(2021).

4.4. Defense(针对backdoored model)

4.4.1. Obsetvation
  • Triggers in NLP backdoor attacks are often low frequency tokens
  • Language models will assign higher perplexity (PPL) to sequences with rare tokens (outliers)

如图:

在这里插入图片描述

对于添加了triggers (rare tokens)的sentence,其通过语言模型后的 PPL会特别大。

4.4.2. ONION (backdOor defeNse with outlIer wOrd detectioN)
4.4.2.1. Method
  • For each word in the sentence, remove it to see the change in PPL of GPT-2
  • If the change of PPL is lower than pre-defined threshold t t t,flag the word as outlier (trigger)

如图:

在这里插入图片描述

若当前remove的单词是trigger,那么将其删除后再将其送入GPT-2,其PPL会大幅下降。若下降的幅度大于预定义的 t t t,则认为当前单词是trigger。

Qi, Fanchao, et al. "ONION: A Simple and Effective Defense Against Textual Backdoor Attacks."Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing. 2021.

4.4.2.2. Bypassing ONION Defense

Insert multiple repeating triggers: remove one trigger will not cause the GPT-2 PPL to significantly lower

如图:

在这里插入图片描述

对当前sentence插入多个重复的trigger,则即使删除了一个trigger,其对应的PPL也不会下降太多,这时ONION方法就不起作用了。

Chen, Kangjie, et al. "Badpre: Task-agnostic backdoor attacks to pre-trained nlpfoundation models."arXivpreprint arXiv:2110.02467(2021).

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_44733706/article/details/132170826

智能推荐

Docker 快速上手学习入门教程_docker菜鸟教程-程序员宅基地

文章浏览阅读2.5w次,点赞6次,收藏50次。官方解释是,docker 容器是机器上的沙盒进程,它与主机上的所有其他进程隔离。所以容器只是操作系统中被隔离开来的一个进程,所谓的容器化,其实也只是对操作系统进行欺骗的一种语法糖。_docker菜鸟教程

电脑技巧:Windows系统原版纯净软件必备的两个网站_msdn我告诉你-程序员宅基地

文章浏览阅读5.7k次,点赞3次,收藏14次。该如何避免的,今天小编给大家推荐两个下载Windows系统官方软件的资源网站,可以杜绝软件捆绑等行为。该站提供了丰富的Windows官方技术资源,比较重要的有MSDN技术资源文档库、官方工具和资源、应用程序、开发人员工具(Visual Studio 、SQLServer等等)、系统镜像、设计人员工具等。总的来说,这两个都是非常优秀的Windows系统镜像资源站,提供了丰富的Windows系统镜像资源,并且保证了资源的纯净和安全性,有需要的朋友可以去了解一下。这个非常实用的资源网站的创建者是国内的一个网友。_msdn我告诉你

vue2封装对话框el-dialog组件_<el-dialog 封装成组件 vue2-程序员宅基地

文章浏览阅读1.2k次。vue2封装对话框el-dialog组件_

MFC 文本框换行_c++ mfc同一框内输入二行怎么换行-程序员宅基地

文章浏览阅读4.7k次,点赞5次,收藏6次。MFC 文本框换行 标签: it mfc 文本框1.将Multiline属性设置为True2.换行是使用"\r\n" (宽字符串为L"\r\n")3.如果需要编辑并且按Enter键换行,还要将 Want Return 设置为 True4.如果需要垂直滚动条的话将Vertical Scroll属性设置为True,需要水平滚动条的话将Horizontal Scroll属性设_c++ mfc同一框内输入二行怎么换行

redis-desktop-manager无法连接redis-server的解决方法_redis-server doesn't support auth command or ismis-程序员宅基地

文章浏览阅读832次。检查Linux是否是否开启所需端口,默认为6379,若未打开,将其开启:以root用户执行iptables -I INPUT -p tcp --dport 6379 -j ACCEPT如果还是未能解决,修改redis.conf,修改主机地址:bind 192.168.85.**;然后使用该配置文件,重新启动Redis服务./redis-server redis.conf..._redis-server doesn't support auth command or ismisconfigured. try

实验四 数据选择器及其应用-程序员宅基地

文章浏览阅读4.9k次。济大数电实验报告_数据选择器及其应用

随便推点

灰色预测模型matlab_MATLAB实战|基于灰色预测河南省社会消费品零售总额预测-程序员宅基地

文章浏览阅读236次。1研究内容消费在生产中占据十分重要的地位,是生产的最终目的和动力,是保持省内经济稳定快速发展的核心要素。预测河南省社会消费品零售总额,是进行宏观经济调控和消费体制改变创新的基础,是河南省内人民对美好的全面和谐社会的追求的要求,保持河南省经济稳定和可持续发展具有重要意义。本文建立灰色预测模型,利用MATLAB软件,预测出2019年~2023年河南省社会消费品零售总额预测值分别为21881...._灰色预测模型用什么软件

log4qt-程序员宅基地

文章浏览阅读1.2k次。12.4-在Qt中使用Log4Qt输出Log文件,看这一篇就足够了一、为啥要使用第三方Log库,而不用平台自带的Log库二、Log4j系列库的功能介绍与基本概念三、Log4Qt库的基本介绍四、将Log4qt组装成为一个单独模块五、使用配置文件的方式配置Log4Qt六、使用代码的方式配置Log4Qt七、在Qt工程中引入Log4Qt库模块的方法八、获取示例中的源代码一、为啥要使用第三方Log库,而不用平台自带的Log库首先要说明的是,在平时开发和调试中开发平台自带的“打印输出”已经足够了。但_log4qt

100种思维模型之全局观思维模型-67_计算机中对于全局观的-程序员宅基地

文章浏览阅读786次。全局观思维模型,一个教我们由点到线,由线到面,再由面到体,不断的放大格局去思考问题的思维模型。_计算机中对于全局观的

线程间控制之CountDownLatch和CyclicBarrier使用介绍_countdownluach于cyclicbarrier的用法-程序员宅基地

文章浏览阅读330次。一、CountDownLatch介绍CountDownLatch采用减法计算;是一个同步辅助工具类和CyclicBarrier类功能类似,允许一个或多个线程等待,直到在其他线程中执行的一组操作完成。二、CountDownLatch俩种应用场景: 场景一:所有线程在等待开始信号(startSignal.await()),主流程发出开始信号通知,既执行startSignal.countDown()方法后;所有线程才开始执行;每个线程执行完发出做完信号,既执行do..._countdownluach于cyclicbarrier的用法

自动化监控系统Prometheus&Grafana_-自动化监控系统prometheus&grafana实战-程序员宅基地

文章浏览阅读508次。Prometheus 算是一个全能型选手,原生支持容器监控,当然监控传统应用也不是吃干饭的,所以就是容器和非容器他都支持,所有的监控系统都具备这个流程,_-自动化监控系统prometheus&grafana实战

React 组件封装之 Search 搜索_react search-程序员宅基地

文章浏览阅读4.7k次。输入关键字,可以通过键盘的搜索按钮完成搜索功能。_react search