Skip to content

Commit 4a17abd

Browse files
committed
fixing minor errors in notebooks and format change
1 parent eaecc0e commit 4a17abd

3 files changed

Lines changed: 42 additions & 24 deletions

File tree

docs/2notebook/1_Introduction_and_Transformations.ipynb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
"Please remember to run **pip3 install textattack[tensorflow]** in your notebook enviroment before the following codes:"
3030
]
3131
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"!pip3 install textattack[tensorflow]"
39+
]
40+
},
3241
{
3342
"cell_type": "markdown",
3443
"metadata": {
@@ -668,11 +677,13 @@
668677
"logger = CSVLogger(color_method=\"html\")\n",
669678
"\n",
670679
"for result in attack_results:\n",
671-
" logger.log_attack_result(result)\n",
680+
" if isinstance(result, SuccessfulAttackResult):\n",
681+
" logger.log_attack_result(result)\n",
672682
"\n",
673683
"from IPython.core.display import display, HTML\n",
674684
"\n",
675-
"display(HTML(logger.df[[\"original_text\", \"perturbed_text\"]].to_html(escape=False)))"
685+
"results = pd.DataFrame.from_records(logger.row_list)\n",
686+
"display(HTML(results[[\"original_text\", \"perturbed_text\"]].to_html(escape=False)))"
676687
]
677688
},
678689
{

docs/2notebook/2_Constraints.ipynb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,6 @@
7676
"Let's import NLTK and download the required modules:"
7777
]
7878
},
79-
{
80-
"cell_type": "code",
81-
"execution_count": 11,
82-
"metadata": {},
83-
"outputs": [
84-
{
85-
"name": "stdout",
86-
"output_type": "stream",
87-
"text": [
88-
"2.4.0\n"
89-
]
90-
}
91-
],
92-
"source": [
93-
"import tensorflow as tf\n",
94-
"\n",
95-
"print(tf.__version__)"
96-
]
97-
},
9879
{
9980
"cell_type": "code",
10081
"execution_count": 2,
@@ -138,7 +119,7 @@
138119
}
139120
],
140121
"source": [
141-
"! pip3 install textattack[tensorflow]\n",
122+
"!pip3 install textattack[tensorflow]\n",
142123
"\n",
143124
"import nltk\n",
144125
"\n",

docs/2notebook/4_Custom_Datasets_Word_Embedding.ipynb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
}
124124
],
125125
"source": [
126-
"!pip3 install textattack"
126+
"!pip3 install textattack[tensorflow]"
127127
]
128128
},
129129
{
@@ -558,10 +558,36 @@
558558
"attack_args = AttackArgs(\n",
559559
" num_successful_examples=5, log_to_csv=\"results.csv\", csv_coloring_style=\"html\"\n",
560560
")\n",
561-
"attacker = Attacker(attack, dataset, attack_args)\n",
561+
"attacker = Attacker(attack, custom_dataset, attack_args)\n",
562562
"\n",
563563
"attack_results = attacker.attack_dataset()"
564564
]
565+
},
566+
{
567+
"cell_type": "code",
568+
"execution_count": null,
569+
"metadata": {},
570+
"outputs": [],
571+
"source": [
572+
"# now we visualize the attack results\n",
573+
"\n",
574+
"import pandas as pd\n",
575+
"\n",
576+
"pd.options.display.max_colwidth = (\n",
577+
" 480 # increase colum width so we can actually read the examples\n",
578+
")\n",
579+
"\n",
580+
"logger = CSVLogger(color_method=\"html\")\n",
581+
"\n",
582+
"for result in attack_results:\n",
583+
" if isinstance(result, SuccessfulAttackResult):\n",
584+
" logger.log_attack_result(result)\n",
585+
"\n",
586+
"from IPython.core.display import display, HTML\n",
587+
"\n",
588+
"results = pd.DataFrame.from_records(logger.row_list)\n",
589+
"display(HTML(results[[\"original_text\", \"perturbed_text\"]].to_html(escape=False)))"
590+
]
565591
}
566592
],
567593
"metadata": {

0 commit comments

Comments
 (0)