Skip to content

Commit

Permalink
Add example notebook for AutoSummarization (#19)
Browse files Browse the repository at this point in the history
* Create 03_TextSummarization.ipynb

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
gagan3012 and pre-commit-ci[bot] committed Aug 25, 2021
1 parent a444ab9 commit 5428c45
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions examples/nbs/03_TextSummarization.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xYgiH2TkkX7x"
},
"outputs": [],
"source": [
"!pip install lightning-flash\n",
"!pip install git+https://github.com/gradsflow/gradsflow@main"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2_posF7Rj8sH"
},
"outputs": [],
"source": [
"from flash.core.data.utils import download_data\n",
"from flash.text import SummarizationData, SummarizationTask\n",
"\n",
"# 1. Download the data\n",
"download_data(\"https://pl-flash-data.s3.amazonaws.com/xsum.zip\", \"data/\")\n",
"\n",
"# 2. Load the data\n",
"datamodule = SummarizationData.from_csv(\n",
" \"input\",\n",
" \"target\",\n",
" train_file=\"data/xsum/train.csv\",\n",
" val_file=\"data/xsum/valid.csv\",\n",
" test_file=\"data/xsum/test.csv\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "YCYFfKhDkVVK"
},
"outputs": [],
"source": [
"from gradsflow.autoclassifier import AutoSummarization\n",
"\n",
"suggested_conf = dict(\n",
" optimizers=[\"adam\"],\n",
" lr=(5e-4, 1e-3),\n",
")\n",
"\n",
"model = AutoSummarization(datamodule,\n",
" suggested_backbones=\"sshleifer/distilbart-cnn-12-6\",\n",
" suggested_conf=suggested_conf,\n",
" max_epochs=1,\n",
" optimization_metric=\"train_loss\",\n",
" timeout=5)\n",
"\n",
"print(\"AutoSummarization initialised!\")\n",
"model.hp_tune()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "w_KVlJxYpTVy"
},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"name": "03-TextSummarization.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 5428c45

Please sign in to comment.