-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example notebook for AutoSummarization (#19)
* 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
1 parent
a444ab9
commit 5428c45
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |