-
-
Save KennyKang7012/26ba18924cffd4a816bdac19d6fe8241 to your computer and use it in GitHub Desktop.
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "FineTune.ipynb", | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "n2oPmVrJj8oQ", | |
"outputId": "19752767-f058-47d0-eecd-015fb1d36b87" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
"Collecting openai\n", | |
" Downloading openai-0.20.0.tar.gz (42 kB)\n", | |
"\u001b[K |████████████████████████████████| 42 kB 745 kB/s \n", | |
"\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", | |
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", | |
" Preparing wheel metadata ... \u001b[?25l\u001b[?25hdone\n", | |
"Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.7/dist-packages (from openai) (2.23.0)\n", | |
"Requirement already satisfied: openpyxl>=3.0.7 in /usr/local/lib/python3.7/dist-packages (from openai) (3.0.10)\n", | |
"Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from openai) (4.64.0)\n", | |
"Requirement already satisfied: pandas>=1.2.3 in /usr/local/lib/python3.7/dist-packages (from openai) (1.3.5)\n", | |
"Collecting pandas-stubs>=1.1.0.11\n", | |
" Downloading pandas_stubs-1.2.0.62-py3-none-any.whl (163 kB)\n", | |
"\u001b[K |████████████████████████████████| 163 kB 8.8 MB/s \n", | |
"\u001b[?25hRequirement already satisfied: et-xmlfile in /usr/local/lib/python3.7/dist-packages (from openpyxl>=3.0.7->openai) (1.1.0)\n", | |
"Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.2.3->openai) (2.8.2)\n", | |
"Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.2.3->openai) (2022.1)\n", | |
"Requirement already satisfied: numpy>=1.17.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.2.3->openai) (1.21.6)\n", | |
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.7/dist-packages (from pandas-stubs>=1.1.0.11->openai) (4.1.1)\n", | |
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas>=1.2.3->openai) (1.15.0)\n", | |
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (3.0.4)\n", | |
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (2.10)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (2022.6.15)\n", | |
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (1.24.3)\n", | |
"Building wheels for collected packages: openai\n", | |
" Building wheel for openai (PEP 517) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for openai: filename=openai-0.20.0-py3-none-any.whl size=54118 sha256=f9df8736df071c745de034cdd8b90d12d2ffee3420d1fe26c8c2c619690dc579\n", | |
" Stored in directory: /root/.cache/pip/wheels/71/8d/9b/e28529ec53123e0279208f99148d4661232120d78cb866839b\n", | |
"Successfully built openai\n", | |
"Installing collected packages: pandas-stubs, openai\n", | |
"Successfully installed openai-0.20.0 pandas-stubs-1.2.0.62\n" | |
] | |
} | |
], | |
"source": [ | |
"#download openai\n", | |
"!pip install openai" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#making required imports\n", | |
"import openai\n", | |
"import pandas as pd\n", | |
"import string\n", | |
"\n", | |
"#writing openai api key\n", | |
"openai.api_key = ''\n", | |
"\n", | |
"#reading your dataset\n", | |
"df = pd.read_csv('jokes.csv')\n", | |
"df.head()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 206 | |
}, | |
"id": "Qvkir7-Ej-sk", | |
"outputId": "91dfa9eb-ddf8-4811-9b75-bce537e8b003" | |
}, | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
" ID Joke\n", | |
"0 1 What did the bartender say to the jumper cable...\n", | |
"1 2 Don't you hate jokes about German sausage? The...\n", | |
"2 3 Two artists had an art contest... It ended in ...\n", | |
"3 4 Why did the chicken cross the playground? To g...\n", | |
"4 5 What gun do you use to hunt a moose? A moosecut!" | |
], | |
"text/html": [ | |
"\n", | |
" <div id=\"df-43de4075-d0c5-491e-84d3-b57f6423339c\">\n", | |
" <div class=\"colab-df-container\">\n", | |
" <div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>ID</th>\n", | |
" <th>Joke</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" <td>What did the bartender say to the jumper cable...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2</td>\n", | |
" <td>Don't you hate jokes about German sausage? The...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>3</td>\n", | |
" <td>Two artists had an art contest... It ended in ...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>4</td>\n", | |
" <td>Why did the chicken cross the playground? To g...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>5</td>\n", | |
" <td>What gun do you use to hunt a moose? A moosecut!</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>\n", | |
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-43de4075-d0c5-491e-84d3-b57f6423339c')\"\n", | |
" title=\"Convert this dataframe to an interactive table.\"\n", | |
" style=\"display:none;\">\n", | |
" \n", | |
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n", | |
" width=\"24px\">\n", | |
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n", | |
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n", | |
" </svg>\n", | |
" </button>\n", | |
" \n", | |
" <style>\n", | |
" .colab-df-container {\n", | |
" display:flex;\n", | |
" flex-wrap:wrap;\n", | |
" gap: 12px;\n", | |
" }\n", | |
"\n", | |
" .colab-df-convert {\n", | |
" background-color: #E8F0FE;\n", | |
" border: none;\n", | |
" border-radius: 50%;\n", | |
" cursor: pointer;\n", | |
" display: none;\n", | |
" fill: #1967D2;\n", | |
" height: 32px;\n", | |
" padding: 0 0 0 0;\n", | |
" width: 32px;\n", | |
" }\n", | |
"\n", | |
" .colab-df-convert:hover {\n", | |
" background-color: #E2EBFA;\n", | |
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n", | |
" fill: #174EA6;\n", | |
" }\n", | |
"\n", | |
" [theme=dark] .colab-df-convert {\n", | |
" background-color: #3B4455;\n", | |
" fill: #D2E3FC;\n", | |
" }\n", | |
"\n", | |
" [theme=dark] .colab-df-convert:hover {\n", | |
" background-color: #434B5C;\n", | |
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n", | |
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n", | |
" fill: #FFFFFF;\n", | |
" }\n", | |
" </style>\n", | |
"\n", | |
" <script>\n", | |
" const buttonEl =\n", | |
" document.querySelector('#df-43de4075-d0c5-491e-84d3-b57f6423339c button.colab-df-convert');\n", | |
" buttonEl.style.display =\n", | |
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n", | |
"\n", | |
" async function convertToInteractive(key) {\n", | |
" const element = document.querySelector('#df-43de4075-d0c5-491e-84d3-b57f6423339c');\n", | |
" const dataTable =\n", | |
" await google.colab.kernel.invokeFunction('convertToInteractive',\n", | |
" [key], {});\n", | |
" if (!dataTable) return;\n", | |
"\n", | |
" const docLinkHtml = 'Like what you see? Visit the ' +\n", | |
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n", | |
" + ' to learn more about interactive tables.';\n", | |
" element.innerHTML = '';\n", | |
" dataTable['output_type'] = 'display_data';\n", | |
" await google.colab.output.renderOutput(dataTable, element);\n", | |
" const docLink = document.createElement('div');\n", | |
" docLink.innerHTML = docLinkHtml;\n", | |
" element.appendChild(docLink);\n", | |
" }\n", | |
" </script>\n", | |
" </div>\n", | |
" </div>\n", | |
" " | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 5 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#preprocessing dataset\n", | |
"def divide(joke):\n", | |
" for i in joke:\n", | |
" if i in string.punctuation:\n", | |
" break\n", | |
" question = joke[:joke.index(i)+1]\n", | |
" answer = joke[joke.index(i)+1:]\n", | |
" return question, answer" | |
], | |
"metadata": { | |
"id": "vGVmuWaikNk7" | |
}, | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#creating new dataset with prompt and completion as two columns \n", | |
"data = list(df['Joke'].apply(divide))\n", | |
"df2 = pd.DataFrame(data, columns =['prompt', 'completion'])\n", | |
"df2.head()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 206 | |
}, | |
"id": "1eoYQSnvkevA", | |
"outputId": "1da619c5-3b61-4299-d575-3c44ebe15c24" | |
}, | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
" prompt \\\n", | |
"0 What did the bartender say to the jumper cables? \n", | |
"1 Don' \n", | |
"2 Two artists had an art contest. \n", | |
"3 Why did the chicken cross the playground? \n", | |
"4 What gun do you use to hunt a moose? \n", | |
"\n", | |
" completion \n", | |
"0 You better not try to start anything. \n", | |
"1 t you hate jokes about German sausage? They're... \n", | |
"2 .. It ended in a draw \n", | |
"3 To get to the other slide. \n", | |
"4 A moosecut! " | |
], | |
"text/html": [ | |
"\n", | |
" <div id=\"df-dc2ae8ff-13bb-4bd4-8078-3c9a010b787c\">\n", | |
" <div class=\"colab-df-container\">\n", | |
" <div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>prompt</th>\n", | |
" <th>completion</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>What did the bartender say to the jumper cables?</td>\n", | |
" <td>You better not try to start anything.</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>Don'</td>\n", | |
" <td>t you hate jokes about German sausage? They're...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>Two artists had an art contest.</td>\n", | |
" <td>.. It ended in a draw</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>Why did the chicken cross the playground?</td>\n", | |
" <td>To get to the other slide.</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>What gun do you use to hunt a moose?</td>\n", | |
" <td>A moosecut!</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>\n", | |
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-dc2ae8ff-13bb-4bd4-8078-3c9a010b787c')\"\n", | |
" title=\"Convert this dataframe to an interactive table.\"\n", | |
" style=\"display:none;\">\n", | |
" \n", | |
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n", | |
" width=\"24px\">\n", | |
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n", | |
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n", | |
" </svg>\n", | |
" </button>\n", | |
" \n", | |
" <style>\n", | |
" .colab-df-container {\n", | |
" display:flex;\n", | |
" flex-wrap:wrap;\n", | |
" gap: 12px;\n", | |
" }\n", | |
"\n", | |
" .colab-df-convert {\n", | |
" background-color: #E8F0FE;\n", | |
" border: none;\n", | |
" border-radius: 50%;\n", | |
" cursor: pointer;\n", | |
" display: none;\n", | |
" fill: #1967D2;\n", | |
" height: 32px;\n", | |
" padding: 0 0 0 0;\n", | |
" width: 32px;\n", | |
" }\n", | |
"\n", | |
" .colab-df-convert:hover {\n", | |
" background-color: #E2EBFA;\n", | |
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n", | |
" fill: #174EA6;\n", | |
" }\n", | |
"\n", | |
" [theme=dark] .colab-df-convert {\n", | |
" background-color: #3B4455;\n", | |
" fill: #D2E3FC;\n", | |
" }\n", | |
"\n", | |
" [theme=dark] .colab-df-convert:hover {\n", | |
" background-color: #434B5C;\n", | |
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n", | |
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n", | |
" fill: #FFFFFF;\n", | |
" }\n", | |
" </style>\n", | |
"\n", | |
" <script>\n", | |
" const buttonEl =\n", | |
" document.querySelector('#df-dc2ae8ff-13bb-4bd4-8078-3c9a010b787c button.colab-df-convert');\n", | |
" buttonEl.style.display =\n", | |
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n", | |
"\n", | |
" async function convertToInteractive(key) {\n", | |
" const element = document.querySelector('#df-dc2ae8ff-13bb-4bd4-8078-3c9a010b787c');\n", | |
" const dataTable =\n", | |
" await google.colab.kernel.invokeFunction('convertToInteractive',\n", | |
" [key], {});\n", | |
" if (!dataTable) return;\n", | |
"\n", | |
" const docLinkHtml = 'Like what you see? Visit the ' +\n", | |
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n", | |
" + ' to learn more about interactive tables.';\n", | |
" element.innerHTML = '';\n", | |
" dataTable['output_type'] = 'display_data';\n", | |
" await google.colab.output.renderOutput(dataTable, element);\n", | |
" const docLink = document.createElement('div');\n", | |
" docLink.innerHTML = docLinkHtml;\n", | |
" element.appendChild(docLink);\n", | |
" }\n", | |
" </script>\n", | |
" </div>\n", | |
" </div>\n", | |
" " | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 9 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#saving the new csv file\n", | |
"df2.to_csv('joke.csv')" | |
], | |
"metadata": { | |
"id": "7DGJc2yJkikx" | |
}, | |
"execution_count": 10, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#converting csv to jsonl format because that is the format GPT3 can be finetuned in\n", | |
"!yes | openai tools fine_tunes.prepare_data -f 'joke.csv' " | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "E-R6FSg9kzF9", | |
"outputId": "ea914898-9245-406b-bf6a-906ffb89c4f3" | |
}, | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Logging requires wandb to be installed. Run `pip install wandb`.\n", | |
"Analyzing...\n", | |
"\n", | |
"- Based on your file extension, your file is formatted as a CSV file\n", | |
"- Your file contains 1622 prompt-completion pairs\n", | |
"- The input file should contain exactly two columns/keys per row. Additional columns/keys present are: ['Unnamed: 0']\n", | |
" WARNING: Some of the additional columns/keys contain `Unnamed: 0` in their name. These will be ignored, and the column/key `Unnamed: 0` will be used instead. This could also result from a duplicate column/key in the provided file.\n", | |
"- `completion` column/key should not contain empty strings. These are rows: [223, 267, 300, 359, 373, 414, 446, 455, 486, 499, 504, 558, 599, 668, 672, 696, 715, 782, 874, 913, 1006, 1041, 1177, 1278, 1302, 1325, 1326, 1342, 1378, 1387, 1405, 1427, 1440, 1457, 1476, 1491, 1614]\n", | |
"- There are 11 duplicated prompt-completion sets. These are rows: [336, 449, 607, 788, 997, 1019, 1149, 1310, 1445, 1497, 1582]\n", | |
"- Your data does not contain a common separator at the end of your prompts. Having a separator string appended to the end of the prompt makes it clearer to the fine-tuned model where the completion should begin. See https://beta.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more detail and examples. If you intend to do open-ended generation, then you should leave the prompts empty\n", | |
"- Your data does not contain a common ending at the end of your completions. Having a common ending string appended to the end of the completion makes it clearer to the fine-tuned model where the completion should end. See https://beta.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more detail and examples.\n", | |
"- The completion should start with a whitespace character (` `). This tends to produce better results due to the tokenization we use. See https://beta.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more details\n", | |
"\n", | |
"Based on the analysis we will perform the following actions:\n", | |
"- [Necessary] Your format `CSV` will be converted to `JSONL`\n", | |
"- [Necessary] Remove additional columns/keys: ['Unnamed: 0']\n", | |
"- [Necessary] Remove 37 rows with empty completions\n", | |
"- [Recommended] Remove 11 duplicate rows [Y/n]: - [Recommended] Add a suffix separator ` ->` to all prompts [Y/n]: - [Recommended] Add a suffix ending `\\n` to all completions [Y/n]: - [Recommended] Add a whitespace character to the beginning of the completion [Y/n]: \n", | |
"\n", | |
"Your data will be written to a new JSONL file. Proceed [Y/n]: \n", | |
"Wrote modified file to `joke_prepared.jsonl`\n", | |
"Feel free to take a look!\n", | |
"\n", | |
"Now use that file when fine-tuning:\n", | |
"> openai api fine_tunes.create -t \"joke_prepared.jsonl\"\n", | |
"\n", | |
"After you’ve fine-tuned a model, remember that your prompt has to end with the indicator string ` ->` for the model to start generating completions, rather than continuing with the prompt. Make sure to include `stop=[\"\\n\"]` so that the generated texts ends at the expected place.\n", | |
"Once your model starts training, it'll approximately take 1.05 hours to train a `curie` model, and less for `ada` and `babbage`. Queue will approximately take half an hour per job ahead of you.\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#creating a file id from the jsonl file\n", | |
"with open(\"joke_prepared.jsonl\") as f:\n", | |
" response = openai.File.create(file=f, purpose='fine-tune')\n", | |
" print(response)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "62H9dyNLlBqx", | |
"outputId": "2aecbd2e-25ca-460d-f471-44fa7b557892" | |
}, | |
"execution_count": 12, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"{\n", | |
" \"bytes\": 181225,\n", | |
" \"created_at\": 1658487883,\n", | |
" \"filename\": \"file\",\n", | |
" \"id\": \"file-IBVH2yRfMoUzF8fFoGIoatV0\",\n", | |
" \"object\": \"file\",\n", | |
" \"purpose\": \"fine-tune\",\n", | |
" \"status\": \"uploaded\",\n", | |
" \"status_details\": null\n", | |
"}\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#the file id is then used to create finetune model\n", | |
"response = openai.FineTune.create(training_file=\"file-IBVH2yRfMoUzF8fFoGIoatV0\", model='ada')\n", | |
"print(response)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "NxzuwSQVlL-S", | |
"outputId": "74e237ef-63cc-4f73-8357-7c8140d87af3" | |
}, | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"{\n", | |
" \"created_at\": 1658487913,\n", | |
" \"events\": [\n", | |
" {\n", | |
" \"created_at\": 1658487913,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Created fine-tune: ft-ab49gQRKvzFKwKstqZjX1lio\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" }\n", | |
" ],\n", | |
" \"fine_tuned_model\": null,\n", | |
" \"hyperparams\": {\n", | |
" \"batch_size\": null,\n", | |
" \"learning_rate_multiplier\": null,\n", | |
" \"n_epochs\": 4,\n", | |
" \"prompt_loss_weight\": 0.1\n", | |
" },\n", | |
" \"id\": \"ft-ab49gQRKvzFKwKstqZjX1lio\",\n", | |
" \"model\": \"ada\",\n", | |
" \"object\": \"fine-tune\",\n", | |
" \"organization_id\": \"org-wv1JXiBQXR2IcQ7PzJakqYeo\",\n", | |
" \"result_files\": [],\n", | |
" \"status\": \"pending\",\n", | |
" \"training_files\": [\n", | |
" {\n", | |
" \"bytes\": 181225,\n", | |
" \"created_at\": 1658487883,\n", | |
" \"filename\": \"file\",\n", | |
" \"id\": \"file-IBVH2yRfMoUzF8fFoGIoatV0\",\n", | |
" \"object\": \"file\",\n", | |
" \"purpose\": \"fine-tune\",\n", | |
" \"status\": \"processed\",\n", | |
" \"status_details\": null\n", | |
" }\n", | |
" ],\n", | |
" \"updated_at\": 1658487913,\n", | |
" \"validation_files\": []\n", | |
"}\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#this shows how much training has been done\n", | |
"response = openai.FineTune.retrieve(id=\"ft-ab49gQRKvzFKwKstqZjX1lio\")\n", | |
"print(response)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "ZcXju1DflUir", | |
"outputId": "5e8de77c-ecd8-4f3a-8088-e57f7c1dc971" | |
}, | |
"execution_count": 20, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"{\n", | |
" \"created_at\": 1658487913,\n", | |
" \"events\": [\n", | |
" {\n", | |
" \"created_at\": 1658487913,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Created fine-tune: ft-ab49gQRKvzFKwKstqZjX1lio\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658487917,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Fine-tune costs $0.06\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658487917,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Fine-tune enqueued. Queue number: 0\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658487921,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Fine-tune started\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658488223,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Completed epoch 1/4\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658488514,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Completed epoch 2/4\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658488804,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Completed epoch 3/4\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658489095,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Completed epoch 4/4\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658489119,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Uploaded model: ada:ft-personal-2022-07-22-11-25-19\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658489120,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Uploaded result file: file-EMh7pK05sdcT3SvdB2Pn9NDC\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" },\n", | |
" {\n", | |
" \"created_at\": 1658489120,\n", | |
" \"level\": \"info\",\n", | |
" \"message\": \"Fine-tune succeeded\",\n", | |
" \"object\": \"fine-tune-event\"\n", | |
" }\n", | |
" ],\n", | |
" \"fine_tuned_model\": \"ada:ft-personal-2022-07-22-11-25-19\",\n", | |
" \"hyperparams\": {\n", | |
" \"batch_size\": 2,\n", | |
" \"learning_rate_multiplier\": 0.1,\n", | |
" \"n_epochs\": 4,\n", | |
" \"prompt_loss_weight\": 0.1\n", | |
" },\n", | |
" \"id\": \"ft-ab49gQRKvzFKwKstqZjX1lio\",\n", | |
" \"model\": \"ada\",\n", | |
" \"object\": \"fine-tune\",\n", | |
" \"organization_id\": \"org-wv1JXiBQXR2IcQ7PzJakqYeo\",\n", | |
" \"result_files\": [\n", | |
" {\n", | |
" \"bytes\": 171720,\n", | |
" \"created_at\": 1658489120,\n", | |
" \"filename\": \"compiled_results.csv\",\n", | |
" \"id\": \"file-EMh7pK05sdcT3SvdB2Pn9NDC\",\n", | |
" \"object\": \"file\",\n", | |
" \"purpose\": \"fine-tune-results\",\n", | |
" \"status\": \"processed\",\n", | |
" \"status_details\": null\n", | |
" }\n", | |
" ],\n", | |
" \"status\": \"succeeded\",\n", | |
" \"training_files\": [\n", | |
" {\n", | |
" \"bytes\": 181225,\n", | |
" \"created_at\": 1658487883,\n", | |
" \"filename\": \"file\",\n", | |
" \"id\": \"file-IBVH2yRfMoUzF8fFoGIoatV0\",\n", | |
" \"object\": \"file\",\n", | |
" \"purpose\": \"fine-tune\",\n", | |
" \"status\": \"processed\",\n", | |
" \"status_details\": null\n", | |
" }\n", | |
" ],\n", | |
" \"updated_at\": 1658489120,\n", | |
" \"validation_files\": []\n", | |
"}\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#Checking the inference\n", | |
"ft_model = \"ada:ft-personal-2022-07-22-11-25-19\"\n", | |
"res = openai.Completion.create(model=ft_model, prompt=\"I hate ... \", max_tokens=18, temperature=1)\n", | |
"res" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "_FArVoEIlXTW", | |
"outputId": "2a345c15-0075-4395-d973-15bbd0570673" | |
}, | |
"execution_count": 49, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<OpenAIObject text_completion id=cmpl-5Wl8XTfwfe0gNok40ymddb83JGigK at 0x7f5322a996b0> JSON: {\n", | |
" \"choices\": [\n", | |
" {\n", | |
" \"finish_reason\": \"length\",\n", | |
" \"index\": 0,\n", | |
" \"logprobs\": null,\n", | |
" \"text\": \" Nothing in my entire life is alright. It's just a fool's joke. -> It\"\n", | |
" }\n", | |
" ],\n", | |
" \"created\": 1658489373,\n", | |
" \"id\": \"cmpl-5Wl8XTfwfe0gNok40ymddb83JGigK\",\n", | |
" \"model\": \"ada:ft-personal-2022-07-22-11-25-19\",\n", | |
" \"object\": \"text_completion\",\n", | |
" \"usage\": {\n", | |
" \"completion_tokens\": 18,\n", | |
" \"prompt_tokens\": 4,\n", | |
" \"total_tokens\": 22\n", | |
" }\n", | |
"}" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 49 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment