From d72823acdbe1756bc2b9c63d61d496ac6a914dd0 Mon Sep 17 00:00:00 2001 From: Jin Yong Yoo Date: Mon, 6 Jul 2020 12:51:16 -0400 Subject: [PATCH] resolve merge conflict --- tests/sample_outputs/interactive_mode.txt | 3 +++ tests/sample_outputs/kuleshov_cnn_sst_2.txt | 3 +++ .../run_attack_deepwordbug_lstm_mr_2.txt | 1 + .../run_attack_faster_alzantot_recipe.txt | 5 ++++- .../run_attack_flair_pos_tagger_bert_score.txt | 2 ++ .../sample_outputs/run_attack_hotflip_lstm_mr_4.txt | 3 +++ ...dnet_langtool_enable_csv_beamsearch2_attack_n.txt | 1 + tests/sample_outputs/run_attack_transformers_nlp.txt | 1 + .../google_language_model/google_language_model.py | 12 +----------- .../language_models/language_model_constraint.py | 2 +- .../constraints/grammaticality/language_tool.py | 2 +- .../constraints/grammaticality/part_of_speech.py | 2 +- textattack/constraints/overlap/bleu_score.py | 2 +- textattack/constraints/overlap/chrf_score.py | 2 +- .../constraints/overlap/levenshtein_edit_distance.py | 2 +- .../constraints/overlap/max_words_perturbed.py | 2 +- textattack/constraints/overlap/meteor_score.py | 2 +- textattack/constraints/semantics/bert_score.py | 2 +- .../semantics/sentence_encoders/sentence_encoder.py | 2 +- .../constraints/semantics/word_embedding_distance.py | 2 +- 20 files changed, 30 insertions(+), 23 deletions(-) diff --git a/tests/sample_outputs/interactive_mode.txt b/tests/sample_outputs/interactive_mode.txt index 654bf2d7..764cfb63 100644 --- a/tests/sample_outputs/interactive_mode.txt +++ b/tests/sample_outputs/interactive_mode.txt @@ -13,17 +13,20 @@ (min_cos_sim): 0.5 (cased): False (include_unknown_words): True + (compare_against_original): True ) (1): PartOfSpeech( (tagger_type): nltk (tagset): universal (allow_verb_noun_swap): True + (compare_against_original): True ) (2): UniversalSentenceEncoder( (metric): angular (threshold): 0.904458599 (window_size): 15 (skip_text_shorter_than_window): True + (compare_against_original): False ) (3): RepeatModification (4): StopwordModification diff --git a/tests/sample_outputs/kuleshov_cnn_sst_2.txt b/tests/sample_outputs/kuleshov_cnn_sst_2.txt index e9bb1995..5ebd01b5 100644 --- a/tests/sample_outputs/kuleshov_cnn_sst_2.txt +++ b/tests/sample_outputs/kuleshov_cnn_sst_2.txt @@ -8,6 +8,7 @@ (constraints): (0): MaxWordsPerturbed( (max_percent): 0.5 + (compare_against_original): True ) (1): ThoughtVector( (embedding_type): paragramcf @@ -15,9 +16,11 @@ (threshold): -0.2 (window_size): inf (skip_text_shorter_than_window): False + (compare_against_original): True ) (2): GPT2( (max_log_prob_diff): 2.0 + (compare_against_original): True ) (3): RepeatModification (4): StopwordModification diff --git a/tests/sample_outputs/run_attack_deepwordbug_lstm_mr_2.txt b/tests/sample_outputs/run_attack_deepwordbug_lstm_mr_2.txt index 3010826c..d79c38bb 100644 --- a/tests/sample_outputs/run_attack_deepwordbug_lstm_mr_2.txt +++ b/tests/sample_outputs/run_attack_deepwordbug_lstm_mr_2.txt @@ -7,6 +7,7 @@ (constraints): (0): LevenshteinEditDistance( (max_edit_distance): 30 + (compare_against_original): True ) (1): RepeatModification (2): StopwordModification diff --git a/tests/sample_outputs/run_attack_faster_alzantot_recipe.txt b/tests/sample_outputs/run_attack_faster_alzantot_recipe.txt index 4ee4817a..1e25fd61 100644 --- a/tests/sample_outputs/run_attack_faster_alzantot_recipe.txt +++ b/tests/sample_outputs/run_attack_faster_alzantot_recipe.txt @@ -1,4 +1,4 @@ -Attack( +/.*/Attack( (search_method): GeneticAlgorithm( (pop_size): 60 (max_iters): 20 @@ -13,15 +13,18 @@ Attack( (constraints): (0): MaxWordsPerturbed( (max_percent): 0.2 + (compare_against_original): True ) (1): WordEmbeddingDistance( (embedding_type): paragramcf (max_mse_dist): 0.5 (cased): False (include_unknown_words): True + (compare_against_original): True ) (2): LearningToWriteLanguageModel( (max_log_prob_diff): 5.0 + (compare_against_original): True ) (3): RepeatModification (4): StopwordModification diff --git a/tests/sample_outputs/run_attack_flair_pos_tagger_bert_score.txt b/tests/sample_outputs/run_attack_flair_pos_tagger_bert_score.txt index 024b1ba0..42eb6789 100644 --- a/tests/sample_outputs/run_attack_flair_pos_tagger_bert_score.txt +++ b/tests/sample_outputs/run_attack_flair_pos_tagger_bert_score.txt @@ -12,11 +12,13 @@ (min_bert_score): 0.8 (model): bert-base-uncased (score_type): f1 + (compare_against_original): True ) (1): PartOfSpeech( (tagger_type): flair (tagset): universal (allow_verb_noun_swap): True + (compare_against_original): True ) (2): RepeatModification (3): StopwordModification diff --git a/tests/sample_outputs/run_attack_hotflip_lstm_mr_4.txt b/tests/sample_outputs/run_attack_hotflip_lstm_mr_4.txt index 98a3965c..f5a076d2 100644 --- a/tests/sample_outputs/run_attack_hotflip_lstm_mr_4.txt +++ b/tests/sample_outputs/run_attack_hotflip_lstm_mr_4.txt @@ -9,17 +9,20 @@ (constraints): (0): MaxWordsPerturbed( (max_num_words): 2 + (compare_against_original): True ) (1): WordEmbeddingDistance( (embedding_type): paragramcf (min_cos_sim): 0.8 (cased): False (include_unknown_words): True + (compare_against_original): True ) (2): PartOfSpeech( (tagger_type): nltk (tagset): universal (allow_verb_noun_swap): True + (compare_against_original): True ) (3): RepeatModification (4): StopwordModification diff --git a/tests/sample_outputs/run_attack_targetedclassification2_wordnet_langtool_enable_csv_beamsearch2_attack_n.txt b/tests/sample_outputs/run_attack_targetedclassification2_wordnet_langtool_enable_csv_beamsearch2_attack_n.txt index e7f3f657..6a7d3dc6 100644 --- a/tests/sample_outputs/run_attack_targetedclassification2_wordnet_langtool_enable_csv_beamsearch2_attack_n.txt +++ b/tests/sample_outputs/run_attack_targetedclassification2_wordnet_langtool_enable_csv_beamsearch2_attack_n.txt @@ -9,6 +9,7 @@ (constraints): (0): LanguageTool( (grammar_error_threshold): 0 + (compare_against_original): True ) (1): RepeatModification (2): StopwordModification diff --git a/tests/sample_outputs/run_attack_transformers_nlp.txt b/tests/sample_outputs/run_attack_transformers_nlp.txt index 1a71253f..e5c62555 100644 --- a/tests/sample_outputs/run_attack_transformers_nlp.txt +++ b/tests/sample_outputs/run_attack_transformers_nlp.txt @@ -7,6 +7,7 @@ (constraints): (0): LevenshteinEditDistance( (max_edit_distance): 30 + (compare_against_original): True ) (1): RepeatModification (2): StopwordModification diff --git a/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py b/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py index 2212cd44..e8a5e52d 100644 --- a/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py +++ b/textattack/constraints/grammaticality/language_models/google_language_model/google_language_model.py @@ -98,18 +98,8 @@ class GoogleLanguageModel(Constraint): return [transformed_texts[i] for i in max_el_indices] -<<<<<<< HEAD def _check_constraint(self, transformed_text, reference_text): return self._check_constraint_many([transformed_text], reference_text) -======= - def _check_constraint(self, transformed_text, current_text, original_text=None): - return self._check_constraint_many( - [transformed_text], current_text, original_text=original_text - ) - - def __call__(self, x, x_adv): - raise NotImplementedError() ->>>>>>> master def extra_repr_keys(self): - return ["top_n", "top_n_per_index"] + return ["top_n", "top_n_per_index"] + super().extra_repr_keys() diff --git a/textattack/constraints/grammaticality/language_models/language_model_constraint.py b/textattack/constraints/grammaticality/language_models/language_model_constraint.py index cae75164..aa8f3288 100644 --- a/textattack/constraints/grammaticality/language_models/language_model_constraint.py +++ b/textattack/constraints/grammaticality/language_models/language_model_constraint.py @@ -49,4 +49,4 @@ class LanguageModelConstraint(Constraint, ABC): return True def extra_repr_keys(self): - return ["max_log_prob_diff"] + return ["max_log_prob_diff"] + super().extra_repr_keys() diff --git a/textattack/constraints/grammaticality/language_tool.py b/textattack/constraints/grammaticality/language_tool.py index 55d8e640..7e240311 100644 --- a/textattack/constraints/grammaticality/language_tool.py +++ b/textattack/constraints/grammaticality/language_tool.py @@ -37,4 +37,4 @@ class LanguageTool(Constraint): return errors_added <= self.grammar_error_threshold def extra_repr_keys(self): - return ["grammar_error_threshold"] + return ["grammar_error_threshold"] + super().extra_repr_keys() diff --git a/textattack/constraints/grammaticality/part_of_speech.py b/textattack/constraints/grammaticality/part_of_speech.py index 53609c58..e58e1e76 100644 --- a/textattack/constraints/grammaticality/part_of_speech.py +++ b/textattack/constraints/grammaticality/part_of_speech.py @@ -97,7 +97,7 @@ class PartOfSpeech(Constraint): return transformation_consists_of_word_swaps(transformation) def extra_repr_keys(self): - return ["tagger_type", "tagset", "allow_verb_noun_swap"] + return ["tagger_type", "tagset", "allow_verb_noun_swap"] + super().extra_repr_keys() def zip_flair_result(pred): diff --git a/textattack/constraints/overlap/bleu_score.py b/textattack/constraints/overlap/bleu_score.py index 9e99a32f..d0c8fabf 100644 --- a/textattack/constraints/overlap/bleu_score.py +++ b/textattack/constraints/overlap/bleu_score.py @@ -26,4 +26,4 @@ class BLEU(Constraint): return bleu_score <= self.max_bleu_score def extra_repr_keys(self): - return ["max_bleu_score"] + return ["max_bleu_score"] + super().extra_repr_keys() diff --git a/textattack/constraints/overlap/chrf_score.py b/textattack/constraints/overlap/chrf_score.py index ba879f08..91697b59 100644 --- a/textattack/constraints/overlap/chrf_score.py +++ b/textattack/constraints/overlap/chrf_score.py @@ -25,4 +25,4 @@ class chrF(Constraint): return chrf <= self.max_chrf def extra_repr_keys(self): - return ["max_chrf"] + return ["max_chrf"] + super().extra_repr_keys() diff --git a/textattack/constraints/overlap/levenshtein_edit_distance.py b/textattack/constraints/overlap/levenshtein_edit_distance.py index eb5d6669..4b3007e7 100644 --- a/textattack/constraints/overlap/levenshtein_edit_distance.py +++ b/textattack/constraints/overlap/levenshtein_edit_distance.py @@ -23,4 +23,4 @@ class LevenshteinEditDistance(Constraint): return edit_distance <= self.max_edit_distance def extra_repr_keys(self): - return ["max_edit_distance"] + return ["max_edit_distance"] + super().extra_repr_keys() diff --git a/textattack/constraints/overlap/max_words_perturbed.py b/textattack/constraints/overlap/max_words_perturbed.py index 691dd084..85da0456 100644 --- a/textattack/constraints/overlap/max_words_perturbed.py +++ b/textattack/constraints/overlap/max_words_perturbed.py @@ -52,4 +52,4 @@ class MaxWordsPerturbed(Constraint): metric.append("max_percent") if self.max_num_words is not None: metric.append("max_num_words") - return metric + return metric + super().extra_repr_keys() diff --git a/textattack/constraints/overlap/meteor_score.py b/textattack/constraints/overlap/meteor_score.py index ceeab3cf..64d2830e 100644 --- a/textattack/constraints/overlap/meteor_score.py +++ b/textattack/constraints/overlap/meteor_score.py @@ -24,4 +24,4 @@ class METEOR(Constraint): return meteor <= self.max_meteor def extra_repr_keys(self): - return ["max_meteor"] + return ["max_meteor"] + super().extra_repr_keys() diff --git a/textattack/constraints/semantics/bert_score.py b/textattack/constraints/semantics/bert_score.py index ae7df990..9bdbfc9b 100644 --- a/textattack/constraints/semantics/bert_score.py +++ b/textattack/constraints/semantics/bert_score.py @@ -63,4 +63,4 @@ class BERTScore(Constraint): return False def extra_repr_keys(self): - return ["min_bert_score", "model", "score_type"] + return ["min_bert_score", "model", "score_type"] + super().extra_repr_keys() diff --git a/textattack/constraints/semantics/sentence_encoders/sentence_encoder.py b/textattack/constraints/semantics/sentence_encoders/sentence_encoder.py index b07602e0..5f3f7d0b 100644 --- a/textattack/constraints/semantics/sentence_encoders/sentence_encoder.py +++ b/textattack/constraints/semantics/sentence_encoders/sentence_encoder.py @@ -204,7 +204,7 @@ class SentenceEncoder(Constraint): "threshold", "window_size", "skip_text_shorter_than_window", - ] + ] + super().extra_repr_keys() def get_angular_sim(emb1, emb2): diff --git a/textattack/constraints/semantics/word_embedding_distance.py b/textattack/constraints/semantics/word_embedding_distance.py index ffe3d670..a6a745e0 100644 --- a/textattack/constraints/semantics/word_embedding_distance.py +++ b/textattack/constraints/semantics/word_embedding_distance.py @@ -176,4 +176,4 @@ class WordEmbeddingDistance(Constraint): metric = "max_mse_dist" else: metric = "min_cos_sim" - return ["embedding_type", metric, "cased", "include_unknown_words"] + return ["embedding_type", metric, "cased", "include_unknown_words"] + super().extra_repr_keys()