diff --git a/notebooks/codeio/PreprocessCode.ipynb b/notebooks/codeio/PreprocessCode.ipynb index 231aaf17..8b583d79 100644 --- a/notebooks/codeio/PreprocessCode.ipynb +++ b/notebooks/codeio/PreprocessCode.ipynb @@ -33,14 +33,13 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "prompt_template = \"\"\"\n", "You are tasked with preprocessing a raw file of Python code into a standard format. The format is made up of several components. Here is a very simple example of a raw code file:\n", "\n", - "```python\n", "def kg_to_pounds(weights):\n", " return [w * 2.20462 for w in weights]\n", "\n", @@ -52,7 +51,6 @@ "\n", " for measurement in filter_weekly(lbs, days):\n", " print(measurement)\n", - "```\n", "\n", "1. Cleaned reference code, with a main entrypoint function that takes all required arguments as parameters and returns all outputs.\n", "\n", @@ -70,7 +68,6 @@ "\n", "Example description:\n", "\n", - "```plaintext\n", "Input:\n", " weights_kg (list of int): List of weight values in kilograms.\n", " days (list of int): List of integers representing the number of days passed, starting from zero.\n", @@ -78,7 +75,6 @@ "Output:\n", " return (dict): A dictionary with one key:\n", " - weights_lb (list of int): List of filtered weight values in pounds.\n", - "```\n", "\n", "4. Python 3.11 code for an input generator, which randomly generates valid sets of inputs for the functions.\n", "\n", @@ -86,24 +82,22 @@ "\n", "Example input generator:\n", "\n", - "```python\n", "def input_generator():\n", " weights = [np.random.uniform(0, 100) for _ in range(40)]\n", " days = list(range(40))\n", " return {{\"weights_kg\": weights, \"days\": days}}\n", - "```\n", "\n", "Using the guidelines and example above, preprocess the following raw code file into the standard format:\n", "\n", "{0}\n", "\n", - "Output the components (reference code, query, description, input generator) in order. Separate each component with a triple newline (\\n\\n\\n).\n", + "Output the components (reference code, query, description, input generator) in order. Separate each component with a triple newline (\\n\\n\\n). Avoid code blocks and do not output any Markdown formatting.\n", "\"\"\"" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -145,21 +139,18 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "### Reference Code\n", - "```python\n", - "def main(word1: str, word2: str) -> dict:\n", - " m, n = len(word1), len(word2)\n", - " dp = [[0] * (n + 1) for _ in range(m + 1)]\n", - "\n", - " for i in range(m + 1):\n", - " for j in range(n + 1):\n", + "def main(word1, word2):\n", + " dp = [[0 for _ in range(len(word2) + 1)] for _ in range(len(word1) + 1)]\n", + " \n", + " for i in range(len(word1) + 1):\n", + " for j in range(len(word2) + 1):\n", " if i == 0:\n", " dp[i][j] = j\n", " elif j == 0:\n", @@ -171,39 +162,29 @@ " delete = dp[i - 1][j]\n", " replace = dp[i - 1][j - 1]\n", " dp[i][j] = 1 + min(insert, delete, replace)\n", + " \n", + " return {\"minimum_edit_distance\": dp[len(word1)][len(word2)]}\n", "\n", - " return {\"min_edit_distance\": dp[m][n]}\n", - "```\n", "\n", - "### Query\n", - "You are given two strings, `word1` and `word2`. Your task is to calculate the minimum number of operations required to transform `word1` into `word2`. The permitted operations are insertion, deletion, and substitution of a single character. Return the minimum number of operations needed.\n", + "You are given two strings, `word1` and `word2`. Your task is to find the minimum number of operations required to transform `word1` into `word2`. The permitted operations are insertion, deletion, and substitution of a single character. Return the minimum number of operations as an integer.\n", + "\n", "\n", - "### Description\n", - "```plaintext\n", "Input:\n", " word1 (str): The first string.\n", " word2 (str): The second string.\n", "\n", "Output:\n", " return (dict): A dictionary with one key:\n", - " - min_edit_distance (int): The minimum number of operations required to transform `word1` into `word2`.\n", - "```\n", + " - minimum_edit_distance (int): The minimum number of operations required to transform `word1` into `word2`.\n", "\n", - "### Input Generator\n", - "```python\n", - "import random\n", - "import string\n", "\n", "def input_generator():\n", - " def random_string(length):\n", - " letters = string.ascii_lowercase\n", - " return ''.join(random.choice(letters) for _ in range(length))\n", - "\n", - " word1 = random_string(random.randint(5, 15))\n", - " word2 = random_string(random.randint(5, 15))\n", + " import random\n", + " import string\n", " \n", - " return {\"word1\": word1, \"word2\": word2}\n", - "```\n" + " word1 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 10)))\n", + " word2 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 10)))\n", + " return {\"word1\": word1, \"word2\": word2}\n" ] } ],