{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "if \"workding_dir\" not in locals():\n", " try:\n", " from google.colab import drive\n", "\n", " drive.mount(\"/content/drive\")\n", " workding_dir = \"/content/drive/MyDrive/logical-reasoning/\"\n", " except ModuleNotFoundError:\n", " workding_dir = str(Path.cwd().parent)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "workding dir: /Users/inflaton/code/engd/projects/logical-reasoning\n" ] } ], "source": [ "import os\n", "import sys\n", "\n", "os.chdir(workding_dir)\n", "sys.path.append(workding_dir)\n", "print(\"workding dir:\", workding_dir)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "id": "l40Iu1qbZkMH" }, "outputs": [], "source": [ "from llm_toolkit.llm_utils import *" ] }, { "cell_type": "markdown", "metadata": { "id": "wN-vwM7_ZkMI" }, "source": [ "## Compare GPT-4o and o1-preview\n", "\n", "[LogiQA-dataset / Train.txt](https://raw.githubusercontent.com/lgw863/LogiQA-dataset/master/Train.txt)\n", "\n", "There are 4 cups on the table, each with a sentence written on it.The first cup: \"Beer is in all cups\".The second cup: \"Cola in this cup\".The third cup: \" No coffee in this cup \".Fourth cup:\" Some cups have no beer \".Only one of the 4 sentences is true.\n", "\n", "So which of the following is true?\n", "\n", "A.Beer is in all cups\n", "\n", "B.No cola in all cups\n", "\n", "C.Coffee in the third cup\n", "\n", "D.Cola in the second cup\n", "\n", "**Correct Answer:** C" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "tyW4CRnBZkMI", "outputId": "e6481d65-6710-4267-f6b6-4a0925ce2ba1" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 4 cups on the table, each with a sentence written on it.The first cup: \"Beer is in all cups\".The second cup: \"Cola in this cup\".The third cup: \" No coffee in this cup \".Fourth cup:\" Some cups have no beer \".Only one of the 4 sentences is true.\n", "So which of the following is true?\n", "A.Beer is in all cups\n", "B.No cola in all cups\n", "C.Coffee in the third cup\n", "D.Cola in the second cup\n" ] } ], "source": [ "prompt = \"\"\"There are 4 cups on the table, each with a sentence written on it.The first cup: \"Beer is in all cups\".The second cup: \"Cola in this cup\".The third cup: \" No coffee in this cup \".Fourth cup:\" Some cups have no beer \".Only one of the 4 sentences is true.\n", "So which of the following is true?\n", "A.Beer is in all cups\n", "B.No cola in all cups\n", "C.Coffee in the third cup\n", "D.Cola in the second cup\"\"\"\n", "\n", "print(prompt)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "xjQoOWHtZkMI", "outputId": "f4f085a6-0a93-498c-c615-86032ceff73d" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "We are given that there are four cups, each with a sentence, and only one of these sentences is true. We'll denote the sentences as follows:\n", "\n", "- S1 on Cup 1: \"Beer is in all cups.\"\n", "- S2 on Cup 2: \"Cola is in this cup.\"\n", "- S3 on Cup 3: \"No coffee in this cup.\"\n", "- S4 on Cup 4: \"Some cups have no beer.\"\n", "\n", "Our goal is to determine which of the options (A-D) must be true given that only one of S1-S4 is true.\n", "\n", "**Case 1: Assume S1 is true, and S2, S3, S4 are false.**\n", "\n", "- **S1 is true**: \"Beer is in all cups.\"\n", "- **S2 is false**: \"Cola is in this cup\" is false ⇒ Cup 2 does **not** have cola.\n", "- **S3 is false**: \"No coffee in this cup\" is false ⇒ Cup 3 **does** have coffee.\n", "- **S4 is false**: \"Some cups have no beer\" is false ⇒ All cups have beer (which aligns with S1 being true).\n", "\n", "**Case 2: Assume S4 is true, and S1, S2, S3 are false.**\n", "\n", "- **S4 is true**: \"Some cups have no beer.\"\n", "- **S1 is false**: \"Beer is in all cups\" is false ⇒ At least one cup does **not** have beer.\n", "- **S2 is false**: \"Cola is in this cup\" is false ⇒ Cup 2 does **not** have cola.\n", "- **S3 is false**: \"No coffee in this cup\" is false ⇒ Cup 3 **does** have coffee.\n", "\n", "**In both cases**, Cup 3 has coffee. Also, in both cases, we cannot conclude that \"No cola in all cups\" (Option B) is true because we have no information on cola in cups other than Cup 2. Option D (\"Cola in the second cup\") is false because we've determined Cup 2 does not have cola in both scenarios.\n", "\n", "Therefore, the only option that must be true, regardless of which sentence (S1 or S4) is true, is **Option C: Coffee in the third cup**.\n", "\n", "**Answer: C.Coffee in the third cup**\n", "CPU times: user 21.2 ms, sys: 2.31 ms, total: 23.5 ms\n", "Wall time: 47.3 s\n" ] } ], "source": [ "%%time\n", "\n", "o1_preview_answer = invoke_openai_api(prompt, model=\"o1-preview\", temperature=1)\n", "print(o1_preview_answer)" ] }, { "cell_type": "markdown", "metadata": { "id": "Z7XAd-XkZ1NU" }, "source": [ "**Answer by o1-preview:**\n", "\n", "We are given that there are four cups, each with a sentence, and only one of these sentences is true. We'll denote the sentences as follows:\n", "\n", "- S1 on Cup 1: \"Beer is in all cups.\"\n", "- S2 on Cup 2: \"Cola is in this cup.\"\n", "- S3 on Cup 3: \"No coffee in this cup.\"\n", "- S4 on Cup 4: \"Some cups have no beer.\"\n", "\n", "Our goal is to determine which of the options (A-D) must be true given that only one of S1-S4 is true.\n", "\n", "**Case 1: Assume S1 is true, and S2, S3, S4 are false.**\n", "\n", "- **S1 is true**: \"Beer is in all cups.\"\n", "- **S2 is false**: \"Cola is in this cup\" is false ⇒ Cup 2 does **not** have cola.\n", "- **S3 is false**: \"No coffee in this cup\" is false ⇒ Cup 3 **does** have coffee.\n", "- **S4 is false**: \"Some cups have no beer\" is false ⇒ All cups have beer (which aligns with S1 being true).\n", "\n", "**Case 2: Assume S4 is true, and S1, S2, S3 are false.**\n", "\n", "- **S4 is true**: \"Some cups have no beer.\"\n", "- **S1 is false**: \"Beer is in all cups\" is false ⇒ At least one cup does **not** have beer.\n", "- **S2 is false**: \"Cola is in this cup\" is false ⇒ Cup 2 does **not** have cola.\n", "- **S3 is false**: \"No coffee in this cup\" is false ⇒ Cup 3 **does** have coffee.\n", "\n", "**In both cases**, Cup 3 has coffee. Also, in both cases, we cannot conclude that \"No cola in all cups\" (Option B) is true because we have no information on cola in cups other than Cup 2. Option D (\"Cola in the second cup\") is false because we've determined Cup 2 does not have cola in both scenarios.\n", "\n", "Therefore, the only option that must be true, regardless of which sentence (S1 or S4) is true, is **Option C: Coffee in the third cup**.\n", "\n", "**Answer: C.Coffee in the third cup**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "yRw5u-QEZkMJ", "outputId": "17d72e5d-4a8a-4842-a183-cc46e0c81ba6" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Let's analyze the problem step by step to determine which of the options is true, given that only one of the four sentences on the cups is true.\n", "\n", "### **Cup Statements:**\n", "1. **Cup 1:** \"Beer is in all cups.\"\n", "2. **Cup 2:** \"Cola in this cup.\"\n", "3. **Cup 3:** \"No coffee in this cup.\"\n", "4. **Cup 4:** \"Some cups have no beer.\"\n", "\n", "### **Options:**\n", "A. Beer is in all cups \n", "B. No cola in all cups \n", "C. Coffee in the third cup \n", "D. Cola in the second cup\n", "\n", "### **Analysis:**\n", "\n", "1. **Assume Cup 1 is True (\"Beer is in all cups\"):**\n", " - **Cup 2:** \"Cola in this cup\" is **false** → No cola in Cup 2.\n", " - **Cup 3:** \"No coffee in this cup\" is **false** → Coffee **is** in Cup 3.\n", " - **Cup 4:** \"Some cups have no beer\" is **false** → All cups **do** have beer.\n", "\n", " **Implications:**\n", " - **Option A:** True.\n", " - **Option C:** True.\n", "\n", " **Issue:** Both A and C are true, which violates the condition that only one statement is true.\n", "\n", "2. **Assume Cup 4 is True (\"Some cups have no beer\"):**\n", " - **Cup 1:** \"Beer is in all cups\" is **false** → Not all cups have beer.\n", " - **Cup 2:** \"Cola in this cup\" is **false** → No cola in Cup 2.\n", " - **Cup 3:** \"No coffee in this cup\" is **false** → Coffee **is** in Cup 3.\n", "\n", " **Implications:**\n", " - **Option C:** True.\n", " - **Options A, B, D:** Either false or not necessarily true.\n", "\n", " **Conclusion:** Only **Option C** holds true without violating the condition.\n", "\n", "### **Final Answer:**\n", "\n", "**C. Coffee in the third cup**\n", "CPU times: user 20.4 ms, sys: 2.62 ms, total: 23.1 ms\n", "Wall time: 20.8 s\n" ] } ], "source": [ "%%time\n", "\n", "o1_mini_answer = invoke_openai_api(prompt, model=\"o1-mini\", temperature=1)\n", "print(o1_mini_answer)" ] }, { "cell_type": "markdown", "metadata": { "id": "241cVccaZ7LF" }, "source": [ "**Answer by o1-mini:**\n", "\n", "Let's analyze the problem step by step to determine which of the options is true, given that only one of the four sentences on the cups is true.\n", "\n", "### **Cup Statements:**\n", "1. **Cup 1:** \"Beer is in all cups.\"\n", "2. **Cup 2:** \"Cola in this cup.\"\n", "3. **Cup 3:** \"No coffee in this cup.\"\n", "4. **Cup 4:** \"Some cups have no beer.\"\n", "\n", "### **Options:**\n", "A. Beer is in all cups \n", "B. No cola in all cups \n", "C. Coffee in the third cup \n", "D. Cola in the second cup\n", "\n", "### **Analysis:**\n", "\n", "1. **Assume Cup 1 is True (\"Beer is in all cups\"):**\n", " - **Cup 2:** \"Cola in this cup\" is **false** → No cola in Cup 2.\n", " - **Cup 3:** \"No coffee in this cup\" is **false** → Coffee **is** in Cup 3.\n", " - **Cup 4:** \"Some cups have no beer\" is **false** → All cups **do** have beer.\n", "\n", " **Implications:**\n", " - **Option A:** True.\n", " - **Option C:** True.\n", "\n", " **Issue:** Both A and C are true, which violates the condition that only one statement is true.\n", "\n", "2. **Assume Cup 4 is True (\"Some cups have no beer\"):**\n", " - **Cup 1:** \"Beer is in all cups\" is **false** → Not all cups have beer.\n", " - **Cup 2:** \"Cola in this cup\" is **false** → No cola in Cup 2.\n", " - **Cup 3:** \"No coffee in this cup\" is **false** → Coffee **is** in Cup 3.\n", "\n", " **Implications:**\n", " - **Option C:** True.\n", " - **Options A, B, D:** Either false or not necessarily true.\n", "\n", " **Conclusion:** Only **Option C** holds true without violating the condition.\n", "\n", "### **Final Answer:**\n", "\n", "**C. Coffee in the third cup**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Tq0-6LjIZkMJ", "outputId": "75fb4ce6-54a5-44eb-8b01-654bd3eff2a9" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "To solve this puzzle, we need to determine which one of the four sentences is true, given that only one of them is true. Let's analyze each sentence and its implications:\n", "\n", "1. **First cup: \"Beer is in all cups\"**\n", " - If this sentence is true, then beer must be in all four cups.\n", " - This would make the fourth sentence (\"Some cups have no beer\") false, which is consistent with the condition that only one sentence is true.\n", " - However, if beer is in all cups, the second sentence (\"Cola in this cup\") would also be false, which is consistent.\n", " - The third sentence (\"No coffee in this cup\") would also be false, which is consistent.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "2. **Second cup: \"Cola in this cup\"**\n", " - If this sentence is true, then cola must be in the second cup.\n", " - This would make the first sentence (\"Beer is in all cups\") false, which is consistent.\n", " - The third sentence (\"No coffee in this cup\") would also be false, which means there is coffee in the third cup.\n", " - The fourth sentence (\"Some cups have no beer\") would also be false, which means all cups have beer.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "3. **Third cup: \"No coffee in this cup\"**\n", " - If this sentence is true, then there is no coffee in the third cup.\n", " - This would make the first sentence (\"Beer is in all cups\") false, which is consistent.\n", " - The second sentence (\"Cola in this cup\") would also be false, which means there is no cola in the second cup.\n", " - The fourth sentence (\"Some cups have no beer\") would also be false, which means all cups have beer.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "4. **Fourth cup: \"Some cups have no beer\"**\n", " - If this sentence is true, then at least one cup does not have beer.\n", " - This would make the first sentence (\"Beer is in all cups\") false, which is consistent.\n", " - The second sentence (\"Cola in this cup\") would also be false, which means there is no cola in the second cup.\n", " - The third sentence (\"No coffee in this cup\") would also be false, which means there is coffee in the third cup.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "Now, let's summarize the implications of each scenario:\n", "\n", "- If the first sentence is true, then beer is in all cups, and the other sentences are false.\n", "- If the second sentence is true, then cola is in the second cup, and the other sentences are false.\n", "- If the third sentence is true, then there is no coffee in the third cup, and the other sentences are false.\n", "- If the fourth sentence is true, then some cups have no beer, and the other sentences are false.\n", "\n", "Given that only one sentence is true, the scenario where the second sentence is true (Cola in the second cup) seems to be the most consistent with the condition that only one sentence is true. Therefore, the correct answer is:\n", "\n", "D. Cola in the second cup\n", "CPU times: user 18.1 ms, sys: 2.2 ms, total: 20.3 ms\n", "Wall time: 7.71 s\n" ] } ], "source": [ "%%time\n", "\n", "gpt_4o_answer = invoke_openai_api(prompt, model=\"gpt-4o\")\n", "print(gpt_4o_answer)" ] }, { "cell_type": "markdown", "metadata": { "id": "7zDghv7taRqC" }, "source": [ "**Answer by gpt-4o:**\n", "\n", "To solve this puzzle, we need to determine which one of the four sentences is true, given that only one of them is true. Let's analyze each sentence and its implications:\n", "\n", "1. **First cup: \"Beer is in all cups\"**\n", " - If this sentence is true, then beer must be in all four cups.\n", " - This would make the fourth sentence (\"Some cups have no beer\") false, which is consistent with the condition that only one sentence is true.\n", " - However, if beer is in all cups, the second sentence (\"Cola in this cup\") would also be false, which is consistent.\n", " - The third sentence (\"No coffee in this cup\") would also be false, which is consistent.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "2. **Second cup: \"Cola in this cup\"**\n", " - If this sentence is true, then cola must be in the second cup.\n", " - This would make the first sentence (\"Beer is in all cups\") false, which is consistent.\n", " - The third sentence (\"No coffee in this cup\") would also be false, which means there is coffee in the third cup.\n", " - The fourth sentence (\"Some cups have no beer\") would also be false, which means all cups have beer.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "3. **Third cup: \"No coffee in this cup\"**\n", " - If this sentence is true, then there is no coffee in the third cup.\n", " - This would make the first sentence (\"Beer is in all cups\") false, which is consistent.\n", " - The second sentence (\"Cola in this cup\") would also be false, which means there is no cola in the second cup.\n", " - The fourth sentence (\"Some cups have no beer\") would also be false, which means all cups have beer.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "4. **Fourth cup: \"Some cups have no beer\"**\n", " - If this sentence is true, then at least one cup does not have beer.\n", " - This would make the first sentence (\"Beer is in all cups\") false, which is consistent.\n", " - The second sentence (\"Cola in this cup\") would also be false, which means there is no cola in the second cup.\n", " - The third sentence (\"No coffee in this cup\") would also be false, which means there is coffee in the third cup.\n", " - This scenario seems possible, but let's check the other sentences to be sure.\n", "\n", "Now, let's summarize the implications of each scenario:\n", "\n", "- If the first sentence is true, then beer is in all cups, and the other sentences are false.\n", "- If the second sentence is true, then cola is in the second cup, and the other sentences are false.\n", "- If the third sentence is true, then there is no coffee in the third cup, and the other sentences are false.\n", "- If the fourth sentence is true, then some cups have no beer, and the other sentences are false.\n", "\n", "Given that only one sentence is true, the scenario where the second sentence is true (Cola in the second cup) seems to be the most consistent with the condition that only one sentence is true. Therefore, the correct answer is:\n", "\n", "D. Cola in the second cup" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "aDCNM8x3ZkMJ", "outputId": "360d4617-f173-4c77-dc5f-49333aeeae00" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "To solve this puzzle, we need to analyze the statements on the cups and determine which one is true, given that only one of the four sentences is true.\n", "\n", "1. **First cup: \"Beer is in all cups.\"**\n", " - If this statement is true, then all cups contain beer, which would make the fourth cup's statement (\"Some cups have no beer\") false. This would mean that more than one statement is true, which contradicts the condition that only one statement is true. Therefore, this statement cannot be true.\n", "\n", "2. **Second cup: \"Cola in this cup.\"**\n", " - If this statement is true, then the second cup contains cola. However, if the second cup has cola, it does not affect the truth of the other statements directly. We need to check the other statements to see if this can be the only true statement.\n", "\n", "3. **Third cup: \"No coffee in this cup.\"**\n", " - If this statement is true, then the third cup does not contain coffee. If this is true, it does not directly contradict any other statements, but we need to check the implications.\n", "\n", "4. **Fourth cup: \"Some cups have no beer.\"**\n", " - If this statement is true, then at least one cup does not contain beer. If this is true, it contradicts the first cup's statement (\"Beer is in all cups\"), which would mean that more than one statement is true. Therefore, this statement cannot be true.\n", "\n", "Now, let's analyze the implications of the second and third cups being true:\n", "\n", "- If the **second cup** is true (\"Cola in this cup\"), then:\n", " - The first cup is false (not all cups have beer).\n", " - The third cup could still be true or false.\n", " - The fourth cup could still be true or false.\n", "\n", "- If the **third cup** is true (\"No coffee in this cup\"), then:\n", " - The first cup is false (not all cups have beer).\n", " - The second cup could still be true or false.\n", " - The fourth cup could still be true or false.\n", "\n", "Since we need to find a scenario where only one statement is true, we can conclude:\n", "\n", "- If the second cup is true, then the first cup is false, and the fourth cup must also be false (which means all cups have beer, contradicting the second cup). This leads to a contradiction.\n", "- If the third cup is true, then the first cup is false, and the fourth cup must also be false (which means all cups have beer, contradicting the third cup). This leads to a contradiction.\n", "\n", "Thus, the only consistent scenario is that the **second cup** is true, which means:\n", "\n", "**B. No cola in all cups** is the only true statement. \n", "\n", "So, the answer is **B. No cola in all cups**.\n", "CPU times: user 23.5 ms, sys: 2.57 ms, total: 26.1 ms\n", "Wall time: 4.78 s\n" ] } ], "source": [ "%%time\n", "\n", "gpt_4o_mini_answer = invoke_openai_api(prompt, model=\"gpt-4o-mini\")\n", "print(gpt_4o_mini_answer)" ] }, { "cell_type": "markdown", "metadata": { "id": "o33uWumdaeFT" }, "source": [ "**Answer by gpt-4o-mini:**\n", "\n", "To solve this puzzle, we need to analyze the statements on the cups and determine which one is true, given that only one of the four sentences is true.\n", "\n", "1. **First cup: \"Beer is in all cups.\"**\n", " - If this statement is true, then all cups contain beer, which would make the fourth cup's statement (\"Some cups have no beer\") false. This would mean that more than one statement is true, which contradicts the condition that only one statement is true. Therefore, this statement cannot be true.\n", "\n", "2. **Second cup: \"Cola in this cup.\"**\n", " - If this statement is true, then the second cup contains cola. However, if the second cup has cola, it does not affect the truth of the other statements directly. We need to check the other statements to see if this can be the only true statement.\n", "\n", "3. **Third cup: \"No coffee in this cup.\"**\n", " - If this statement is true, then the third cup does not contain coffee. If this is true, it does not directly contradict any other statements, but we need to check the implications.\n", "\n", "4. **Fourth cup: \"Some cups have no beer.\"**\n", " - If this statement is true, then at least one cup does not contain beer. If this is true, it contradicts the first cup's statement (\"Beer is in all cups\"), which would mean that more than one statement is true. Therefore, this statement cannot be true.\n", "\n", "Now, let's analyze the implications of the second and third cups being true:\n", "\n", "- If the **second cup** is true (\"Cola in this cup\"), then:\n", " - The first cup is false (not all cups have beer).\n", " - The third cup could still be true or false.\n", " - The fourth cup could still be true or false.\n", "\n", "- If the **third cup** is true (\"No coffee in this cup\"), then:\n", " - The first cup is false (not all cups have beer).\n", " - The second cup could still be true or false.\n", " - The fourth cup could still be true or false.\n", "\n", "Since we need to find a scenario where only one statement is true, we can conclude:\n", "\n", "- If the second cup is true, then the first cup is false, and the fourth cup must also be false (which means all cups have beer, contradicting the second cup). This leads to a contradiction.\n", "- If the third cup is true, then the first cup is false, and the fourth cup must also be false (which means all cups have beer, contradicting the third cup). This leads to a contradiction.\n", "\n", "Thus, the only consistent scenario is that the **second cup** is true, which means:\n", "\n", "**B. No cola in all cups** is the only true statement.\n", "\n", "So, the answer is **B. No cola in all cups**." ] } ], "metadata": { "accelerator": "GPU", "application/vnd.databricks.v1+notebook": { "dashboards": [], "environmentMetadata": null, "language": "python", "notebookMetadata": { "pythonIndentUnit": 4 }, "notebookName": "07_MAC_+_Qwen2-7B-Instructi_Unsloth_train", "widgets": {} }, "colab": { "gpuType": "T4", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 0 }