Skip to content

Instantly share code, notes, and snippets.

@brockmanmatt
Last active July 25, 2020 00:02
Show Gist options
  • Save brockmanmatt/75ed62f09dbba796150e5335d30e4b19 to your computer and use it in GitHub Desktop.
Save brockmanmatt/75ed62f09dbba796150e5335d30e4b19 to your computer and use it in GitHub Desktop.
removeCursing.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "removeCursing.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyNmrwJihSl7BEyL/TzqY1JV",
"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/75ed62f09dbba796150e5335d30e4b19/removecursing.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "J7wnsgT2kPut",
"colab_type": "code",
"colab": {
"resources": {
"http://localhost:8080/nbextensions/google.colab/files.js": {
"data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXQKLy8KLy8gICAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjAKLy8KLy8gVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5n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hpbGUgKHBvc2l0aW9uIDwgZmlsZURhdGEuYnl0ZUxlbmd0aCkgewogICAgICBjb25zdCBsZW5ndGggPSBNYXRoLm1pbihmaWxlRGF0YS5ieXRlTGVuZ3RoIC0gcG9zaXRpb24sIE1BWF9QQVlMT0FEX1NJWkUpOwogICAgICBjb25zdCBjaHVuayA9IG5ldyBVaW50OEFycmF5KGZpbGVEYXRhLCBwb3NpdGlvbiwgbGVuZ3RoKTsKICAgICAgcG9zaXRpb24gKz0gbGVuZ3RoOwoKICAgICAgY29uc3QgYmFzZTY0ID0gYnRvYShTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIGNodW5rKSk7CiAgICAgIHlpZWxkIHsKICAgICAgICByZXNwb25zZTogewogICAgICAgICAgYWN0aW9uOiAnYXBwZW5kJywKICAgICAgICAgIGZpbGU6IGZpbGUubmFtZSwKICAgICAgICAgIGRhdGE6IGJhc2U2NCwKICAgICAgICB9LAogICAgICB9OwogICAgICBwZXJjZW50LnRleHRDb250ZW50ID0KICAgICAgICAgIGAke01hdGgucm91bmQoKHBvc2l0aW9uIC8gZmlsZURhdGEuYnl0ZUxlbmd0aCkgKiAxMDApfSUgZG9uZWA7CiAgICB9CiAgfQoKICAvLyBBbGwgZG9uZS4KICB5aWVsZCB7CiAgICByZXNwb25zZTogewogICAgICBhY3Rpb246ICdjb21wbGV0ZScsCiAgICB9CiAgfTsKfQoKc2NvcGUuZ29vZ2xlID0gc2NvcGUuZ29vZ2xlIHx8IHt9OwpzY29wZS5nb29nbGUuY29sYWIgPSBzY29wZS5nb29nbGUuY29sYWIgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYi5fZmlsZXMgPSB7CiAgX3VwbG9hZEZpbGVzLAogIF91cGxvYWRGaWxlc0NvbnRpbnVlLAp9Owp9KShzZWxmKTsK",
"ok": true,
"headers": [
[
"content-type",
"application/javascript"
]
],
"status": 200,
"status_text": ""
}
},
"base_uri": "https://localhost:8080/",
"height": 89
},
"outputId": "627f95eb-300b-40c9-e3ac-270d61857c93"
},
"source": [
"from google.colab import files\n",
"uploaded = files.upload()\n",
"print(\"done\")"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"\n",
" <input type=\"file\" id=\"files-ad85419f-e2d0-404d-bf86-611cc78e89ba\" name=\"files[]\" multiple disabled\n",
" style=\"border:none\" />\n",
" <output id=\"result-ad85419f-e2d0-404d-bf86-611cc78e89ba\">\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": "828c9774-9b05-4d63-89e8-5a903289ccbc"
},
"source": [
"!pip install openai\n",
"import openai, json, pandas as pd"
],
"execution_count": null,
"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 16.3MB/s eta 0:00:01\r\u001b[K |████▏ | 20kB 1.7MB/s eta 0:00:01\r\u001b[K |██████▎ | 30kB 2.3MB/s eta 0:00:01\r\u001b[K |████████▍ | 40kB 2.6MB/s eta 0:00:01\r\u001b[K |██████████▍ | 51kB 2.0MB/s eta 0:00:01\r\u001b[K |████████████▌ | 61kB 2.3MB/s eta 0:00:01\r\u001b[K |██████████████▋ | 71kB 2.5MB/s eta 0:00:01\r\u001b[K |████████████████▊ | 81kB 2.7MB/s eta 0:00:01\r\u001b[K |██████████████████▊ | 92kB 2.9MB/s eta 0:00:01\r\u001b[K |████████████████████▉ | 102kB 2.8MB/s eta 0:00:01\r\u001b[K |███████████████████████ | 112kB 2.8MB/s eta 0:00:01\r\u001b[K |█████████████████████████ | 122kB 2.8MB/s eta 0:00:01\r\u001b[K |███████████████████████████ | 133kB 2.8MB/s eta 0:00:01\r\u001b[K |█████████████████████████████▏ | 143kB 2.8MB/s eta 0:00:01\r\u001b[K |███████████████████████████████▎| 153kB 2.8MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 163kB 2.8MB/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: 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",
"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",
"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=5e6ff550fec070e80f5abeed8d28fbca4ce568ee29f31de49d2568980a6e4d00\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": 38,
"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": 39,
"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": 40,
"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": "7641cf34-d6be-40d6-9118-bb1ac558306e"
},
"source": [
"newKwargs = kwargs.copy()\n",
"newKwargs[\"stop\"] = \"\\n\"\n",
"query(\"q: what is 1+1?\\na:\", newKwargs)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'2'"
]
},
"metadata": {
"tags": []
},
"execution_count": 21
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "GRpmr0R9_FV6",
"colab_type": "code",
"colab": {}
},
"source": [
"prompt=\"\"\"Non-standard English: What the fuck is this?\n",
"Standard American English: What the **** is this?\n",
"\n",
"Non-standard English: This is bullshit.\n",
"Standard American English: This is ********.\n",
"\n",
"Non-standard English: Tis is kind of wierd.\n",
"Standard American English: This is kind of wierd.\n",
"\n",
"\n",
"Non-standard English: You are an asshole.\n",
"Standard American English: You are a ********.\n",
"\n",
"Non-standard English:Waht is happening?\n",
"Standard American English:\"\"\""
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "kzP2iII-_e6K",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "8afd9763-49c3-4bc6-e8f8-cbeb217a817f"
},
"source": [
"query(prompt)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What is happening?'"
]
},
"metadata": {
"tags": []
},
"execution_count": 9
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jzqUYZcXBZ71",
"colab_type": "text"
},
"source": [
"Using string formating to make it easier to test that prompt"
]
},
{
"cell_type": "code",
"metadata": {
"id": "V9PV0xRQ_gBL",
"colab_type": "code",
"colab": {}
},
"source": [
"prompt=\"\"\"Non-standard English: What the fuck is this?\n",
"Standard American English: What the **** is this?\n",
"\n",
"Non-standard English: This bullshit is bullshit.\n",
"Standard American English: This ******* is ********.\n",
"\n",
"Non-standard English: Tis is kind of wierd.\n",
"Standard American English: This is kind of wierd.\n",
"\n",
"Non-standard English: You are an asshole?\n",
"Standard American English: You are a ********?\n",
"\n",
"Non-standard English:{}\n",
"Standard American English:\"\"\""
],
"execution_count": 41,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "5Sf87qFNBdk_",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "d52e4fcc-1c72-45aa-b767-fb129b2c92e1"
},
"source": [
"query(prompt.format(\"Waht is happening?\"))"
],
"execution_count": 42,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What is happening?'"
]
},
"metadata": {
"tags": []
},
"execution_count": 42
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "YydIFHELBkYk",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "188aa51c-71d1-47ec-ea84-c1e806ae246a"
},
"source": [
"query(prompt.format(\"this is bullshit\"))"
],
"execution_count": 43,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'this is ********'"
]
},
"metadata": {
"tags": []
},
"execution_count": 43
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "T7Q_Wt6UBl1n",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "2fd69a10-1a71-4f85-8ea1-332d98a5b50d"
},
"source": [
"query(prompt.format(\"this is bullshit?\"))"
],
"execution_count": 44,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'This is ********?'"
]
},
"metadata": {
"tags": []
},
"execution_count": 44
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "0j8rHj8WBrO-",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "f86aaef4-513e-4008-d2be-5aa7182c8add"
},
"source": [
"query(prompt.format(\"what an asshole?\"))"
],
"execution_count": 45,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What a ********?'"
]
},
"metadata": {
"tags": []
},
"execution_count": 45
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "w4oRKirhBtg8",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "70eeabce-e784-43fd-ffd5-378fed746083"
},
"source": [
"query(prompt.format(\"what an asshole\"))"
],
"execution_count": 46,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'what a ********'"
]
},
"metadata": {
"tags": []
},
"execution_count": 46
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "Mz79Awq1B2Tc",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "374fbbaf-42ce-4736-9406-4f10bd843c95"
},
"source": [
"query(prompt.format(\"what an asshole she said dickishly\"))"
],
"execution_count": 47,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What an asshole she said ********ishly.'"
]
},
"metadata": {
"tags": []
},
"execution_count": 47
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "ffcefsD0B42X",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "cc8f81f1-3000-469a-a44e-32f4c6a1f9d1"
},
"source": [
"query(prompt.format(\"what an fucking asshole she said dickishly\"))"
],
"execution_count": 48,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What an ******** she said ********.'"
]
},
"metadata": {
"tags": []
},
"execution_count": 48
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "QGthK2nYCCJd",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "396f4d9b-e0a5-4afc-c36e-20bb26efa6a0"
},
"source": [
"query(prompt.format(\"what an fucking dumbass she said dickishly\"))"
],
"execution_count": 49,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What an ******* she said ********.'"
]
},
"metadata": {
"tags": []
},
"execution_count": 49
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "HOA9OJ9qCDvs",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "27799635-95cc-4d94-a2ac-622b3710d65c"
},
"source": [
"query(prompt.format(\"what a dumbass she said dickishly\"))"
],
"execution_count": 50,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What a dumbass she said ********ishly.'"
]
},
"metadata": {
"tags": []
},
"execution_count": 50
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pCA40D7eEJpt",
"colab_type": "text"
},
"source": [
"What if I give instructions?"
]
},
{
"cell_type": "code",
"metadata": {
"id": "mmu0Ltn4CFPQ",
"colab_type": "code",
"colab": {}
},
"source": [
"prompt=\"\"\"I starred out all the cursing\n",
"Non-standard English: What the fuck is this?\n",
"Standard American English: What the **** is this?\n",
"\n",
"Non-standard English: This bullshit is bullshit.\n",
"Standard American English: This ******* is ********.\n",
"\n",
"Non-standard English: Tis is kind of wierd.\n",
"Standard American English: This is kind of wierd.\n",
"\n",
"Non-standard English: You are an asshole?\n",
"Standard American English: You are a ********?\n",
"\n",
"Non-standard English:{}\n",
"Standard American English:\"\"\""
],
"execution_count": 66,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "0HN0tmwuEGtv",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "34717b03-d8b0-4067-e102-adb26424613b"
},
"source": [
"query(prompt.format(\"what an asshole she said dickishly\"))"
],
"execution_count": 67,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'what an asshole she said ********ishly'"
]
},
"metadata": {
"tags": []
},
"execution_count": 67
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "tnz5wMbPEGt1",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "0c26b5df-889c-43d2-adc5-0531c33e9f58"
},
"source": [
"query(prompt.format(\"what an fucking asshole she said dickishly\"))"
],
"execution_count": 68,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What an ******** she said ********.'"
]
},
"metadata": {
"tags": []
},
"execution_count": 68
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "ysEh5U0gEGt4",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "d0702aff-6e51-4c0a-855d-0b3bfa58b79b"
},
"source": [
"query(prompt.format(\"what an fucking dumbass she said dickishly\"))"
],
"execution_count": 69,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'What an ******* dumbass she said ********ishly.'"
]
},
"metadata": {
"tags": []
},
"execution_count": 69
}
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "StjfcEWBEGt7",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "033956af-300a-4fd4-be8b-837c97707b27"
},
"source": [
"query(prompt.format(\"what a dumbass she said dickishly\"))"
],
"execution_count": 70,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'what a dumbass she said ********ishly'"
]
},
"metadata": {
"tags": []
},
"execution_count": 70
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_2I6H2CGEMzk",
"colab_type": "text"
},
"source": [
"nope, didn't fix it."
]
},
{
"cell_type": "code",
"metadata": {
"id": "Tbc5rUK3EHOi",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 74,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "1oaL6IivEhNW",
"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