|
123 | 123 | } |
124 | 124 | ], |
125 | 125 | "source": [ |
126 | | - "!pip3 install textattack" |
| 126 | + "!pip3 install textattack[tensorflow]" |
127 | 127 | ] |
128 | 128 | }, |
129 | 129 | { |
|
558 | 558 | "attack_args = AttackArgs(\n", |
559 | 559 | " num_successful_examples=5, log_to_csv=\"results.csv\", csv_coloring_style=\"html\"\n", |
560 | 560 | ")\n", |
561 | | - "attacker = Attacker(attack, dataset, attack_args)\n", |
| 561 | + "attacker = Attacker(attack, custom_dataset, attack_args)\n", |
562 | 562 | "\n", |
563 | 563 | "attack_results = attacker.attack_dataset()" |
564 | 564 | ] |
| 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 | + ] |
565 | 591 | } |
566 | 592 | ], |
567 | 593 | "metadata": { |
|
0 commit comments