Last active
July 22, 2020 08:03
-
-
Save brockmanmatt/aea4fc4a962188f85d83db761bf0ac50 to your computer and use it in GitHub Desktop.
balance_parens.ipynb
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": "balance_parens.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyOzBno/2ixz6BLO0170msVS", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/brockmanmatt/aea4fc4a962188f85d83db761bf0ac50/balance_parens.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Rih86XVVkoqf", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Notebook: GPT bad at parentheses by themselves without additional tweaking/priming\n", | |
"\n", | |
"## However, it can fix f(f(x)) type stuff" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "J7wnsgT2kPut", | |
"colab_type": "code", | |
"colab": { | |
"resources": { | |
"http://localhost:8080/nbextensions/google.colab/files.js": { | |
"data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb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ogICAgICByZXNwb25zZTogewogICAgICAgIGFjdGlvbjogJ2NvbnRpbnVlJywKICAgICAgfQogICAgfTsKCiAgICAvLyBVc2UgYSBjaHVua2VkIHNlbmRpbmcgdG8gYXZvaWQgbWVzc2FnZSBzaXplIGxpbWl0cy4gU2VlIGIvNjIxMTU2NjAuCiAgICBsZXQgcG9zaXRpb24gPSAwOwogICAgd2hpbGUgKHBvc2l0aW9uIDwgZmlsZURhdGEuYnl0ZUxlbmd0aCkgewogICAgICBjb25zdCBsZW5ndGggPSBNYXRoLm1pbihmaWxlRGF0YS5ieXRlTGVuZ3RoIC0gcG9zaXRpb24sIE1BWF9QQVlMT0FEX1NJWkUpOwogICAgICBjb25zdCBjaHVuayA9IG5ldyBVaW50OEFycmF5KGZpbGVEYXRhLCBwb3NpdGlvbiwgbGVuZ3RoKTsKICAgICAgcG9zaXRpb24gKz0gbGVuZ3RoOwoKICAgICAgY29uc3QgYmFzZTY0ID0gYnRvYShTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIGNodW5rKSk7CiAgICAgIHlpZWxkIHsKICAgICAgICByZXNwb25zZTogewogICAgICAgICAgYWN0aW9uOiAnYXBwZW5kJywKICAgICAgICAgIGZpbGU6IGZpbGUubmFtZSwKICAgICAgICAgIGRhdGE6IGJhc2U2NCwKICAgICAgICB9LAogICAgICB9OwogICAgICBwZXJjZW50LnRleHRDb250ZW50ID0KICAgICAgICAgIGAke01hdGgucm91bmQoKHBvc2l0aW9uIC8gZmlsZURhdGEuYnl0ZUxlbmd0aCkgKiAxMDApfSUgZG9uZWA7CiAgICB9CiAgfQoKICAvLyBBbGwgZG9uZS4KICB5aWVsZCB7CiAgICByZXNwb25zZTogewogICAgICBhY3Rpb246ICdjb21wbGV0ZScsCiAgICB9CiAgfTsKfQoKc2NvcGUuZ29vZ2xlID0gc2NvcGUuZ29vZ2xlIHx8IHt9OwpzY29wZS5nb29nbGUuY29sYWIgPSBzY29wZS5nb29nbGUuY29sYWIgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYi5fZmlsZXMgPSB7CiAgX3VwbG9hZEZpbGVzLAogIF91cGxvYWRGaWxlc0NvbnRpbnVlLAp9Owp9KShzZWxmKTsK", | |
"ok": true, | |
"headers": [ | |
[ | |
"content-type", | |
"application/javascript" | |
] | |
], | |
"status": 200, | |
"status_text": "" | |
} | |
}, | |
"base_uri": "https://localhost:8080/", | |
"height": 89 | |
}, | |
"outputId": "aa3509ef-7828-44c4-ba5b-2ca9d6012cd9" | |
}, | |
"source": [ | |
"from google.colab import files\n", | |
"uploaded = files.upload()\n", | |
"print(\"done\")" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/html": [ | |
"\n", | |
" <input type=\"file\" id=\"files-9542d2d3-32a0-4ba5-950e-f8caf6c3d2f7\" name=\"files[]\" multiple disabled\n", | |
" style=\"border:none\" />\n", | |
" <output id=\"result-9542d2d3-32a0-4ba5-950e-f8caf6c3d2f7\">\n", | |
" Upload widget is only available when the cell has been executed in the\n", | |
" current browser session. Please rerun this cell to enable.\n", | |
" </output>\n", | |
" <script src=\"/nbextensions/google.colab/files.js\"></script> " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Saving key.json to key.json\n", | |
"done\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "WHPHrUnhpKnI", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"I'll install the API" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "zq0ltp2xn4yt", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 292 | |
}, | |
"outputId": "e96b614e-da02-4fa9-fa0a-08657d7b321b" | |
}, | |
"source": [ | |
"!pip install openai\n", | |
"import openai, json, pandas as pd" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Collecting openai\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/a8/65/c7461f4c87984534683f480ea5742777bc39bbf5721123194c2d0347dc1f/openai-0.2.4.tar.gz (157kB)\n", | |
"\r\u001b[K |██ | 10kB 13.8MB/s eta 0:00:01\r\u001b[K |████▏ | 20kB 2.9MB/s eta 0:00:01\r\u001b[K |██████▎ | 30kB 3.5MB/s eta 0:00:01\r\u001b[K |████████▍ | 40kB 4.0MB/s eta 0:00:01\r\u001b[K |██████████▍ | 51kB 3.3MB/s eta 0:00:01\r\u001b[K |████████████▌ | 61kB 3.6MB/s eta 0:00:01\r\u001b[K |██████████████▋ | 71kB 3.6MB/s eta 0:00:01\r\u001b[K |████████████████▊ | 81kB 4.0MB/s eta 0:00:01\r\u001b[K |██████████████████▊ | 92kB 4.4MB/s eta 0:00:01\r\u001b[K |████████████████████▉ | 102kB 4.5MB/s eta 0:00:01\r\u001b[K |███████████████████████ | 112kB 4.5MB/s eta 0:00:01\r\u001b[K |█████████████████████████ | 122kB 4.5MB/s eta 0:00:01\r\u001b[K |███████████████████████████ | 133kB 4.5MB/s eta 0:00:01\r\u001b[K |█████████████████████████████▏ | 143kB 4.5MB/s eta 0:00:01\r\u001b[K |███████████████████████████████▎| 153kB 4.5MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 163kB 4.5MB/s \n", | |
"\u001b[?25hRequirement already satisfied: requests>=2.20 in /usr/local/lib/python3.6/dist-packages (from openai) (2.23.0)\n", | |
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (2.10)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (2020.6.20)\n", | |
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (3.0.4)\n", | |
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (1.24.3)\n", | |
"Building wheels for collected packages: openai\n", | |
" Building wheel for openai (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for openai: filename=openai-0.2.4-cp36-none-any.whl size=170709 sha256=d1b35bdeae855b8cdf8a811f5d80d659a3a8e38f12c11be20c1b2398d0e028c5\n", | |
" Stored in directory: /root/.cache/pip/wheels/74/96/c8/c6e170929c276b836613e1b9985343b501fe455e53d85e7d48\n", | |
"Successfully built openai\n", | |
"Installing collected packages: openai\n", | |
"Successfully installed openai-0.2.4\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Q2yE0jcnpMEV", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Loading in key.json that I uploaded; I do this so I don't need to worry about accidently leaking creds if I share the colab (which I'm 99% sure is just a json file that won't expose them)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "bwNXXwHen5x9", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"openai.api_key = json.load(open(\"key.json\", \"r\"))[\"key\"]" | |
], | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "k67w5H0fpTkT", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Default keyword arguments to pass the aPI" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "e1EwpqqJkTYh", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#arguments to send the API\n", | |
"kwargs = {\n", | |
"\"engine\":\"davinci\",\n", | |
"\"temperature\":0,\n", | |
"\"max_tokens\":150,\n", | |
"\"stop\":\"\\n\\n\",\n", | |
"}" | |
], | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "zZubgPoOpWDH", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Quick wrapper to automatically save prompts and responses sent for later analysis if needed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "sXTDJx0An9Bl", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import datetime\n", | |
"def query(prompt, myKwargs = kwargs):\n", | |
" \"\"\"\n", | |
" wrapper for the API to save the prompt and the result\n", | |
" \"\"\"\n", | |
"\n", | |
" r = openai.Completion.create(prompt=prompt, **myKwargs)[\"choices\"][0][\"text\"].strip()\n", | |
" with open(\"{}.json\".format(datetime.datetime.now().strftime(\"%Y%m%d%s\")), \"w\") as fh:\n", | |
" json.dump({\"prompt\":prompt, \"response\":r}, fh, indent=4)\n", | |
" return r" | |
], | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "EdFXafcJpZ3Q", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Test to make sure my query works" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "4SlyKgjyopPn", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "1a32dc96-ed83-46e6-db15-d950b6e99132" | |
}, | |
"source": [ | |
"newKwargs = kwargs.copy()\n", | |
"newKwargs[\"stop\"] = \"\\n\"\n", | |
"query(\"q: what is 1+1?\\na:\", newKwargs)" | |
], | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'2'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 6 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "P4S7CFEqh818", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"prompt = \"\"\"q: is () balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is (() balanced or unbalanced\n", | |
"a: unbalanced\n", | |
"\n", | |
"q: is (()) balanced or unbalanced\n", | |
"a:\"\"\"" | |
], | |
"execution_count": 7, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "9LFUKZtGiMhn", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "d5749c52-2cba-44d6-e072-f51ce964e922" | |
}, | |
"source": [ | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'unbalanced'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 8 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "9M00Q2SGiPBd", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"prompt = \"\"\"A set of parentheses is balanced if it has a closing parenthese for each opening parenthese.\n", | |
"\n", | |
"q: is ) balanced or unbalanced\n", | |
"a: unbalanced; missing an opening parethese\n", | |
"\n", | |
"q: is () balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is (()) balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is (() balanced or unbalanced\n", | |
"a: unbalanced; it has an unclosed parethese\n", | |
"\n", | |
"q: is (()) balanced or unbalanced\n", | |
"a:\"\"\"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "tBAOgCnvifor", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "05850ea5-66a6-42f6-85de-1e5d224706cd" | |
}, | |
"source": [ | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'unbalanced; it has an unclosed parethese'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 14 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "vby_QThzigR1", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "2116c71a-cfc2-4d48-f2ca-994fcf69ff8b" | |
}, | |
"source": [ | |
"prompt = \"\"\"A set of parentheses is balanced if it has a closing parenthese for each opening parenthese.\n", | |
"\n", | |
"q: is ' ) ' balanced or unbalanced\n", | |
"a: unbalanced; missing an opening parethese\n", | |
"\n", | |
"q: is ' ( ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ' balanced or unbalanced\n", | |
"a: unbalanced; it has an unclosed parethese\n", | |
"\n", | |
"q: is ' ( ( ) ) ' balanced or unbalanced\n", | |
"a:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'balanced'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 15 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "7_7ahuZhi9Nf", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "28dd6524-16dc-4167-8cd7-a9ad6c02ea47" | |
}, | |
"source": [ | |
"prompt = \"\"\"A set of parentheses is balanced if it has a closing parenthese for each opening parenthese.\n", | |
"\n", | |
"q: is ' ) ' balanced or unbalanced\n", | |
"a: unbalanced; missing an opening parethese\n", | |
"\n", | |
"q: is ' ( ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ' balanced or unbalanced\n", | |
"a: unbalanced; it has an unclosed parethese\n", | |
"\n", | |
"q: is ' ( ( ( ) ) ' balanced or unbalanced\n", | |
"a:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'balanced'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 16 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "KV8_evEIjAYp", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "7f3280a5-fbb7-4e87-b6a5-1f57acc5f3e5" | |
}, | |
"source": [ | |
"prompt = \"\"\"A set of parentheses is balanced if it has a closing parenthese for each opening parenthese.\n", | |
"\n", | |
"q: is ' ) ' balanced or unbalanced\n", | |
"a: unbalanced; missing an opening parethese\n", | |
"\n", | |
"q: is ' ( ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ' balanced or unbalanced\n", | |
"a: unbalanced; it has an unclosed parethese\n", | |
"\n", | |
"q: is ' ( ( ( ) ) ) ' balanced or unbalanced\n", | |
"a:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'balanced'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 17 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "_o6tbASQjB-B", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "574968d9-8f39-432a-a856-10c0ffd8b7de" | |
}, | |
"source": [ | |
"prompt = \"\"\"A set of parentheses is balanced if it has a closing parenthese for each opening parenthese.\n", | |
"\n", | |
"q: is ' ( ( ) ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ' balanced or unbalanced\n", | |
"a: unbalanced; it has an unclosed parethese\n", | |
"\n", | |
"q: is ' ( ( ( ) ) ) ' balanced or unbalanced\n", | |
"a:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'balanced'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 18 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "BvpyqPORjFJR", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "969e12aa-20a5-4c6a-89f8-df35e5fc7bf6" | |
}, | |
"source": [ | |
"prompt = \"\"\"A set of parentheses is balanced if it has a closing parenthese for each opening parenthese.\n", | |
"\n", | |
"q: is ' ( ( ) ) ' balanced or unbalanced\n", | |
"a: balanced\n", | |
"\n", | |
"q: is ' ( ( ) ' balanced or unbalanced\n", | |
"a: unbalanced; it has an unclosed parethese\n", | |
"\n", | |
"q: is ' ( ( ( ) ) ' balanced or unbalanced\n", | |
"a:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'balanced'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 19 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "PU1ZJlNqjHMT", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "82e83f30-1394-4bf6-c781-23ca3f6c01d2" | |
}, | |
"source": [ | |
"prompt = \"\"\"balance the number of open and closed parentheses\n", | |
"\n", | |
"input: ' ( ( ) ) '\n", | |
"output: ' ( ( ) ) '\n", | |
"\n", | |
"input: ' ( ( ) '\n", | |
"output: ' ( ( ) ) '\n", | |
"\n", | |
"input: ' ( ( ( '\n", | |
"output:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"\"' ( ( ( ) ) '\"" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 20 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "god_6YuXjYtF", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "d3ffecdb-0a74-44be-b9b5-1d01818dbb5c" | |
}, | |
"source": [ | |
"prompt = \"\"\"fix the following:\n", | |
"\n", | |
"input: 'f(x) + f(y'\n", | |
"output: 'f(x) + f(y)'\n", | |
"\n", | |
"input: 'f(f(f(y)'\n", | |
"output: 'f(f(f(y)))'\n", | |
"\n", | |
"input: 'f(f(y'\n", | |
"output:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"\"'f(f(y))'\"" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 21 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "sCwkI6jMkWyt", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "e38bc3ee-a243-47d7-9e7c-163588b94883" | |
}, | |
"source": [ | |
"prompt = \"\"\"fix the following:\n", | |
"\n", | |
"input: 'f(x) + f(y'\n", | |
"output: 'f(x) + f(y)'\n", | |
"\n", | |
"input: 'f(f(f(y)'\n", | |
"output: 'f(f(f(y)))'\n", | |
"\n", | |
"input: 'f(f(f(f(y'\n", | |
"output:\"\"\"\n", | |
"query(prompt, newKwargs)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"\"'f(f(f(f(y)))'\"" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 22 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "kFEb6XPokZKM", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"tests = {}\n", | |
"for i in range(1,6):\n", | |
" tests[i]= {}\n", | |
" tests[i][\"inputs\"] = []\n", | |
" newParens = \" \"\n", | |
" for j in range(i):\n", | |
" newParens += \" ( \"\n", | |
" for j in range(i):\n", | |
" newParens += \" ) \"\n", | |
" tests[i][\"inputs\"].append(newParens + \" \")" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Rj9SvpCYlrIp", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 111 | |
}, | |
"outputId": "668e60c5-e790-44b8-a257-768892c2b4ce" | |
}, | |
"source": [ | |
"pd.DataFrame(tests[2])" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<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>inputs</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>( ( )</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>( ( ) )</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" inputs\n", | |
"0 ( ( ) \n", | |
"1 ( ( ) ) " | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 35 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "zA8aq5RupEu6", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Look, it just fails miserably on the parentheses" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "-Z6iyiX6lNtB", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 102 | |
}, | |
"outputId": "df34c835-2fcd-4faf-996c-5382e9a6595b" | |
}, | |
"source": [ | |
"prompt = \"\"\" Parentheses are balanced if there's a closing parenthese for each opening parenthese. Are following parentheses following balanced or unbalanced?\n", | |
"\n", | |
"input: ' ( ( ) ) '\n", | |
"output: balanced\n", | |
"\n", | |
"input: ' ( ( ) '\n", | |
"output: unbalanced\n", | |
"\n", | |
"input: ' ( ) ( ) ( ) '\n", | |
"output: balanced\n", | |
"\n", | |
"input: ' ( ) ) '\n", | |
"output: unbalanced\n", | |
"\n", | |
"input: ' ( ) ( ) ) '\n", | |
"output: unbalanced\n", | |
"\n", | |
"input: {}\n", | |
"output:\"\"\"\n", | |
"query(prompt, newKwargs)\n", | |
"\n", | |
"for i in range(1,6):\n", | |
" print(i)\n", | |
" tests[i][\"completions\"] = []\n", | |
" for j in tests[i][\"inputs\"]:\n", | |
" tests[i][\"completions\"].append(query(prompt.format(j), newKwargs))\n", | |
" " | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1\n", | |
"2\n", | |
"3\n", | |
"4\n", | |
"5\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Wnc-Mzl7n2Cb", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"def isBalanced(someParens):\n", | |
" \"\"\"\n", | |
" bad way to count balance but works for what I fed it\n", | |
" \"\"\"\n", | |
" a = someParens.count(\"(\")\n", | |
" b = someParens.count(\")\")\n", | |
" return a==b" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JS09qqaXnAy6", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 102 | |
}, | |
"outputId": "9514bdb4-7b2a-421a-9b94-c9249853e7ad" | |
}, | |
"source": [ | |
"for i in range(1,6):\n", | |
" print(i)\n", | |
" tests[i][\"actual\"] = []\n", | |
" for j in tests[i][\"inputs\"]:\n", | |
" tests[i][\"actual\"].append(isBalanced(j))" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1\n", | |
"2\n", | |
"3\n", | |
"4\n", | |
"5\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Q9ttnMKApC_h", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 142 | |
}, | |
"outputId": "a31b8d5b-a4eb-4bb5-aa7a-e4898dc874e7" | |
}, | |
"source": [ | |
"pd.DataFrame(tests[3])" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<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>inputs</th>\n", | |
" <th>completions</th>\n", | |
" <th>actual</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>( ( ( )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>( ( ( ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>( ( ( ) ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" inputs completions actual\n", | |
"0 ( ( ( ) balanced False\n", | |
"1 ( ( ( ) ) balanced False\n", | |
"2 ( ( ( ) ) ) balanced True" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 71 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "S8NJgd_0pBLi", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 173 | |
}, | |
"outputId": "60a0d02a-b46f-4eee-d4a7-906d335e2013" | |
}, | |
"source": [ | |
"pd.DataFrame(tests[4])" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<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>inputs</th>\n", | |
" <th>completions</th>\n", | |
" <th>actual</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>( ( ( ( )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>( ( ( ( ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>( ( ( ( ) ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>( ( ( ( ) ) ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" inputs completions actual\n", | |
"0 ( ( ( ( ) balanced False\n", | |
"1 ( ( ( ( ) ) balanced False\n", | |
"2 ( ( ( ( ) ) ) balanced False\n", | |
"3 ( ( ( ( ) ) ) ) balanced True" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 69 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "65pO0pPdlOtn", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 204 | |
}, | |
"outputId": "fb244334-307b-4e61-ff98-38c138b99e1b" | |
}, | |
"source": [ | |
"pd.DataFrame(tests[5])" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<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>inputs</th>\n", | |
" <th>completions</th>\n", | |
" <th>actual</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>( ( ( ( ( )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>( ( ( ( ( ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>( ( ( ( ( ) ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>( ( ( ( ( ) ) ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>False</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>( ( ( ( ( ) ) ) ) )</td>\n", | |
" <td>balanced</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" inputs completions actual\n", | |
"0 ( ( ( ( ( ) balanced False\n", | |
"1 ( ( ( ( ( ) ) balanced False\n", | |
"2 ( ( ( ( ( ) ) ) balanced False\n", | |
"3 ( ( ( ( ( ) ) ) ) balanced False\n", | |
"4 ( ( ( ( ( ) ) ) ) ) balanced True" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 70 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "as6Krrjrm54X", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"prompt = \"\"\"Fix the parentheses so there's a closed ) for every open (\n", | |
"Original: There isn't a good answer (I mean, who knows(right?)\n", | |
"Fixed: There isn't a good answer (I mean, who knows(right?))\n", | |
"\n", | |
"Original: Tim (my friend)) is really tired.\n", | |
"Fixed: Tim (my friend) is really tired.\n", | |
"\n", | |
"Original: {}\n", | |
"Fixed:\"\"\"" | |
], | |
"execution_count": 14, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "RyTEMWXAi922", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "4a2c8d7d-b550-4971-fd8a-b93accfadf58" | |
}, | |
"source": [ | |
"query(prompt.format(\"wait (test (this\"))" | |
], | |
"execution_count": 18, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'wait (test (this'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 18 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "lvSZA4gwiove", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "c3fc9a0c-847b-4dbc-c219-f59cb0625f1b" | |
}, | |
"source": [ | |
"query(prompt.format(\"wait (test (this)\"))" | |
], | |
"execution_count": 17, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'wait (test (this))'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 17 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "uZ1C1MakitZf", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment