Skip to content

Commit 9cdaa48

Browse files
committed
make format update
1 parent e426102 commit 9cdaa48

17 files changed

Lines changed: 29 additions & 37 deletions

File tree

docs/2notebook/0_End_to_End.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@
14301430
"metadata": {},
14311431
"outputs": [],
14321432
"source": [
1433-
"!textattack attack --model cnn-yelp --num-examples 3 --search-method greedy-word-wir --transformation word-swap-wordnet --constraints cola^max_diff=0.1 bert-score^min_bert_score=0.7 --enable-advance-metrics \n"
1433+
"!textattack attack --model cnn-yelp --num-examples 3 --search-method greedy-word-wir --transformation word-swap-wordnet --constraints cola^max_diff=0.1 bert-score^min_bert_score=0.7 --enable-advance-metrics"
14341434
]
14351435
},
14361436
{
@@ -1439,7 +1439,7 @@
14391439
"metadata": {},
14401440
"outputs": [],
14411441
"source": [
1442-
"!textattack attack --model lstm-mr --recipe deepwordbug --num-examples 2 --attack-n --enable-advance-metrics \n"
1442+
"!textattack attack --model lstm-mr --recipe deepwordbug --num-examples 2 --attack-n --enable-advance-metrics"
14431443
]
14441444
},
14451445
{
@@ -1448,7 +1448,7 @@
14481448
"metadata": {},
14491449
"outputs": [],
14501450
"source": [
1451-
"!textattack attack --model lstm-mr --recipe hotflip --num-examples 4 --num-examples-offset 3 --enable-advance-metrics "
1451+
"!textattack attack --model lstm-mr --recipe hotflip --num-examples 4 --num-examples-offset 3 --enable-advance-metrics"
14521452
]
14531453
},
14541454
{
@@ -1457,7 +1457,7 @@
14571457
"metadata": {},
14581458
"outputs": [],
14591459
"source": [
1460-
"!textattack attack --model-from-huggingface distilbert-base-uncased-finetuned-sst-2-english --dataset-from-huggingface glue^sst2^train --recipe deepwordbug --num-examples 3 --enable-advance-metrics\n"
1460+
"!textattack attack --model-from-huggingface distilbert-base-uncased-finetuned-sst-2-english --dataset-from-huggingface glue^sst2^train --recipe deepwordbug --num-examples 3 --enable-advance-metrics"
14611461
]
14621462
},
14631463
{
@@ -1466,7 +1466,7 @@
14661466
"metadata": {},
14671467
"outputs": [],
14681468
"source": [
1469-
"! textattack attack --model cnn-imdb --attack-from-file tests/sample_inputs/attack_from_file.py^Attack --num-examples 2 --num-examples-offset 18 --attack-n "
1469+
"! textattack attack --model cnn-imdb --attack-from-file tests/sample_inputs/attack_from_file.py^Attack --num-examples 2 --num-examples-offset 18 --attack-n"
14701470
]
14711471
}
14721472
],

docs/2notebook/4_Custom_Datasets_Word_Embedding.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@
537537
"\n",
538538
"attack = Attack(goal_function, constraints, transformation, search_method)\n",
539539
"\n",
540-
"# here is a legacy code piece showing how the attack runs in details \n",
540+
"# here is a legacy code piece showing how the attack runs in details\n",
541541
"for example, label in custom_dataset:\n",
542542
" result = attack.attack(example, label)\n",
543543
" print(result.__str__(color_method=\"ansi\"))"

docs/2notebook/Example_3_Keras.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@
259259
" self.model = model\n",
260260
"\n",
261261
" def __call__(self, text_input_list):\n",
262-
"\n",
263262
" x_transform = []\n",
264263
" for i, review in enumerate(text_input_list):\n",
265264
" tokens = [x.strip(\",\") for x in review.split()]\n",

