Skip to content

Commit

Permalink
fixing minor errors in notebooks and format change
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyanjun committed Sep 11, 2023
1 parent eaecc0e commit 4a17abd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
15 changes: 13 additions & 2 deletions docs/2notebook/1_Introduction_and_Transformations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
"Please remember to run **pip3 install textattack[tensorflow]** in your notebook enviroment before the following codes:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip3 install textattack[tensorflow]"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -668,11 +677,13 @@
"logger = CSVLogger(color_method=\"html\")\n",
"\n",
"for result in attack_results:\n",
" logger.log_attack_result(result)\n",
" if isinstance(result, SuccessfulAttackResult):\n",
" logger.log_attack_result(result)\n",
"\n",
"from IPython.core.display import display, HTML\n",
"\n",
"display(HTML(logger.df[[\"original_text\", \"perturbed_text\"]].to_html(escape=False)))"
"results = pd.DataFrame.from_records(logger.row_list)\n",
"display(HTML(results[[\"original_text\", \"perturbed_text\"]].to_html(escape=False)))"
]
},
{
Expand Down
21 changes: 1 addition & 20 deletions docs/2notebook/2_Constraints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,6 @@
"Let's import NLTK and download the required modules:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.4.0\n"
]
}
],
"source": [
"import tensorflow as tf\n",
"\n",
"print(tf.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down Expand Up @@ -138,7 +119,7 @@
}
],
"source": [
"! pip3 install textattack[tensorflow]\n",
"!pip3 install textattack[tensorflow]\n",
"\n",
"import nltk\n",
"\n",
Expand Down
30 changes: 28 additions & 2 deletions docs/2notebook/4_Custom_Datasets_Word_Embedding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
}
],
"source": [
"!pip3 install textattack"
"!pip3 install textattack[tensorflow]"
]
},
{
Expand Down Expand Up @@ -558,10 +558,36 @@
"attack_args = AttackArgs(\n",
" num_successful_examples=5, log_to_csv=\"results.csv\", csv_coloring_style=\"html\"\n",
")\n",
"attacker = Attacker(attack, dataset, attack_args)\n",
"attacker = Attacker(attack, custom_dataset, attack_args)\n",
"\n",
"attack_results = attacker.attack_dataset()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# now we visualize the attack results\n",
"\n",
"import pandas as pd\n",
"\n",
"pd.options.display.max_colwidth = (\n",
" 480 # increase colum width so we can actually read the examples\n",
")\n",
"\n",
"logger = CSVLogger(color_method=\"html\")\n",
"\n",
"for result in attack_results:\n",
" if isinstance(result, SuccessfulAttackResult):\n",
" logger.log_attack_result(result)\n",
"\n",
"from IPython.core.display import display, HTML\n",
"\n",
"results = pd.DataFrame.from_records(logger.row_list)\n",
"display(HTML(results[[\"original_text\", \"perturbed_text\"]].to_html(escape=False)))"
]
}
],
"metadata": {
Expand Down

0 comments on commit 4a17abd

Please sign in to comment.