Skip to content

Commit

Permalink
Merge pull request #576 from QData/update-augmentation-notebook
Browse files Browse the repository at this point in the history
Update Augmentation Notebook
  • Loading branch information
qiyanjun committed Nov 12, 2021
2 parents 866f07d + b75ca08 commit b05c555
Showing 1 changed file with 105 additions and 12 deletions.
117 changes: 105 additions & 12 deletions docs/2notebook/3_Augmentations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
"\n",
"\n",
"\n",
"Here's another example of using `WordNetAugmenter`:\n"
"Here's another example of using `WordNetAugmenter`. In this scenario, we enable `enable_advanced_metrics` to acquire perplexity and USE score, and enable `high_yield` to generate more examples in the same running time:\n"
]
},
{
Expand All @@ -245,29 +245,122 @@
"base_uri": "https://localhost:8080/"
},
"id": "l2b-4scuXvkA",
"outputId": "72a78a95-ffc0-4d2a-b98c-b456d338807d"
"outputId": "5a372fd2-226a-4970-a2c9-c09bf2af56c2"
},
"source": [
"from textattack.augmentation import WordNetAugmenter\n",
"augmenter = WordNetAugmenter(pct_words_to_swap=0.2, transformations_per_example=5)\n",
"augmenter = WordNetAugmenter(pct_words_to_swap=0.4, transformations_per_example=5, high_yield=True, enable_advanced_metrics=True)\n",
"s = \"I'd love to go to Japan but the tickets are 500 dollars\"\n",
"augmenter.augment(s)"
"results = augmenter.augment(s)\n",
"print(f\"Average Original Perplexity Score: {results[1]['avg_original_perplexity']}\\n\")\n",
"print(f\"Average Augment Perplexity Score: {results[1]['avg_attack_perplexity']}\\n\")\n",
"print(f\"Average Augment USE Score: {results[2]['avg_attack_use_score']}\\n\")\n",
"print(f\"Augmentations:\")\n",
"results[0]"
],
"execution_count": null,
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Token indices sequence length is longer than the specified maximum sequence length for this model (1091 > 1024). Running this sequence through the model will result in indexing errors\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Average Original Perplexity Score: 1.09\n",
"\n",
"Average Augment Perplexity Score: 3.17\n",
"\n",
"Average Augment USE Score: 0.72\n",
"\n",
"Augmentations:\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[\"I'd fuck to fit to Japan but the tickets are 500 dollars\",\n",
" \"I'd know to cristal to Japan but the tickets are 500 dollars\",\n",
" \"I'd love to depart to Japan but the tickets are D dollars\",\n",
" \"I'd love to get to Nihon but the tickets are 500 dollars\",\n",
" \"I'd love to work to Japan but the tickets are 500 buck\"]"
"[\"I'd bang to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd bang to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd bed to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd bed to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd beloved to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd beloved to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd bonk to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd bonk to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd bonk to travel to Japan but the tag are 500 buck\",\n",
" \"I'd bonk to travel to Japan but the tag are 500 clam\",\n",
" \"I'd bonk to travel to Japan but the tag are 500 dollar\",\n",
" \"I'd bonk to travel to Japan but the tag are 500 dollars\",\n",
" \"I'd bonk to travel to Japan but the tag are D dollars\",\n",
" \"I'd bonk to travel to Japan but the tag are d dollars\",\n",
" \"I'd bonk to travel to Nihon but the tag are 500 dollars\",\n",
" \"I'd bonk to travel to Nippon but the tag are 500 dollars\",\n",
" \"I'd bonk to travel to japan but the tag are 500 dollars\",\n",
" \"I'd dear to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd dear to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd dearest to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd dearest to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd eff to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd eff to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd enjoy to exit to Japan but the fine are 500 buck\",\n",
" \"I'd enjoy to exit to Japan but the slate are 500 buck\",\n",
" \"I'd enjoy to exit to Japan but the tag are 500 buck\",\n",
" \"I'd enjoy to exit to Japan but the ticket are 500 buck\",\n",
" \"I'd enjoy to exit to Japan but the tickets are 500 buck\",\n",
" \"I'd enjoy to exit to Japan but the tickets are D buck\",\n",
" \"I'd enjoy to exit to Japan but the tickets are d buck\",\n",
" \"I'd enjoy to exit to Nihon but the tickets are 500 buck\",\n",
" \"I'd enjoy to exit to Nippon but the tickets are 500 buck\",\n",
" \"I'd enjoy to exit to japan but the tickets are 500 buck\",\n",
" \"I'd enjoy to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd enjoy to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd fuck to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd fuck to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd honey to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd honey to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd hump to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd hump to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd jazz to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd jazz to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd know to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd know to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd love to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd love to operate to Japan but the ticket are D buck\",\n",
" \"I'd love to operate to Japan but the ticket are d buck\",\n",
" \"I'd love to operate to Nihon but the ticket are 500 buck\",\n",
" \"I'd love to operate to Nippon but the ticket are 500 buck\",\n",
" \"I'd love to operate to japan but the ticket are 500 buck\",\n",
" \"I'd love to plump to Nihon but the fine are 500 clam\",\n",
" \"I'd love to plump to Nihon but the slate are 500 clam\",\n",
" \"I'd love to plump to Nihon but the tag are 500 clam\",\n",
" \"I'd love to plump to Nihon but the ticket are 500 clam\",\n",
" \"I'd love to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd love to plump to Nihon but the tickets are D clam\",\n",
" \"I'd love to plump to Nihon but the tickets are d clam\",\n",
" \"I'd lovemaking to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd lovemaking to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd passion to fit to Japan but the fine are 500 buck\",\n",
" \"I'd passion to fit to Japan but the fine are 500 clam\",\n",
" \"I'd passion to fit to Japan but the fine are 500 dollar\",\n",
" \"I'd passion to fit to Japan but the fine are 500 dollars\",\n",
" \"I'd passion to fit to Japan but the fine are D dollars\",\n",
" \"I'd passion to fit to Japan but the fine are d dollars\",\n",
" \"I'd passion to fit to Nihon but the fine are 500 dollars\",\n",
" \"I'd passion to fit to Nippon but the fine are 500 dollars\",\n",
" \"I'd passion to fit to japan but the fine are 500 dollars\",\n",
" \"I'd passion to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd passion to plump to Nihon but the tickets are 500 clam\",\n",
" \"I'd screw to operate to Japan but the ticket are 500 buck\",\n",
" \"I'd screw to plump to Nihon but the tickets are 500 clam\"]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
"execution_count": 9
}
]
},
Expand Down

0 comments on commit b05c555

Please sign in to comment.