docs/2notebook/Example_5_Explain_BERT.ipynb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,9 @@
273273
" list_of_text = []\n",
274274
" number = input_ids.size()[0]\n",
275275
" for i in range(number):\n",
276-
" ii = (\n",
277-
" input_ids[\n",
278-
" i,\n",
279-
" ]\n",
280-
" .cpu()\n",
281-
" .numpy()\n",
282-
" )\n",
283-
" tt = token_type_ids[\n",
284-
" i,\n",
285-
" ]\n",
286-
" am = attention_mask[\n",
287-
" i,\n",
288-
" ]\n",
276+
" ii = input_ids[i,].cpu().numpy()\n",
277+
" tt = token_type_ids[i,]\n",
278+
" am = attention_mask[i,]\n",
289279
" txt = tokenizer.decode(ii, skip_special_tokens=True)\n",
290280
" list_of_text.append(txt)\n",
291281
" return list_of_text\n",

tests/test_attacked_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_window_around_index(self, attacked_text):
7070

7171
def test_big_window_around_index(self, attacked_text):
7272
assert (
73-
attacked_text.text_window_around_index(0, 10 ** 5) + "."
73+
attacked_text.text_window_around_index(0, 10**5) + "."
7474
) == attacked_text.text
7575

7676
def test_window_around_index_start(self, attacked_text):

tests/test_word_embedding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_embedding_paragramcf():
1010
word_embedding = WordEmbedding.counterfitted_GLOVE_embedding()
1111
assert pytest.approx(word_embedding[0][0]) == -0.022007
1212
assert pytest.approx(word_embedding["fawn"][0]) == -0.022007
13-
assert word_embedding[10 ** 9] is None
13+
assert word_embedding[10**9] is None
1414

1515

1616
def test_embedding_gensim():
@@ -37,7 +37,7 @@ def test_embedding_gensim():
3737
word_embedding = GensimWordEmbedding(keyed_vectors)
3838
assert pytest.approx(word_embedding[0][0]) == 1
3939
assert pytest.approx(word_embedding["bye-bye"][0]) == -1 / np.sqrt(2)
40-
assert word_embedding[10 ** 9] is None
40+
assert word_embedding[10**9] is None
4141

4242
# test query functionality
4343
assert pytest.approx(word_embedding.get_cos_sim(1, 3)) == 0

textattack/attack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def __init__(
8383
constraints: List[Union[Constraint, PreTransformationConstraint]],
8484
transformation: Transformation,
8585
search_method: SearchMethod,
86-
transformation_cache_size=2 ** 15,
87-
constraint_cache_size=2 ** 15,
86+
transformation_cache_size=2**15,
87+
constraint_cache_size=2**15,
8888
):
8989
"""Initialize an attack object.
9090

textattack/attack_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ class _CommandLineAttackArgs:
504504
interactive: bool = False
505505
parallel: bool = False
506506
model_batch_size: int = 32
507-
model_cache_size: int = 2 ** 18
508-
constraint_cache_size: int = 2 ** 18
507+
model_cache_size: int = 2**18
508+
constraint_cache_size: int = 2**18
509509

510510
@classmethod
511511
def _add_parser_args(cls, parser):

textattack/constraints/grammaticality/cola.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(
4343

4444
self.max_diff = max_diff
4545
self.model_name = model_name
46-
self._reference_score_cache = lru.LRU(2 ** 10)
46+
self._reference_score_cache = lru.LRU(2**10)
4747
model = AutoModelForSequenceClassification.from_pretrained(model_name)
4848
tokenizer = AutoTokenizer.from_pretrained(model_name)
4949
self.model = HuggingFaceModelWrapper(model, tokenizer)

textattack/constraints/grammaticality/language_models/google_language_model/alzantot_goog_lm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self):
4949
self.sess, self.graph, self.PBTXT_PATH, self.CKPT_PATH
5050
)
5151

52-
self.lm_cache = lru.LRU(2 ** 18)
52+
self.lm_cache = lru.LRU(2**18)
5353

5454
def clear_cache(self):
5555
self.lm_cache.clear()

0 commit comments

Comments
 (0)