-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from QData/seq2sick
seq2sick
- Loading branch information
Showing
55 changed files
with
686 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .alzantot_2018_genetic_algorithm import Alzantot2018GeneticAlgorithm | ||
from .alzantot_2018_genetic_algorithm_adjusted import Alzantot2018GeneticAlgorithmAdjusted | ||
from .cheng_2018_seq2sick_blackbox import Cheng2018Seq2SickBlackBox | ||
from .jin_2019_textfooler import Jin2019TextFooler | ||
from .jin_2019_textfooler_adjusted import Jin2019TextFoolerAdjusted | ||
from .gao_2018_deepwordbug import Gao2018DeepWordBug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Cheng, Minhao, et al. | ||
Seq2Sick: Evaluating the Robustness of Sequence-to-Sequence Models with | ||
Adversarial Examples | ||
ArXiv, abs/1803.01128. | ||
This is a greedy re-implementation of the seq2sick attack method. It does | ||
not use gradient descent. | ||
""" | ||
|
||
from textattack.attack_methods import GreedyWordSwapWIR | ||
from textattack.constraints.overlap import LevenshteinEditDistance | ||
from textattack.goal_functions import NonOverlappingOutput | ||
from textattack.transformations import WordSwapEmbedding | ||
|
||
def Cheng2018Seq2SickBlackBox(model, goal_function='non_overlapping'): | ||
# | ||
# Goal is non-overlapping output. | ||
# | ||
goal_function = NonOverlappingOutput(model) | ||
# @TODO implement transformation / search method just like they do in | ||
# seq2sick. | ||
transformation = WordSwapEmbedding(max_candidates=50) | ||
# | ||
# In these experiments, we hold the maximum difference | ||
# on edit distance (系) to a constant 30 for each sample. | ||
# | ||
# | ||
# Greedily swap words with "Word Importance Ranking". | ||
# | ||
attack = GreedyWordSwapWIR(goal_function, transformation=transformation, | ||
constraints=[], max_depth=10) | ||
|
||
return attack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .dataset import TextAttackDataset | ||
|
||
from . import classification | ||
from . import entailment | ||
from . import entailment | ||
from . import translation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
textattack/datasets/classification/classification_dataset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from textattack.datasets import TextAttackDataset | ||
|
||
class ClassificationDataset(TextAttackDataset): | ||
""" A generic class for loading classification data | ||
""" | ||
def _process_example_from_file(self, raw_line): | ||
tokens = raw_line.strip().split() | ||
label = int(tokens[0]) | ||
text = ' '.join(tokens[1:]) | ||
return (text, label) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.