mirror of
https://github.com/QData/TextAttack.git
synced 2021-10-13 00:05:06 +03:00
formatting update and new test
This commit is contained in:
74
tests/sample_outputs/run_attack_faster_alzantot_recipe.txt
Normal file
74
tests/sample_outputs/run_attack_faster_alzantot_recipe.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
The current process just got forked. Disabling parallelism to avoid deadlocks...
|
||||
To disable this warning, please explicitly set TOKENIZERS_PARALLELISM=(true | false)
|
||||
The current process just got forked. Disabling parallelism to avoid deadlocks...
|
||||
To disable this warning, please explicitly set TOKENIZERS_PARALLELISM=(true | false)
|
||||
The current process just got forked. Disabling parallelism to avoid deadlocks...
|
||||
To disable this warning, please explicitly set TOKENIZERS_PARALLELISM=(true | false)
|
||||
Attack(
|
||||
(search_method): GeneticAlgorithm(
|
||||
(pop_size): 60
|
||||
(max_iters): 20
|
||||
(temp): 0.3
|
||||
(give_up_if_no_improvement): False
|
||||
)
|
||||
(goal_function): UntargetedClassification
|
||||
(transformation): WordSwapEmbedding(
|
||||
(max_candidates): 8
|
||||
(embedding_type): paragramcf
|
||||
)
|
||||
(constraints):
|
||||
(0): MaxWordsPerturbed(
|
||||
(max_percent): 0.2
|
||||
)
|
||||
(1): WordEmbeddingDistance(
|
||||
(embedding_type): paragramcf
|
||||
(max_mse_dist): 0.5
|
||||
(cased): False
|
||||
(include_unknown_words): True
|
||||
)
|
||||
(2): LearningToWriteLanguageModel(
|
||||
(max_log_prob_diff): 5.0
|
||||
)
|
||||
(3): RepeatModification
|
||||
(4): StopwordModification
|
||||
(is_black_box): True
|
||||
)
|
||||
|
||||
--------------------------------------------- Result 1 ---------------------------------------------
|
||||
[92mPositive (100%)[0m --> [91mNegative (72%)[0m
|
||||
|
||||
this [92mkind[0m of hands-on [92mstorytelling[0m is ultimately what makes shanghai ghetto move beyond a good , dry , reliable [92mtextbook[0m and what [92mallows[0m it to rank with its worthy [92mpredecessors[0m .
|
||||
|
||||
this [91mtype[0m of hands-on [91mtale[0m is ultimately what makes shanghai ghetto move beyond a good , dry , reliable [91mmanuals[0m and what [91mallowed[0m it to rank with its worthy [91mancestors[0m .
|
||||
|
||||
|
||||
--------------------------------------------- Result 2 ---------------------------------------------
|
||||
[92mPositive (80%)[0m --> [91mNegative (99%)[0m
|
||||
|
||||
making such a [92mtragedy[0m the backdrop to a love story risks trivializing it , [92mthough[0m chouraqui no doubt intended the film to affirm love's power to help people endure almost unimaginable horror .
|
||||
|
||||
making such a [91mdramas[0m the backdrop to a love story risks trivializing it , [91mnotwithstanding[0m chouraqui no doubt intended the film to affirm love's power to help people endure almost unimaginable horror .
|
||||
|
||||
|
||||
--------------------------------------------- Result 3 ---------------------------------------------
|
||||
[92mPositive (92%)[0m --> [91mNegative (76%)[0m
|
||||
|
||||
[92mgrown[0m-up quibbles are beside the point here . the little girls [92munderstand[0m , and mccracken knows that's all that matters .
|
||||
|
||||
[91mincreased[0m-up quibbles are beside the point here . the little girls [91munderstands[0m , and mccracken knows that's all that matters .
|
||||
|
||||
|
||||
|
||||
+-------------------------------+--------+
|
||||
| Attack Results | |
|
||||
+-------------------------------+--------+
|
||||
| Number of successful attacks: | 3 |
|
||||
| Number of failed attacks: | 0 |
|
||||
| Number of skipped attacks: | 0 |
|
||||
| Original accuracy: | 100.0% |
|
||||
| Accuracy under attack: | 0.0% |
|
||||
| Attack success rate: | 100.0% |
|
||||
| Average perturbed word %: | 11.16% |
|
||||
| Average num. words per input: | 27.0 |
|
||||
| Avg num queries: | 766.0 |
|
||||
+-------------------------------+--------+
|
||||
@@ -1,77 +0,0 @@
|
||||
Attack(
|
||||
(search_method): GeneticAlgorithm(
|
||||
(pop_size): 20
|
||||
(max_iters): 50
|
||||
(temp): 0.3
|
||||
(give_up_if_no_improvement): False
|
||||
)
|
||||
(goal_function): UntargetedClassification
|
||||
(transformation): WordSwapEmbedding(
|
||||
(max_candidates): 15
|
||||
(embedding_type): paragramcf
|
||||
)
|
||||
(constraints):
|
||||
(0): WordEmbeddingDistance(
|
||||
(embedding_type): paragramcf
|
||||
(min_cos_sim): 0.7
|
||||
(cased): False
|
||||
(include_unknown_words): True
|
||||
)
|
||||
(1): BERT(
|
||||
(metric): cosine
|
||||
(threshold): 0.7
|
||||
(compare_with_original): False
|
||||
(window_size): None
|
||||
(skip_text_shorter_than_window): False
|
||||
)
|
||||
(2): RepeatModification
|
||||
(3): StopwordModification
|
||||
(is_black_box): True
|
||||
)
|
||||
|
||||
--------------------------------------------- Result 1 ---------------------------------------------
|
||||
[92mPositive (98%)[0m --> [91mNegative (54%)[0m
|
||||
|
||||
Since this cartoon was made in the [92mold[0m days, Felix talks [92musing[0m [92mcartoon[0m bubbles and the animation style is very crude when compared to today. However, compared to its contemporaries, it's a pretty [92mgood[0m cartoon and [92mstill[0m holds up well. That's because despite its age, the cartoon is very creative and funny.<br /><br />Felix meets a guy whose shoe business is folding because he can't sell any shoes. Well, Felix needs money so he can go to Hollywood, so he tells the guy at the shop he'll get every [92mshoe[0m sold. Felix spreads [92mchewing[0m gum all over town and soon people are stuck and [92mleave[0m their shoes--rushing to buy new ones from the shoe store. In gratitude, the guy gives Felix $500! However, Felix's owner wants to take the money and go alone, so Felix figures out a way to sneak along.<br /><br />Once there, Felix barges into a studio and makes a bit of a nuisance of himself. Along the way, he meets cartoon versions of comics Ben Turpin and Charlie Chaplin. In the end, though, through luck, Felix is discovered and offered a movie contract. Hurray!
|
||||
|
||||
Since this cartoon was made in the [91mantiquity[0m days, Felix talks [91mexploit[0m [91mtoon[0m bubbles and the animation style is very crude when compared to today. However, compared to its contemporaries, it's a pretty [91malright[0m cartoon and [91mnevertheless[0m holds up well. That's because despite its age, the cartoon is very creative and funny.<br /><br />Felix meets a guy whose shoe business is folding because he can't sell any shoes. Well, Felix needs money so he can go to Hollywood, so he tells the guy at the shop he'll get every [91msneakers[0m sold. Felix spreads [91mchewed[0m gum all over town and soon people are stuck and [91mexiting[0m their shoes--rushing to buy new ones from the shoe store. In gratitude, the guy gives Felix $500! However, Felix's owner wants to take the money and go alone, so Felix figures out a way to sneak along.<br /><br />Once there, Felix barges into a studio and makes a bit of a nuisance of himself. Along the way, he meets cartoon versions of comics Ben Turpin and Charlie Chaplin. In the end, though, through luck, Felix is discovered and offered a movie contract. Hurray!
|
||||
|
||||
|
||||
--------------------------------------------- Result 2 ---------------------------------------------
|
||||
[92mPositive (98%)[0m --> [91mNegative (59%)[0m
|
||||
|
||||
Despite the title and unlike some other stories about love and war, this film isn't too sticky and pink, because love is as a rose: With thorns, that is. The four leading actors set their characters realistic and with a good [92msense[0m and balance between the [92mtragic[0m and the down-to-earth. <br /><br />The music and lyrics of the cabaret/chanson-esquire songs (sung b Keira Knightley herself) drag the viewer deeper and deeper in the film, from one place to another, between the brutal war and amongst the peaceful love. Some people may find it too much a biopic, but it ís [92mmostly[0m a romantic story, even though it consequently follows the life of Dylan Thomas and the triangular relationship which is steeped by joy and jealousy. <br /><br />London gets visualized from another angle for once, the bohemian life of Dylan during the bombings of the Germans is set in a floating atmosphere of small bedrooms, pubs and bars. The independent women, the soldier and the charismatic poet are constantly swept in both feelings of love and anger. <br /><br />Maybe the end is too twisted and hangs somewhat loosely to the rest of the film, but all in all this is a great romantic story.
|
||||
|
||||
Despite the title and unlike some other stories about love and war, this film isn't too sticky and pink, because love is as a rose: With thorns, that is. The four leading actors set their characters realistic and with a good [91mmeaning[0m and balance between the [91mterrible[0m and the down-to-earth. <br /><br />The music and lyrics of the cabaret/chanson-esquire songs (sung b Keira Knightley herself) drag the viewer deeper and deeper in the film, from one place to another, between the brutal war and amongst the peaceful love. Some people may find it too much a biopic, but it ís [91mbasically[0m a romantic story, even though it consequently follows the life of Dylan Thomas and the triangular relationship which is steeped by joy and jealousy. <br /><br />London gets visualized from another angle for once, the bohemian life of Dylan during the bombings of the Germans is set in a floating atmosphere of small bedrooms, pubs and bars. The independent women, the soldier and the charismatic poet are constantly swept in both feelings of love and anger. <br /><br />Maybe the end is too twisted and hangs somewhat loosely to the rest of the film, but all in all this is a great romantic story.
|
||||
|
||||
|
||||
--------------------------------------------- Result 3 ---------------------------------------------
|
||||
[92mPositive (97%)[0m --> [91mNegative (89%)[0m
|
||||
|
||||
Felix in Hollywood is a [92mgreat[0m film. The version I [92mviewed[0m was very well restored, which is [92msometimes[0m a [92mproblem[0m with these silent era animated films. It has some of Hollywood's most [92mfamous[0m stars making cameo animated appearances. A must for any [92msilent[0m film or animation enthusiast.
|
||||
|
||||
Felix in Hollywood is a [91mwhopping[0m film. The version I [91mconstrued[0m was very well restored, which is [91mordinarily[0m a [91mtroubles[0m with these silent era animated films. It has some of Hollywood's most [91mproverbial[0m stars making cameo animated appearances. A must for any [91mvoiceless[0m film or animation enthusiast.
|
||||
|
||||
|
||||
--------------------------------------------- Result 4 ---------------------------------------------
|
||||
[92mPositive (97%)[0m --> [91mNegative (69%)[0m
|
||||
|
||||
[92mA[0m gem of a cartoon from the [92msilent[0m era---it was re-discovered by [92mCARTOON[0m NETWORK, and was broadcast for likely the first time in decades, if ever.<br /><br />What makes this so [92menjoyable[0m are the [92mvaried[0m cameos...Douglas Fairbanks is attacked by giant mosquitos; Will Hays pays a visit as 'boss' of Static Studios; as well as appearances by Chaplin, Keaton, and William S. Hart. The image of chewing [92mgum[0m decimating the shoes of the populace (a money-making idea for Felix's near-bankrupt shoe-=salesman boss) cannot be described--it must be viewed. A [92mterrific[0m cultural gem.
|
||||
|
||||
[91muna[0m gem of a cartoon from the [91msilencers[0m era---it was re-discovered by [91mTRAVESTY[0m NETWORK, and was broadcast for likely the first time in decades, if ever.<br /><br />What makes this so [91mpleasurable[0m are the [91massorted[0m cameos...Douglas Fairbanks is attacked by giant mosquitos; Will Hays pays a visit as 'boss' of Static Studios; as well as appearances by Chaplin, Keaton, and William S. Hart. The image of chewing [91merasers[0m decimating the shoes of the populace (a money-making idea for Felix's near-bankrupt shoe-=salesman boss) cannot be described--it must be viewed. A [91mawesome[0m cultural gem.
|
||||
|
||||
|
||||
|
||||
+-------------------------------+--------+
|
||||
| Attack Results | |
|
||||
+-------------------------------+--------+
|
||||
| Number of successful attacks: | 4 |
|
||||
| Number of failed attacks: | 0 |
|
||||
| Number of skipped attacks: | 0 |
|
||||
| Original accuracy: | 100.0% |
|
||||
| Accuracy under attack: | 0.0% |
|
||||
| Attack success rate: | 100.0% |
|
||||
| Average perturbed word %: | 6.24% |
|
||||
| Average num. words per input: | 138.5 |
|
||||
| Avg num queries: | 2318.5 |
|
||||
+-------------------------------+--------+
|
||||
@@ -112,14 +112,13 @@ attack_test_params = [
|
||||
),
|
||||
# fmt: on
|
||||
#
|
||||
# test: run_attack on LSTM IMDB using word embedding transformation and genetic algorithm. Simulate alzantot recipe without using expensive LM
|
||||
# test: run_attack on LSTM MR using word embedding transformation and genetic algorithm. Simulate alzantot recipe without using expensive LM
|
||||
(
|
||||
"run_attack_genetic_lstm_imdb",
|
||||
"run_attack_faster_alzantot_recipe",
|
||||
(
|
||||
"textattack attack --model lstm-imdb --search ga-word --transformation word-swap-embedding "
|
||||
"--constraints repeat stopword embedding:min_cos_sim=0.7 bert --num-examples 4 --num-examples-offset 21"
|
||||
"textattack attack --model lstm-mr --recipe faster-alzantot --num-examples 3 --num-examples-offset 20"
|
||||
),
|
||||
"tests/sample_outputs/run_attack_genetic_lstm_imdb.txt",
|
||||
"tests/sample_outputs/run_attack_faster_alzantot_recipe.txt",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ class GeneticAlgorithm(SearchMethod):
|
||||
temp=0.3,
|
||||
give_up_if_no_improvement=False,
|
||||
max_crossover_retries=20,
|
||||
compare_against_original=True,
|
||||
):
|
||||
self.max_iters = max_iters
|
||||
self.pop_size = pop_size
|
||||
@@ -68,7 +67,7 @@ class GeneticAlgorithm(SearchMethod):
|
||||
transformations = self.get_transformations(
|
||||
pop_member.attacked_text,
|
||||
original_text=original_result.attacked_text,
|
||||
indices_to_modify=[rand_idx]
|
||||
indices_to_modify=[rand_idx],
|
||||
)
|
||||
|
||||
if not len(transformations):
|
||||
@@ -175,8 +174,8 @@ class GeneticAlgorithm(SearchMethod):
|
||||
# Therefore, we give small non-zero probability for words with no candidates
|
||||
# Epsilon is some small number to approximately assign 1% probability
|
||||
total_candidates = np.sum(num_candidates_per_word)
|
||||
num_zero_elements = len(words) - np.count_zero(num_candidates_per_word)
|
||||
epsilon = min(1, int(total_candidates / (100 - num_zero_elements)))
|
||||
num_zero_elements = len(words) - np.count_nonzero(num_candidates_per_word)
|
||||
epsilon = max(1, int(total_candidates / (100 - num_zero_elements)))
|
||||
for i in range(len(num_candidates_per_word)):
|
||||
if num_candidates_per_word[i] == 0:
|
||||
num_candidates_per_word[i] = epsilon
|
||||
|
||||
Reference in New Issue
Block a user