Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added text summarization notebook #317

Merged
merged 12 commits into from
Oct 26, 2023
180 changes: 180 additions & 0 deletions docs/notebooks/content/text_summerization_gpt.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "4vXfYHX6QSJu"
},
"source": [
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/gretelai/gretel-blueprints/blob/main/docs/notebooks/content/text_summerization_gpt.ipynb\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
"</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generate Synthetic text summarization with Gretel GPT\n",
"\n",
"* In this notebook we use Gretel GPT with Llama-2 7b model to create synthetic text summerization dataset. \n",
"* To run this notebook, you will need an API key from the [Gretel Console](https://console.gretel.ai/users/me/key/)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "GhwZL2atTilv"
},
"source": [
"## Getting Started"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "V_iIkqnUQK2l"
},
"outputs": [],
"source": [
"%%capture\n",
"!pip install -U gretel-client"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kixD67x_TSC4"
},
"outputs": [],
"source": [
"#import required packages\n",
"import pandas as pd\n",
"from gretel_client import Gretel"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0pMwi0RghUzh"
},
"source": [
"## Load and preview training data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 234
},
"id": "_QyG3jfRh2-i",
"outputId": "a60c1c7e-b71e-4843-cfb4-784000730546"
},
"outputs": [],
"source": [
"pd.set_option('max_colwidth', None)\n",
"\n",
"# Specify a dataset to train on\n",
"DATASET_PATH = 'https://gretel-datasets.s3.us-west-2.amazonaws.com/Text-dataset/Samsum-text-summerization-sample-1000.csv'\n",
"df = pd.read_csv(DATASET_PATH)\n",
"\n",
"#Let's look at the training dataset:\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure and Train the Synthetic Model:\n",
"\n",
"We can experiment different \"steps\" parameters which result in a change of text SQS."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"PROJECT = 'data-summarization'\n",
"LLM = \"meta-llama/Llama-2-7b-hf\"\n",
"\n",
"gretel = Gretel(project_name=f\"{PROJECT}-llama-2-7b\", api_key=\"prompt\", validate=True)\n",
"\n",
"trained = gretel.submit_train(\n",
" \"natural-language\",\n",
" data_source=df,\n",
" pretrained_model=LLM,\n",
" params={\"steps\": 1000}, \n",
" )"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Lh4-8dddoTWb"
},
"source": [
"## Display Text Synthetic Quality Score:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"trained.report.quality_scores"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"trained.report.display_in_notebook()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "J_yIE4WrW1Je"
},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading