diff --git a/Decision_Tree_Promt_GPT_3 (1).ipynb b/Decision_Tree_Promt_GPT_3 (1).ipynb
new file mode 100644
index 0000000..b82a1ec
--- /dev/null
+++ b/Decision_Tree_Promt_GPT_3 (1).ipynb
@@ -0,0 +1,3006 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "CelFOfyF9ti_",
+ "outputId": "ce866d46-2915-4af4-815f-99dd9720fdf3"
+ },
+ "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.27.2-py3-none-any.whl (70 kB)\n",
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m70.1/70.1 KB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+ "\u001b[?25hRequirement already satisfied: tqdm in /usr/local/lib/python3.9/dist-packages (from openai) (4.65.0)\n",
+ "Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.9/dist-packages (from openai) (2.27.1)\n",
+ "Collecting aiohttp\n",
+ " Downloading aiohttp-3.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB)\n",
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m31.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+ "\u001b[?25hRequirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (3.4)\n",
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (2022.12.7)\n",
+ "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (2.0.12)\n",
+ "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests>=2.20->openai) (1.26.15)\n",
+ "Collecting frozenlist>=1.1.1\n",
+ " Downloading frozenlist-1.3.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158 kB)\n",
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m158.8/158.8 KB\u001b[0m \u001b[31m21.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+ "\u001b[?25hRequirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.9/dist-packages (from aiohttp->openai) (22.2.0)\n",
+ "Collecting async-timeout<5.0,>=4.0.0a3\n",
+ " Downloading async_timeout-4.0.2-py3-none-any.whl (5.8 kB)\n",
+ "Collecting multidict<7.0,>=4.5\n",
+ " Downloading multidict-6.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)\n",
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m114.2/114.2 KB\u001b[0m \u001b[31m14.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+ "\u001b[?25hCollecting yarl<2.0,>=1.0\n",
+ " Downloading yarl-1.8.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264 kB)\n",
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m264.6/264.6 KB\u001b[0m \u001b[31m29.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
+ "\u001b[?25hCollecting aiosignal>=1.1.2\n",
+ " Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n",
+ "Installing collected packages: multidict, frozenlist, async-timeout, yarl, aiosignal, aiohttp, openai\n",
+ "Successfully installed aiohttp-3.8.4 aiosignal-1.3.1 async-timeout-4.0.2 frozenlist-1.3.3 multidict-6.0.4 openai-0.27.2 yarl-1.8.2\n"
+ ]
+ }
+ ],
+ "source": [
+ "!pip install openai"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "id": "pP7YkLvs95Pt"
+ },
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "os.environ['OPENAI_API_KEY'] = \"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\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "id": "raj54WV098Dd"
+ },
+ "outputs": [],
+ "source": [
+ "import openai\n",
+ "def call(context):\n",
+ " try:\n",
+ " response = openai.Completion.create(\n",
+ " api_key = \"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\",\n",
+ " engine=\"text-davinci-003\",\n",
+ " prompt=context,\n",
+ " temperature=1,\n",
+ " max_tokens=900,\n",
+ " top_p=1,\n",
+ " frequency_penalty=0,\n",
+ " presence_penalty=0\n",
+ " )\n",
+ " return response['choices'][0]['text']\n",
+ " except Exception as e:\n",
+ " print (e)\n",
+ " return \"\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "id": "XOGiyCQb-QoM"
+ },
+ "outputs": [],
+ "source": [
+ "data = ''' \n",
+ "Preference\t Red_Wine\t White_Wine\t Recommendation\n",
+ "Red\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "White\t\t None Dry Sauvignon Blanc\n",
+ "White\t\t None None Sweet\tGewurztraminer\n",
+ "Red-Fruity\t None\t\t None Pinot Noir\n",
+ "Red-Earthy\t None\t\t None Chianti\n",
+ "White-Crisp\t None\t\t None Sauvignon Blanc\n",
+ "White-Creamy None\t\t\t None Chardonnay\n",
+ "Red-Spicy\t\t None\t None Shiraz or Zinfandel\n",
+ "Red-Rich\t\t None \t None Cabernet Sauvignon\n",
+ "White-Floral None\t\t\t None Gewurztraminer\n",
+ "White-Citrus None\t\t\t None Riesling\n",
+ "Red\t\t\t None None Pinot Noir\n",
+ "Red\t\t\t None None Chianti\n",
+ "White\t\t\t None None Sauvignon Blanc\n",
+ "White\t\t\t None None Chardonnay\n",
+ "Red\t\t\t None None Shiraz or Zinfandel\n",
+ "Red\t\t\t None None Cabernet Sauvignon\n",
+ "White\t\t\t None None Gewurztraminer\n",
+ "White\t\t\t None None Riesling\n",
+ "Red-Fruity\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Fruity\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "Red-Earthy\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Earthy\t Full-Bodied\t\t None Cabernet Sauvignon\n",
+ "White-Crisp\t Dry\t\t None Sauvignon Blanc\n",
+ "White-Crisp\t Sweet\t\t None Pinot Noir\n",
+ "White-Creamy Dry\t\t None Pinot Noir\n",
+ "White-Creamy Sweet\t\t None Chardonnay\n",
+ "Red-Spicy\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Spicy\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "Red-Rich\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Rich\t Full-Bodied\t\t None Cabernet Sauvignon\n",
+ "White-Floral\tDry\t\t None Pinot Noir\n",
+ "White-Floral\tSweet\t\t None Gewurztraminer\n",
+ "White-Citrus\tDry\t\t None Sauvignon Blanc\n",
+ "White-Citrus\tSweet\t\t None Riesling\n",
+ "Red-Fruity\t\tNone\t Sweet Pinot Noir\n",
+ "Red-Fruity\t\tNone\t Dry Pinot Noir\n",
+ "Red-Earthy\t\tNone\t Sweet Chianti\n",
+ "Red-Earthy\t\tNone\t Dry Pinot Noir\n",
+ "\n",
+ "\n",
+ "Based on the data generate 10 different choices and recommended based on the choices\n",
+ "'''\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "NBVKb7ZOBTtg",
+ "outputId": "98da1540-213a-4221-c866-ca0f880aaf05"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\n",
+ "1. Pinot Noir (Red-Fruity, Light-Bodied, Sweet) \n",
+ "2. Sauvignon Blanc (White-Crisp, Dry)\n",
+ "3. Chardonnay (White-Creamy, Sweet)\n",
+ "4. Chianti (Red-Earthy, Sweet) \n",
+ "5. Riesling (White-Citrus, Sweet)\n",
+ "6. Shiraz or Zinfandel (Red-Spicy, Full-Bodied)\n",
+ "7. Cabernet Sauvignon (Red-Rich, Full-Bodied)\n",
+ "8. Gewurztraminer (White-Floral, Sweet) \n",
+ "9. Pinot Noir (Red-Earthy, Light-Bodied)\n",
+ "10. Pinot Noir (Red-Fruity, Dry)\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(call(data))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "id": "hvcX7UWqBblL"
+ },
+ "outputs": [],
+ "source": [
+ "data1 = '''\n",
+ "Preference\t Red_Wine\t White_Wine\t Recommendation\n",
+ "Red\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "White\t\t None Dry Sauvignon Blanc\n",
+ "White\t\t None None Sweet\tGewurztraminer\n",
+ "Red-Fruity\t None\t\t None Pinot Noir\n",
+ "Red-Earthy\t None\t\t None Chianti\n",
+ "White-Crisp\t None\t\t None Sauvignon Blanc\n",
+ "White-Creamy None\t\t\t None Chardonnay\n",
+ "Red-Spicy\t\t None\t None Shiraz or Zinfandel\n",
+ "Red-Rich\t\t None \t None Cabernet Sauvignon\n",
+ "White-Floral None\t\t\t None Gewurztraminer\n",
+ "White-Citrus None\t\t\t None Riesling\n",
+ "Red\t\t\t None None Pinot Noir\n",
+ "Red\t\t\t None None Chianti\n",
+ "White\t\t\t None None Sauvignon Blanc\n",
+ "White\t\t\t None None Chardonnay\n",
+ "Red\t\t\t None None Shiraz or Zinfandel\n",
+ "Red\t\t\t None None Cabernet Sauvignon\n",
+ "White\t\t\t None None Gewurztraminer\n",
+ "White\t\t\t None None Riesling\n",
+ "Red-Fruity\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Fruity\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "Red-Earthy\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Earthy\t Full-Bodied\t\t None Cabernet Sauvignon\n",
+ "White-Crisp\t Dry\t\t None Sauvignon Blanc\n",
+ "White-Crisp\t Sweet\t\t None Pinot Noir\n",
+ "White-Creamy Dry\t\t None Pinot Noir\n",
+ "White-Creamy Sweet\t\t None Chardonnay\n",
+ "Red-Spicy\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Spicy\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "Red-Rich\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Rich\t Full-Bodied\t\t None Cabernet Sauvignon\n",
+ "White-Floral\tDry\t\t None Pinot Noir\n",
+ "White-Floral\tSweet\t\t None Gewurztraminer\n",
+ "White-Citrus\tDry\t\t None Sauvignon Blanc\n",
+ "White-Citrus\tSweet\t\t None Riesling\n",
+ "Red-Fruity\t\tNone\t Sweet Pinot Noir\n",
+ "Red-Fruity\t\tNone\t Dry Pinot Noir\n",
+ "Red-Earthy\t\tNone\t Sweet Chianti\n",
+ "Red-Earthy\t\tNone\t Dry Pinot Noir\n",
+ "\n",
+ "\n",
+ "Customer 1: Red,Dry?\n",
+ "Customer 2: White?\n",
+ "Customer 3: White-Earthry?\n",
+ "Customer 4: White-Floral,Light-Bodied?\n",
+ "Customer 5: Red-Spicy,Dry?\n",
+ "Customer 6: Red-Rich,Full-Bodied?\n",
+ "Customer 7: White-Creamy?\n",
+ "Customer 8: White-Crisp,Light-Bodied?\n",
+ "Customer 9: White-Crisp,Full-Bodied?\n",
+ "Customer 10: White-Crisp,Dry?\n",
+ "'''\n",
+ "result = call(data1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 54
+ },
+ "id": "j2huyLpSByd7",
+ "outputId": "b97dd46c-43b4-44b3-960c-4f2250bf1e27"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "'\\nRecommendation\\nCustomer 1: Pinot Noir\\nCustomer 2: Sauvignon Blanc\\nCustomer 3: Pinot Noir\\nCustomer 4: Pinot Noir \\nCustomer 5: Shiraz or Zinfandel\\nCustomer 6: Cabernet Sauvignon\\nCustomer 7: Chardonnay\\nCustomer 8: Sauvignon Blanc\\nCustomer 9: Pinot Noir\\nCustomer 10: Sauvignon Blanc'"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "string"
+ }
+ },
+ "metadata": {},
+ "execution_count": 41
+ }
+ ],
+ "source": [
+ "result"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "id": "WQ0o-f8ZDorN"
+ },
+ "outputs": [],
+ "source": [
+ "import re\n",
+ "results = re.split('Customer |[0-9]|:|\\n|Recommendation',result)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "id": "D1NJZE5zHcHE"
+ },
+ "outputs": [],
+ "source": [
+ "fin_res = [res for res in results if len(res)>0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "id": "GSW3EX85DraE"
+ },
+ "outputs": [],
+ "source": [
+ "data = {\n",
+ " 'Query':['Red,Dry?','White?','White-Earthry?','White-Floral,Light-Bodied?','Red-Spicy,Dry?','Red-Rich,Full-Bodied?','White-Creamy?','White-Crisp,Light-Bodied?','White-Crisp,Full-Bodied?','White-Crisp,Dry?'],\n",
+ " 'Recommendation': fin_res\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "fJbCVsgNHotD",
+ "outputId": "8f6571f8-ceba-43f0-bf2a-0e6253f903ec"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "{'Query': ['Red,Dry?',\n",
+ " 'White?',\n",
+ " 'White-Earthry?',\n",
+ " 'White-Floral,Light-Bodied?',\n",
+ " 'Red-Spicy,Dry?',\n",
+ " 'Red-Rich,Full-Bodied?',\n",
+ " 'White-Creamy?',\n",
+ " 'White-Crisp,Light-Bodied?',\n",
+ " 'White-Crisp,Full-Bodied?',\n",
+ " 'White-Crisp,Dry?'],\n",
+ " 'Recommendation': [' Pinot Noir',\n",
+ " ' Sauvignon Blanc',\n",
+ " ' Pinot Noir',\n",
+ " ' Pinot Noir ',\n",
+ " ' Shiraz or Zinfandel',\n",
+ " ' Cabernet Sauvignon',\n",
+ " ' Chardonnay',\n",
+ " ' Sauvignon Blanc',\n",
+ " ' Pinot Noir',\n",
+ " ' Sauvignon Blanc']}"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 45
+ }
+ ],
+ "source": [
+ "data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 206
+ },
+ "id": "lq1YFA-FHtmq",
+ "outputId": "9f2b43e9-1f61-49b0-d324-4a6dbeea6133"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Query Recommendation\n",
+ "0 Red,Dry? Pinot Noir\n",
+ "1 White? Sauvignon Blanc\n",
+ "2 White-Earthry? Pinot Noir\n",
+ "3 White-Floral,Light-Bodied? Pinot Noir \n",
+ "4 Red-Spicy,Dry? Shiraz or Zinfandel"
+ ],
+ "text/html": [
+ "\n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Query | \n",
+ " Recommendation | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " Red,Dry? | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " White? | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " White-Earthry? | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " White-Floral,Light-Bodied? | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " Red-Spicy,Dry? | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 46
+ }
+ ],
+ "source": [
+ "import pandas as pd\n",
+ "df = pd.DataFrame(data)\n",
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {
+ "id": "hZJksWOkH6VS"
+ },
+ "outputs": [],
+ "source": [
+ "data_4 = ''' \n",
+ "Preference\t Red_Wine\t White_Wine\t Recommendation\n",
+ "Red\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "White\t\t None Dry Sauvignon Blanc\n",
+ "White\t\t None None Sweet\tGewurztraminer\n",
+ "Red-Fruity\t None\t\t None Pinot Noir\n",
+ "Red-Earthy\t None\t\t None Chianti\n",
+ "White-Crisp\t None\t\t None Sauvignon Blanc\n",
+ "White-Creamy None\t\t\t None Chardonnay\n",
+ "Red-Spicy\t\t None\t None Shiraz or Zinfandel\n",
+ "Red-Rich\t\t None \t None Cabernet Sauvignon\n",
+ "White-Floral None\t\t\t None Gewurztraminer\n",
+ "White-Citrus None\t\t\t None Riesling\n",
+ "Red\t\t\t None None Pinot Noir\n",
+ "Red\t\t\t None None Chianti\n",
+ "White\t\t\t None None Sauvignon Blanc\n",
+ "White\t\t\t None None Chardonnay\n",
+ "Red\t\t\t None None Shiraz or Zinfandel\n",
+ "Red\t\t\t None None Cabernet Sauvignon\n",
+ "White\t\t\t None None Gewurztraminer\n",
+ "White\t\t\t None None Riesling\n",
+ "Red-Fruity\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Fruity\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "Red-Earthy\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Earthy\t Full-Bodied\t\t None Cabernet Sauvignon\n",
+ "White-Crisp\t Dry\t\t None Sauvignon Blanc\n",
+ "White-Crisp\t Sweet\t\t None Pinot Noir\n",
+ "White-Creamy Dry\t\t None Pinot Noir\n",
+ "White-Creamy Sweet\t\t None Chardonnay\n",
+ "Red-Spicy\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Spicy\t Full-Bodied\t\t None Shiraz or Zinfandel\n",
+ "Red-Rich\t Light-Bodied\t\tNone Pinot Noir\n",
+ "Red-Rich\t Full-Bodied\t\t None Cabernet Sauvignon\n",
+ "White-Floral\tDry\t\t None Pinot Noir\n",
+ "White-Floral\tSweet\t\t None Gewurztraminer\n",
+ "White-Citrus\tDry\t\t None Sauvignon Blanc\n",
+ "White-Citrus\tSweet\t\t None Riesling\n",
+ "Red-Fruity\t\tNone\t Sweet Pinot Noir\n",
+ "Red-Fruity\t\tNone\t Dry Pinot Noir\n",
+ "Red-Earthy\t\tNone\t Sweet Chianti\n",
+ "Red-Earthy\t\tNone\t Dry Pinot Noir\n",
+ "\n",
+ "\n",
+ "Based on the data generate 20 different choices and recommended based on the choices\n",
+ "'''\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "id": "VF7kwoFuYIT4"
+ },
+ "outputs": [],
+ "source": [
+ "Questions = call(data_4)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 109
+ },
+ "id": "zSwiyj-QYNYo",
+ "outputId": "042d5f15-2dc9-4856-e2bc-2e59b43643a9"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "'\\n1. Pinot Noir (Red-Fruity, Dry)\\n2. Shiraz or Zinfandel (Red-Fruity, Full-Bodied)\\n3. Sauvignon Blanc (White-Crisp, Dry)\\n4. Sweet Gewurztraminer (White, None)\\n5. Chianti (Red-Earthy, None)\\n6. Chardonnay (White-Creamy, Sweet)\\n7. Cabernet Sauvignon (Red-Rich, Full-Bodied)\\n8. Pinot Noir (Red, Light-Bodied)\\n9. Shiraz or Zinfandel (Red-Spicy, Light-Bodied)\\n10. Pinot Noir (Red, None)\\n11. Chianti (Red, None)\\n12. Sauvignon Blanc (White, None)\\n13. Chardonnay (White, None)\\n14. Shiraz or Zinfandel (Red, None)\\n15. Cabernet Sauvignon (Red, None)\\n16. Gewurztraminer (White-Floral, Sweet)\\n17. Riesling (White-Citrus, Sweet)\\n18. Pinot Noir (Red-Earthy, Light-Bodied)\\n19. Cabernet Sauvignon (Red-Rich, Light-Bodied)\\n20. Pinot Noir (White-Crisp, Sweet)'"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "string"
+ }
+ },
+ "metadata": {},
+ "execution_count": 49
+ }
+ ],
+ "source": [
+ "Questions"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {
+ "id": "YaP0OU8MYtJ4"
+ },
+ "outputs": [],
+ "source": [
+ "temp = re.split('[0-9]|\\n|\\.',Questions)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "pGeywgUbZC1w",
+ "outputId": "6d3fff60-6c31-4a24-d50b-7f7e8c9a1a54"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "[' Pinot Noir (Red-Fruity, Dry)',\n",
+ " ' Shiraz or Zinfandel (Red-Fruity, Full-Bodied)',\n",
+ " ' Sauvignon Blanc (White-Crisp, Dry)',\n",
+ " ' Sweet Gewurztraminer (White, None)',\n",
+ " ' Chianti (Red-Earthy, None)',\n",
+ " ' Chardonnay (White-Creamy, Sweet)',\n",
+ " ' Cabernet Sauvignon (Red-Rich, Full-Bodied)',\n",
+ " ' Pinot Noir (Red, Light-Bodied)',\n",
+ " ' Shiraz or Zinfandel (Red-Spicy, Light-Bodied)',\n",
+ " ' Pinot Noir (Red, None)',\n",
+ " ' Chianti (Red, None)',\n",
+ " ' Sauvignon Blanc (White, None)',\n",
+ " ' Chardonnay (White, None)',\n",
+ " ' Shiraz or Zinfandel (Red, None)',\n",
+ " ' Cabernet Sauvignon (Red, None)',\n",
+ " ' Gewurztraminer (White-Floral, Sweet)',\n",
+ " ' Riesling (White-Citrus, Sweet)',\n",
+ " ' Pinot Noir (Red-Earthy, Light-Bodied)',\n",
+ " ' Cabernet Sauvignon (Red-Rich, Light-Bodied)',\n",
+ " ' Pinot Noir (White-Crisp, Sweet)']"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 52
+ }
+ ],
+ "source": [
+ "QA = [tem for tem in temp if len(tem)>0]\n",
+ "QA"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {
+ "id": "LtK-srHkaHU4"
+ },
+ "outputs": [],
+ "source": [
+ "ques = []\n",
+ "ans = []\n",
+ "\n",
+ "for item in QA:\n",
+ " a = item\n",
+ " b = re.split('[()]|\\|',a)\n",
+ " ans.append(b[0])\n",
+ " j = 0\n",
+ " str_temp = \"(\"\n",
+ " for i in b:\n",
+ " if j==0:\n",
+ " j = -1\n",
+ " continue\n",
+ " elif len(i):\n",
+ " str_temp += i\n",
+ " str_temp += \"|\"\n",
+ "\n",
+ " str_temp = str_temp.rstrip(\"|\")\n",
+ " str_temp += \")\" \n",
+ " ques.append(str_temp)\n",
+ " str_temp = \"\"\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "KpOLQ105an9v",
+ "outputId": "e3f94de1-e03b-48ae-fc9e-809221f0b111"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "['(Red-Fruity, Dry)',\n",
+ " '(Red-Fruity, Full-Bodied)',\n",
+ " '(White-Crisp, Dry)',\n",
+ " '(White, None)',\n",
+ " '(Red-Earthy, None)',\n",
+ " '(White-Creamy, Sweet)',\n",
+ " '(Red-Rich, Full-Bodied)',\n",
+ " '(Red, Light-Bodied)',\n",
+ " '(Red-Spicy, Light-Bodied)',\n",
+ " '(Red, None)',\n",
+ " '(Red, None)',\n",
+ " '(White, None)',\n",
+ " '(White, None)',\n",
+ " '(Red, None)',\n",
+ " '(Red, None)',\n",
+ " '(White-Floral, Sweet)',\n",
+ " '(White-Citrus, Sweet)',\n",
+ " '(Red-Earthy, Light-Bodied)',\n",
+ " '(Red-Rich, Light-Bodied)',\n",
+ " '(White-Crisp, Sweet)']"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 54
+ }
+ ],
+ "source": [
+ "ques"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "SBRw37z7cQ9I",
+ "outputId": "78c414b2-397f-41f6-8cb4-793bd72eed7f"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "[' Pinot Noir ',\n",
+ " ' Shiraz or Zinfandel ',\n",
+ " ' Sauvignon Blanc ',\n",
+ " ' Sweet Gewurztraminer ',\n",
+ " ' Chianti ',\n",
+ " ' Chardonnay ',\n",
+ " ' Cabernet Sauvignon ',\n",
+ " ' Pinot Noir ',\n",
+ " ' Shiraz or Zinfandel ',\n",
+ " ' Pinot Noir ',\n",
+ " ' Chianti ',\n",
+ " ' Sauvignon Blanc ',\n",
+ " ' Chardonnay ',\n",
+ " ' Shiraz or Zinfandel ',\n",
+ " ' Cabernet Sauvignon ',\n",
+ " ' Gewurztraminer ',\n",
+ " ' Riesling ',\n",
+ " ' Pinot Noir ',\n",
+ " ' Cabernet Sauvignon ',\n",
+ " ' Pinot Noir ']"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 55
+ }
+ ],
+ "source": [
+ "ans"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 70,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 206
+ },
+ "id": "iBEOQXdCdg1A",
+ "outputId": "bf03a995-170e-455f-8e98-433bb254fdfd"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Question Answer\n",
+ "0 (Red-Fruity, Dry) Pinot Noir \n",
+ "1 (Red-Fruity, Full-Bodied) Shiraz or Zinfandel \n",
+ "2 (White-Crisp, Dry) Sauvignon Blanc \n",
+ "3 (White, None) Sweet Gewurztraminer \n",
+ "4 (Red-Earthy, None) Chianti "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Question | \n",
+ " Answer | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " (Red-Fruity, Dry) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " (Red-Fruity, Full-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " (White-Crisp, Dry) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " (White, None) | \n",
+ " Sweet Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " (Red-Earthy, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 70
+ }
+ ],
+ "source": [
+ "data_temp = {'Question':ques,'Answer':ans}\n",
+ "df1 = pd.DataFrame(data_temp)\n",
+ "df1.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 71,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 676
+ },
+ "id": "mrcR7rr7d2W3",
+ "outputId": "6f530435-9415-41f4-f4d4-8eca01ea877a"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Question Answer\n",
+ "0 (Red-Fruity, Dry) Pinot Noir \n",
+ "1 (Red-Fruity, Full-Bodied) Shiraz or Zinfandel \n",
+ "2 (White-Crisp, Dry) Sauvignon Blanc \n",
+ "3 (White, None) Sweet Gewurztraminer \n",
+ "4 (Red-Earthy, None) Chianti \n",
+ "5 (White-Creamy, Sweet) Chardonnay \n",
+ "6 (Red-Rich, Full-Bodied) Cabernet Sauvignon \n",
+ "7 (Red, Light-Bodied) Pinot Noir \n",
+ "8 (Red-Spicy, Light-Bodied) Shiraz or Zinfandel \n",
+ "9 (Red, None) Pinot Noir \n",
+ "10 (Red, None) Chianti \n",
+ "11 (White, None) Sauvignon Blanc \n",
+ "12 (White, None) Chardonnay \n",
+ "13 (Red, None) Shiraz or Zinfandel \n",
+ "14 (Red, None) Cabernet Sauvignon \n",
+ "15 (White-Floral, Sweet) Gewurztraminer \n",
+ "16 (White-Citrus, Sweet) Riesling \n",
+ "17 (Red-Earthy, Light-Bodied) Pinot Noir \n",
+ "18 (Red-Rich, Light-Bodied) Cabernet Sauvignon \n",
+ "19 (White-Crisp, Sweet) Pinot Noir "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Question | \n",
+ " Answer | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " (Red-Fruity, Dry) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " (Red-Fruity, Full-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " (White-Crisp, Dry) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " (White, None) | \n",
+ " Sweet Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " (Red-Earthy, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " (White-Creamy, Sweet) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " (Red-Rich, Full-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " (Red, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " (Red-Spicy, Light-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " (Red, None) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " (Red, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " (White, None) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " (White, None) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " (Red, None) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " (Red, None) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " (White-Floral, Sweet) | \n",
+ " Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " (White-Citrus, Sweet) | \n",
+ " Riesling | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " (Red-Earthy, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " (Red-Rich, Light-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " (White-Crisp, Sweet) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 71
+ }
+ ],
+ "source": [
+ "df1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1['Answer'] = df1['Answer'].str.replace(' END', '')"
+ ],
+ "metadata": {
+ "id": "C02VOrRdsJF1"
+ },
+ "execution_count": 72,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1"
+ ],
+ "metadata": {
+ "id": "o7JXsozXsMV9",
+ "outputId": "0d0e9530-d0d8-4dca-dd13-70f290220bfe",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 676
+ }
+ },
+ "execution_count": 73,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Question Answer\n",
+ "0 (Red-Fruity, Dry) Pinot Noir \n",
+ "1 (Red-Fruity, Full-Bodied) Shiraz or Zinfandel \n",
+ "2 (White-Crisp, Dry) Sauvignon Blanc \n",
+ "3 (White, None) Sweet Gewurztraminer \n",
+ "4 (Red-Earthy, None) Chianti \n",
+ "5 (White-Creamy, Sweet) Chardonnay \n",
+ "6 (Red-Rich, Full-Bodied) Cabernet Sauvignon \n",
+ "7 (Red, Light-Bodied) Pinot Noir \n",
+ "8 (Red-Spicy, Light-Bodied) Shiraz or Zinfandel \n",
+ "9 (Red, None) Pinot Noir \n",
+ "10 (Red, None) Chianti \n",
+ "11 (White, None) Sauvignon Blanc \n",
+ "12 (White, None) Chardonnay \n",
+ "13 (Red, None) Shiraz or Zinfandel \n",
+ "14 (Red, None) Cabernet Sauvignon \n",
+ "15 (White-Floral, Sweet) Gewurztraminer \n",
+ "16 (White-Citrus, Sweet) Riesling \n",
+ "17 (Red-Earthy, Light-Bodied) Pinot Noir \n",
+ "18 (Red-Rich, Light-Bodied) Cabernet Sauvignon \n",
+ "19 (White-Crisp, Sweet) Pinot Noir "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Question | \n",
+ " Answer | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " (Red-Fruity, Dry) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " (Red-Fruity, Full-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " (White-Crisp, Dry) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " (White, None) | \n",
+ " Sweet Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " (Red-Earthy, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " (White-Creamy, Sweet) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " (Red-Rich, Full-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " (Red, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " (Red-Spicy, Light-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " (Red, None) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " (Red, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " (White, None) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " (White, None) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " (Red, None) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " (Red, None) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " (White-Floral, Sweet) | \n",
+ " Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " (White-Citrus, Sweet) | \n",
+ " Riesling | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " (Red-Earthy, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " (Red-Rich, Light-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " (White-Crisp, Sweet) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 73
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1['Question'] = df1['Question'].str.strip()"
+ ],
+ "metadata": {
+ "id": "d66os-iBsRrf"
+ },
+ "execution_count": 74,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1"
+ ],
+ "metadata": {
+ "id": "YfWJRjzps_Xe",
+ "outputId": "2a3e9599-458b-45b0-ab62-a2579ff48b8c",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 676
+ }
+ },
+ "execution_count": 75,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Question Answer\n",
+ "0 (Red-Fruity, Dry) Pinot Noir \n",
+ "1 (Red-Fruity, Full-Bodied) Shiraz or Zinfandel \n",
+ "2 (White-Crisp, Dry) Sauvignon Blanc \n",
+ "3 (White, None) Sweet Gewurztraminer \n",
+ "4 (Red-Earthy, None) Chianti \n",
+ "5 (White-Creamy, Sweet) Chardonnay \n",
+ "6 (Red-Rich, Full-Bodied) Cabernet Sauvignon \n",
+ "7 (Red, Light-Bodied) Pinot Noir \n",
+ "8 (Red-Spicy, Light-Bodied) Shiraz or Zinfandel \n",
+ "9 (Red, None) Pinot Noir \n",
+ "10 (Red, None) Chianti \n",
+ "11 (White, None) Sauvignon Blanc \n",
+ "12 (White, None) Chardonnay \n",
+ "13 (Red, None) Shiraz or Zinfandel \n",
+ "14 (Red, None) Cabernet Sauvignon \n",
+ "15 (White-Floral, Sweet) Gewurztraminer \n",
+ "16 (White-Citrus, Sweet) Riesling \n",
+ "17 (Red-Earthy, Light-Bodied) Pinot Noir \n",
+ "18 (Red-Rich, Light-Bodied) Cabernet Sauvignon \n",
+ "19 (White-Crisp, Sweet) Pinot Noir "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Question | \n",
+ " Answer | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " (Red-Fruity, Dry) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " (Red-Fruity, Full-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " (White-Crisp, Dry) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " (White, None) | \n",
+ " Sweet Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " (Red-Earthy, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " (White-Creamy, Sweet) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " (Red-Rich, Full-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " (Red, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " (Red-Spicy, Light-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " (Red, None) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " (Red, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " (White, None) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " (White, None) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " (Red, None) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " (Red, None) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " (White-Floral, Sweet) | \n",
+ " Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " (White-Citrus, Sweet) | \n",
+ " Riesling | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " (Red-Earthy, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " (Red-Rich, Light-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " (White-Crisp, Sweet) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 75
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1['Question'] = 'Question: ' + df1['Question']"
+ ],
+ "metadata": {
+ "id": "x2U6hCOxtBef"
+ },
+ "execution_count": 76,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1"
+ ],
+ "metadata": {
+ "id": "YXChQOBzsVNl",
+ "outputId": "d0f70f77-8e4f-4ec1-bf4b-778fd016dfd2",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 676
+ }
+ },
+ "execution_count": 77,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Question Answer\n",
+ "0 Question: (Red-Fruity, Dry) Pinot Noir \n",
+ "1 Question: (Red-Fruity, Full-Bodied) Shiraz or Zinfandel \n",
+ "2 Question: (White-Crisp, Dry) Sauvignon Blanc \n",
+ "3 Question: (White, None) Sweet Gewurztraminer \n",
+ "4 Question: (Red-Earthy, None) Chianti \n",
+ "5 Question: (White-Creamy, Sweet) Chardonnay \n",
+ "6 Question: (Red-Rich, Full-Bodied) Cabernet Sauvignon \n",
+ "7 Question: (Red, Light-Bodied) Pinot Noir \n",
+ "8 Question: (Red-Spicy, Light-Bodied) Shiraz or Zinfandel \n",
+ "9 Question: (Red, None) Pinot Noir \n",
+ "10 Question: (Red, None) Chianti \n",
+ "11 Question: (White, None) Sauvignon Blanc \n",
+ "12 Question: (White, None) Chardonnay \n",
+ "13 Question: (Red, None) Shiraz or Zinfandel \n",
+ "14 Question: (Red, None) Cabernet Sauvignon \n",
+ "15 Question: (White-Floral, Sweet) Gewurztraminer \n",
+ "16 Question: (White-Citrus, Sweet) Riesling \n",
+ "17 Question: (Red-Earthy, Light-Bodied) Pinot Noir \n",
+ "18 Question: (Red-Rich, Light-Bodied) Cabernet Sauvignon \n",
+ "19 Question: (White-Crisp, Sweet) Pinot Noir "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Question | \n",
+ " Answer | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " Question: (Red-Fruity, Dry) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " Question: (Red-Fruity, Full-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " Question: (White-Crisp, Dry) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " Question: (White, None) | \n",
+ " Sweet Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " Question: (Red-Earthy, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " Question: (White-Creamy, Sweet) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " Question: (Red-Rich, Full-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " Question: (Red, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " Question: (Red-Spicy, Light-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " Question: (Red, None) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " Question: (Red, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " Question: (White, None) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " Question: (White, None) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " Question: (Red, None) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " Question: (Red, None) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " Question: (White-Floral, Sweet) | \n",
+ " Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " Question: (White-Citrus, Sweet) | \n",
+ " Riesling | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " Question: (Red-Earthy, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " Question: (Red-Rich, Light-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " Question: (White-Crisp, Sweet) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 77
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1.loc[0] = [\"Question: \\n\\nAnswer:\\n\\n\",\"END\"]"
+ ],
+ "metadata": {
+ "id": "IsUtstXYt-j1"
+ },
+ "execution_count": 78,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df1"
+ ],
+ "metadata": {
+ "id": "JaRMnbmbuWIF",
+ "outputId": "95acf69b-6538-4270-bc03-f187eaa28e05",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 676
+ }
+ },
+ "execution_count": 79,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Question Answer\n",
+ "0 Question: \\n\\nAnswer:\\n\\n END\n",
+ "1 Question: (Red-Fruity, Full-Bodied) Shiraz or Zinfandel \n",
+ "2 Question: (White-Crisp, Dry) Sauvignon Blanc \n",
+ "3 Question: (White, None) Sweet Gewurztraminer \n",
+ "4 Question: (Red-Earthy, None) Chianti \n",
+ "5 Question: (White-Creamy, Sweet) Chardonnay \n",
+ "6 Question: (Red-Rich, Full-Bodied) Cabernet Sauvignon \n",
+ "7 Question: (Red, Light-Bodied) Pinot Noir \n",
+ "8 Question: (Red-Spicy, Light-Bodied) Shiraz or Zinfandel \n",
+ "9 Question: (Red, None) Pinot Noir \n",
+ "10 Question: (Red, None) Chianti \n",
+ "11 Question: (White, None) Sauvignon Blanc \n",
+ "12 Question: (White, None) Chardonnay \n",
+ "13 Question: (Red, None) Shiraz or Zinfandel \n",
+ "14 Question: (Red, None) Cabernet Sauvignon \n",
+ "15 Question: (White-Floral, Sweet) Gewurztraminer \n",
+ "16 Question: (White-Citrus, Sweet) Riesling \n",
+ "17 Question: (Red-Earthy, Light-Bodied) Pinot Noir \n",
+ "18 Question: (Red-Rich, Light-Bodied) Cabernet Sauvignon \n",
+ "19 Question: (White-Crisp, Sweet) Pinot Noir "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Question | \n",
+ " Answer | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " Question: \\n\\nAnswer:\\n\\n | \n",
+ " END | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " Question: (Red-Fruity, Full-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " Question: (White-Crisp, Dry) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " Question: (White, None) | \n",
+ " Sweet Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " Question: (Red-Earthy, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " Question: (White-Creamy, Sweet) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " Question: (Red-Rich, Full-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " Question: (Red, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " Question: (Red-Spicy, Light-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " Question: (Red, None) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " Question: (Red, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " Question: (White, None) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " Question: (White, None) | \n",
+ " Chardonnay | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " Question: (Red, None) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " Question: (Red, None) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " Question: (White-Floral, Sweet) | \n",
+ " Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " Question: (White-Citrus, Sweet) | \n",
+ " Riesling | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " Question: (Red-Earthy, Light-Bodied) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " Question: (Red-Rich, Light-Bodied) | \n",
+ " Cabernet Sauvignon | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " Question: (White-Crisp, Sweet) | \n",
+ " Pinot Noir | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 79
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 80,
+ "metadata": {
+ "id": "z3ghh7CWd8KC"
+ },
+ "outputs": [],
+ "source": [
+ "df1.columns = ['prompt', 'completion']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 81,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 206
+ },
+ "id": "gjDCSFdleC5n",
+ "outputId": "1b73d9ea-a7e4-43ff-82dc-813e84eb1c49"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " prompt completion\n",
+ "0 Question: \\n\\nAnswer:\\n\\n END\n",
+ "1 Question: (Red-Fruity, Full-Bodied) Shiraz or Zinfandel \n",
+ "2 Question: (White-Crisp, Dry) Sauvignon Blanc \n",
+ "3 Question: (White, None) Sweet Gewurztraminer \n",
+ "4 Question: (Red-Earthy, None) Chianti "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " prompt | \n",
+ " completion | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " Question: \\n\\nAnswer:\\n\\n | \n",
+ " END | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " Question: (Red-Fruity, Full-Bodied) | \n",
+ " Shiraz or Zinfandel | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " Question: (White-Crisp, Dry) | \n",
+ " Sauvignon Blanc | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " Question: (White, None) | \n",
+ " Sweet Gewurztraminer | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " Question: (Red-Earthy, None) | \n",
+ " Chianti | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 81
+ }
+ ],
+ "source": [
+ "df1.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 82,
+ "metadata": {
+ "id": "bUCjN6UVeERH"
+ },
+ "outputs": [],
+ "source": [
+ "df1.to_json('qa_sample.jsonl', orient='records', lines=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 83,
+ "metadata": {
+ "id": "5pNltIc1eKpP"
+ },
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "os.environ['OPENAI_API_KEY'] = \"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\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 84,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "qMKRiq8jeVN6",
+ "outputId": "68747b92-83c8-47c2-a7f5-690c0475df48"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Analyzing...\n",
+ "\n",
+ "- Your file contains 20 prompt-completion pairs. In general, we recommend having at least a few hundred examples. We've found that performance tends to linearly increase for every doubling of the number of examples\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://platform.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",
+ "- All prompts start with prefix `Question: `\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://platform.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://platform.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",
+ "- [Recommended] Add a suffix separator `\\n\\n###\\n\\n` to all prompts [Y/n]: Y\n",
+ "- [Recommended] Add a suffix ending `\\n` to all completions [Y/n]: Y\n",
+ "- [Recommended] Add a whitespace character to the beginning of the completion [Y/n]: Y\n",
+ "\n",
+ "\n",
+ "Your data will be written to a new JSONL file. Proceed [Y/n]: Y\n",
+ "\n",
+ "Wrote modified file to `qa_sample_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 \"qa_sample_prepared.jsonl\"\n",
+ "\n",
+ "After you’ve fine-tuned a model, remember that your prompt has to end with the indicator string `\\n\\n###\\n\\n` 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 2.72 minutes to train a `curie` model, and less for `ada` and `babbage`. Queue will approximately take half an hour per job ahead of you.\n"
+ ]
+ }
+ ],
+ "source": [
+ "!openai tools fine_tunes.prepare_data -f qa_sample.jsonl"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 85,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "rB6S552FeNmn",
+ "outputId": "df95cacd-e10e-4f12-fd7d-b93047e03ed8"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\rUpload progress: 0% 0.00/1.72k [00:00, ?it/s]\rUpload progress: 100% 1.72k/1.72k [00:00<00:00, 2.53Mit/s]\n",
+ "Uploaded file from qa_sample_prepared.jsonl: file-EJzP9CiMe5CeL9ub20pEVPDr\n",
+ "Created fine-tune: ft-rtDJX5c4gZGQsathmhgkAdMZ\n",
+ "Streaming events until fine-tuning is complete...\n",
+ "\n",
+ "(Ctrl-C will interrupt the stream, but not cancel the fine-tune)\n",
+ "[2023-03-23 18:29:02] Created fine-tune: ft-rtDJX5c4gZGQsathmhgkAdMZ\n",
+ "\n",
+ "Stream interrupted (client disconnected).\n",
+ "To resume the stream, run:\n",
+ "\n",
+ " openai api fine_tunes.follow -i ft-rtDJX5c4gZGQsathmhgkAdMZ\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "!openai api fine_tunes.create -t 'qa_sample_prepared.jsonl' -m 'davinci'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 94,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "Sav-4eTkekpn",
+ "outputId": "4178cdcf-c0d6-436d-90e0-6caf82cb37cb"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "[2023-03-23 18:29:02] Created fine-tune: ft-rtDJX5c4gZGQsathmhgkAdMZ\n",
+ "[2023-03-23 18:32:38] Fine-tune costs $0.05\n",
+ "[2023-03-23 18:32:38] Fine-tune enqueued. Queue number: 5\n",
+ "[2023-03-23 18:33:28] Fine-tune is in the queue. Queue number: 4\n",
+ "[2023-03-23 18:33:46] Fine-tune is in the queue. Queue number: 3\n",
+ "[2023-03-23 18:34:34] Fine-tune is in the queue. Queue number: 2\n",
+ "[2023-03-23 18:36:03] Fine-tune is in the queue. Queue number: 1\n",
+ "[2023-03-23 18:36:46] Fine-tune is in the queue. Queue number: 0\n",
+ "[2023-03-23 18:36:52] Fine-tune started\n",
+ "[2023-03-23 18:39:01] Completed epoch 1/4\n",
+ "[2023-03-23 18:39:07] Completed epoch 2/4\n",
+ "[2023-03-23 18:39:12] Completed epoch 3/4\n",
+ "[2023-03-23 18:39:18] Completed epoch 4/4\n",
+ "[2023-03-23 18:39:56] Uploaded model: davinci:ft-global-corporate-holdings-2023-03-23-18-39-55\n",
+ "[2023-03-23 18:39:57] Uploaded result file: file-my0JOmf92CH1KdwI9SG6czp6\n",
+ "[2023-03-23 18:39:57] Fine-tune succeeded\n",
+ "\n",
+ "Job complete! Status: succeeded 🎉\n",
+ "Try out your fine-tuned model:\n",
+ "\n",
+ "openai api completions.create -m davinci:ft-global-corporate-holdings-2023-03-23-18-39-55 -p \n"
+ ]
+ }
+ ],
+ "source": [
+ "!openai api fine_tunes.follow -i ft-rtDJX5c4gZGQsathmhgkAdMZ"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 97,
+ "metadata": {
+ "id": "pwdFktBKe_On",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "3a817df0-479b-430b-995b-a184878aff87"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Answer the question based on DataSet Q: (White-Floral, Sweet) \n",
+ " Answer: Moscato d'Asti\n",
+ "\n",
+ "Q:\n"
+ ]
+ }
+ ],
+ "source": [
+ "!openai api completions.create -m davinci:ft-global-corporate-holdings-2023-03-23-18-39-55 -p \"Answer the question based on DataSet Q: (White-Floral, Sweet)\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import openai\n",
+ "def get_answers_api(question):\n",
+ " try:\n",
+ " response = openai.Completion.create(\n",
+ " api_key = \"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\",\n",
+ " engine=\"davinci:ft-global-corporate-holdings-2023-03-23-18-39-55\",\n",
+ " prompt=f\"Answer the question based on DataSet Q:\\n{question}\\n\\nAnswer:\",\n",
+ " temperature=0,\n",
+ " max_tokens=900,\n",
+ " top_p=1,\n",
+ " frequency_penalty=0,\n",
+ " presence_penalty=0\n",
+ " )\n",
+ " return response['choices'][0]['text']\n",
+ " except Exception as e:\n",
+ " print (e)\n",
+ " return \"\"\n",
+ "\n",
+ "print(get_answers_api('White-Floral, Sweet'))"
+ ],
+ "metadata": {
+ "id": "FOpiYqihxjUo",
+ "outputId": "87e7b8a2-c785-492c-b844-9535036aa9bc",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "execution_count": 99,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n",
+ "\n",
+ "The correct answer is:\n",
+ "\n",
+ "\"Chardonnay\"\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import openai\n",
+ "openai.api_key = \"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\"\n",
+ "response = openai.ChatCompletion.create(\n",
+ " model=\"gpt-3.5-turbo\",\n",
+ " messages= [{\n",
+ " \"role\": \"system\",\n",
+ " \"content\": \"You are a assistant\"\n",
+ " },\n",
+ "\n",
+ " {\n",
+ " \"role\": \"user\",\n",
+ " \"content\": \"Can you recommend wine based on my taste?\"\n",
+ " },\n",
+ "\n",
+ " {\n",
+ " \"content\": \"Of course! Please provide me with some details about your wine, such as Preference(Red,White,Red-Fruity,Red-Earthy,White-Crisp,Red-Spicy,Red-Rich), Red_Wine characteristics(Light-Bodied,Full-Bodied,Dry,Sweet,None), White_Wine Characteristics(Dry,Sweet,None) and the recommended wine such as (Pinot Noir,Gewurztraminer,Sauvignon Blanc,Shiraz or Zinfandel,Chianti,Chardonnay,Cabernet Sauvignon,Riesling).\",\n",
+ " \"role\": \"assistant\"\n",
+ " }, \n",
+ " {\n",
+ " \"role\": \"user\",\n",
+ " \"content\": \"(Red,Light-Bodied,None)\"\n",
+ " }\n",
+ "\n",
+ " \n",
+ " ]\n",
+ " )\n",
+ "print(response)"
+ ],
+ "metadata": {
+ "id": "nbEDdjmgyNLE",
+ "outputId": "c5b79e79-346d-4bde-b750-98e2cb58c813",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "execution_count": 101,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "{\n",
+ " \"choices\": [\n",
+ " {\n",
+ " \"finish_reason\": \"stop\",\n",
+ " \"index\": 0,\n",
+ " \"message\": {\n",
+ " \"content\": \"Based on your preferences, I would suggest trying a Pinot Noir from Oregon or Burgundy. Both regions are known for producing Pinot Noir wines that are light-bodied with delicate fruit flavors, and have a lower tannin profile. Some specific recommendations include:\\n\\n- Erath Pinot Noir (Oregon)\\n- Domaine William F\\u00e8vre Chablis \\\"Le Domaine\\\" Pinot Noir (Burgundy, France)\\n- Joseph Drouhin LaFor\\u00eat Bourgogne Pinot Noir (Burgundy, France)\",\n",
+ " \"role\": \"assistant\"\n",
+ " }\n",
+ " }\n",
+ " ],\n",
+ " \"created\": 1679597713,\n",
+ " \"id\": \"chatcmpl-6xKNdM2Ye333AhWnzhF8hwOLTSjhT\",\n",
+ " \"model\": \"gpt-3.5-turbo-0301\",\n",
+ " \"object\": \"chat.completion\",\n",
+ " \"usage\": {\n",
+ " \"completion_tokens\": 108,\n",
+ " \"prompt_tokens\": 164,\n",
+ " \"total_tokens\": 272\n",
+ " }\n",
+ "}\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [],
+ "metadata": {
+ "id": "F_H-PxFL0lzw"
+ },
+ "execution_count": null,
+ "outputs": []
+ }
+ ],
+ "metadata": {
+ "colab": {
+ "provenance": []
+ },
+ "kernelspec": {
+ "display_name": "Python 3",
+ "name": "python3"
+ },
+ "language_info": {
+ "name": "python"
+ },
+ "accelerator": "GPU",
+ "gpuClass": "standard"
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
\ No newline at end of file
diff --git a/qa_sample.jsonl b/qa_sample.jsonl
new file mode 100644
index 0000000..766b54c
--- /dev/null
+++ b/qa_sample.jsonl
@@ -0,0 +1,20 @@
+{"prompt":"Question: (Red-Fruity, Dry)\n\nAnswer:\n\n","completion":" Pinot Noir "}
+{"prompt":"Question: (Red-Fruity, Full-Bodied)\n\nAnswer:\n\n","completion":" Shiraz or Zinfandel "}
+{"prompt":"Question: (White-Crisp, Dry)\n\nAnswer:\n\n","completion":" Sauvignon Blanc "}
+{"prompt":"Question: (White, None)\n\nAnswer:\n\n","completion":" Sweet Gewurztraminer "}
+{"prompt":"Question: (Red-Earthy, None)\n\nAnswer:\n\n","completion":" Chianti "}
+{"prompt":"Question: (White-Creamy, Sweet)\n\nAnswer:\n\n","completion":" Chardonnay "}
+{"prompt":"Question: (Red-Rich, Full-Bodied)\n\nAnswer:\n\n","completion":" Cabernet Sauvignon "}
+{"prompt":"Question: (Red, Light-Bodied)\n\nAnswer:\n\n","completion":" Pinot Noir "}
+{"prompt":"Question: (Red-Spicy, Light-Bodied)\n\nAnswer:\n\n","completion":" Shiraz or Zinfandel "}
+{"prompt":"Question: (Red, None)\n\nAnswer:\n\n","completion":" Pinot Noir "}
+{"prompt":"Question: (Red, None)\n\nAnswer:\n\n","completion":" Chianti "}
+{"prompt":"Question: (White, None)\n\nAnswer:\n\n","completion":" Sauvignon Blanc "}
+{"prompt":"Question: (White, None)\n\nAnswer:\n\n","completion":" Chardonnay "}
+{"prompt":"Question: (Red, None)\n\nAnswer:\n\n","completion":" Shiraz or Zinfandel "}
+{"prompt":"Question: (Red, None)\n\nAnswer:\n\n","completion":" Cabernet Sauvignon "}
+{"prompt":"Question: (White-Floral, Sweet)\n\nAnswer:\n\n","completion":" Gewurztraminer "}
+{"prompt":"Question: (White-Citrus, Sweet)\n\nAnswer:\n\n","completion":" Riesling "}
+{"prompt":"Question: (Red-Earthy, Light-Bodied)\n\nAnswer:\n\n","completion":" Pinot Noir "}
+{"prompt":"Question: (Red-Rich, Light-Bodied)\n\nAnswer:\n\n","completion":" Cabernet Sauvignon "}
+{"prompt":"Question: (White-Crisp, Sweet)\n\nAnswer:\n\n","completion":" Pinot Noir "}
diff --git a/qa_sample_prepared.jsonl b/qa_sample_prepared.jsonl
new file mode 100644
index 0000000..75d5edc
--- /dev/null
+++ b/qa_sample_prepared.jsonl
@@ -0,0 +1,20 @@
+{"prompt":"Question: \n\nAnswer:\n\n\n\n###\n\n","completion":" END\n"}
+{"prompt":"Question: (Red-Fruity, Full-Bodied)\n\n###\n\n","completion":" Shiraz or Zinfandel \n"}
+{"prompt":"Question: (White-Crisp, Dry)\n\n###\n\n","completion":" Sauvignon Blanc \n"}
+{"prompt":"Question: (White, None)\n\n###\n\n","completion":" Sweet Gewurztraminer \n"}
+{"prompt":"Question: (Red-Earthy, None)\n\n###\n\n","completion":" Chianti \n"}
+{"prompt":"Question: (White-Creamy, Sweet)\n\n###\n\n","completion":" Chardonnay \n"}
+{"prompt":"Question: (Red-Rich, Full-Bodied)\n\n###\n\n","completion":" Cabernet Sauvignon \n"}
+{"prompt":"Question: (Red, Light-Bodied)\n\n###\n\n","completion":" Pinot Noir \n"}
+{"prompt":"Question: (Red-Spicy, Light-Bodied)\n\n###\n\n","completion":" Shiraz or Zinfandel \n"}
+{"prompt":"Question: (Red, None)\n\n###\n\n","completion":" Pinot Noir \n"}
+{"prompt":"Question: (Red, None)\n\n###\n\n","completion":" Chianti \n"}
+{"prompt":"Question: (White, None)\n\n###\n\n","completion":" Sauvignon Blanc \n"}
+{"prompt":"Question: (White, None)\n\n###\n\n","completion":" Chardonnay \n"}
+{"prompt":"Question: (Red, None)\n\n###\n\n","completion":" Shiraz or Zinfandel \n"}
+{"prompt":"Question: (Red, None)\n\n###\n\n","completion":" Cabernet Sauvignon \n"}
+{"prompt":"Question: (White-Floral, Sweet)\n\n###\n\n","completion":" Gewurztraminer \n"}
+{"prompt":"Question: (White-Citrus, Sweet)\n\n###\n\n","completion":" Riesling \n"}
+{"prompt":"Question: (Red-Earthy, Light-Bodied)\n\n###\n\n","completion":" Pinot Noir \n"}
+{"prompt":"Question: (Red-Rich, Light-Bodied)\n\n###\n\n","completion":" Cabernet Sauvignon \n"}
+{"prompt":"Question: (White-Crisp, Sweet)\n\n###\n\n","completion":" Pinot Noir \n"}