{ "cells": [ { "cell_type": "markdown", "id": "68e9310f-109d-4f30-b263-d1e6c058ee80", "metadata": {}, "source": [ "# Setup" ] }, { "cell_type": "code", "execution_count": 1, "id": "6805b3b5-782b-437c-82b3-9392abb5a599", "metadata": { "tags": [] }, "outputs": [], "source": [ "# %pip install -q -r requirements.txt" ] }, { "cell_type": "markdown", "id": "94f0fcdd-1653-440e-8ebc-9c33d931163a", "metadata": {}, "source": [ "## Config" ] }, { "cell_type": "code", "execution_count": 2, "id": "5d0bd22f-293e-4c15-9dfe-8070553f42b5", "metadata": { "tags": [] }, "outputs": [], "source": [ "INPUT_DATASET = 'derek-thomas/labeled-multiple-choice-explained-mistral-reasoning'\n", "REVISION = '536f3b8'\n", "OUTPUT_DATASET = 'derek-thomas/labeled-multiple-choice-explained-mistral-tokenized'" ] }, { "cell_type": "code", "execution_count": 3, "id": "a1fc7a29-6b60-446d-b708-012f897de6a9", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "85ca07b896804801b5ccd629341e965c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='
\n", " | formatted_question | \n", "combined_fact | \n", "answer_key | \n", "topic | \n", "gpt3_5_reasoning | \n", "question_text | \n", "answer_choices | \n", "mistral_reasoning | \n", "
---|---|---|---|---|---|---|---|---|
0 | \n", "what is satellite technology used for predicti... | \n", "satellite technology is used for predicting wh... | \n", "c | \n", "Technology | \n", "a) Seconds and minutes: This option is incorre... | \n", "What is satellite technology used for predicting? | \n", "(a) Seconds and minutes (b) The strength and m... | \n", "Incorrect answers and explanations:\\n\\n1. Elec... | \n", "
1 | \n", "what does irradiating food do? (a) relieve pai... | \n", "irradiated food improves food safety. | \n", "c | \n", "Food science | \n", "(a) Relieve pain: This option is not correct b... | \n", "What does irradiating food do? | \n", "(a) Relieve pain (b) Enhance food's nutrients ... | \n", "Sure, let's examine each answer and justify wh... | \n", "
2 | \n", "what protects a mammal's skin? (a) fiber folli... | \n", "fiber follicles protect mammal skin | \n", "a | \n", "Biology | \n", "b) Exfoliation: Exfoliation is the process of ... | \n", "What protects a mammal's skin? | \n", "(a) Fiber follicles (b) Exfoliation (c) Resist... | \n", "Sure, let's go through each of the provided an... | \n", "
3 | \n", "what do earthworms do when a segment breaks of... | \n", "earthworms can regrow segments that break off | \n", "b | \n", "Biology | \n", "a) Dies: This option is not correct because ea... | \n", "What do earthworms do when a segment breaks off? | \n", "(a) Dies (b) Regrows it (c) Reproduces (d) Sed... | \n", "1. Reading the question carefully, we can see ... | \n", "
4 | \n", "lightning can be bad for what? (a) the environ... | \n", "lightning can be bad for the environment. | \n", "a | \n", "Electricity | \n", "b) Rainstorms: Lightning is actually a natural... | \n", "Lightning can be bad for what? | \n", "(a) The environment (b) Rainstorms (c) Destruc... | \n", "1. Food: While essential for the growth and he... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
8408 | \n", "organisms that can cause infection do what? (a... | \n", "organisms that can cause infection make humans... | \n", "g | \n", "Biology | \n", "a) Bandaging open sores is not the correct ans... | \n", "Organisms that can cause infection do what? | \n", "(a) Bandage open sores (b) Keep flesh clean (c... | \n", "1. Read the question and options carefully: Th... | \n", "
8409 | \n", "fungi are living things that cannot make thei... | \n", "fungi are living things that cannot make their... | \n", "a | \n", "Biology | \n", "b) Fungi are living things that can make their... | \n", "Fungi are living things that cannot make their... | \n", "(a) Food (b) Cells (c) Energy (d) Fruits (e) H... | \n", "1. Read the question and options carefully: Th... | \n", "
8410 | \n", "an overheated body can use water for: (a) meta... | \n", "the evaporation of water from the skin cools t... | \n", "g | \n", "Biology | \n", "a) Metabolic reaction: This option is incorrec... | \n", "An overheated body can use water for:? | \n", "(a) Metabolic reaction (b) Dehydrating (c) Rai... | \n", "1. Read the question and options carefully: Th... | \n", "
8411 | \n", "what is essential for cellular respiration for... | \n", "plants are essential for cellular respiration ... | \n", "f | \n", "Biology | \n", "a) Electrons are involved in cellular respirat... | \n", "What is essential for cellular respiration for... | \n", "(a) Electron (b) Glucose (c) Energy (d) Energy... | \n", "1. First, let's read the question and options ... | \n", "
8412 | \n", "what helps insulate and protect the body? (a) ... | \n", "living cells in follicles help insulate and pr... | \n", "b | \n", "Biology | \n", "a) H2O: Water is essential for life, but it do... | \n", "What helps insulate and protect the body? | \n", "(a) H2o (b) Living cells in follicles (c) Laye... | \n", "1. Read the question and options carefully: Th... | \n", "
8413 rows × 8 columns
\n", "" ], "text/plain": [ " formatted_question \\\n", "0 what is satellite technology used for predicti... \n", "1 what does irradiating food do? (a) relieve pai... \n", "2 what protects a mammal's skin? (a) fiber folli... \n", "3 what do earthworms do when a segment breaks of... \n", "4 lightning can be bad for what? (a) the environ... \n", "... ... \n", "8408 organisms that can cause infection do what? (a... \n", "8409 fungi are living things that cannot make thei... \n", "8410 an overheated body can use water for: (a) meta... \n", "8411 what is essential for cellular respiration for... \n", "8412 what helps insulate and protect the body? (a) ... \n", "\n", " combined_fact answer_key \\\n", "0 satellite technology is used for predicting wh... c \n", "1 irradiated food improves food safety. c \n", "2 fiber follicles protect mammal skin a \n", "3 earthworms can regrow segments that break off b \n", "4 lightning can be bad for the environment. a \n", "... ... ... \n", "8408 organisms that can cause infection make humans... g \n", "8409 fungi are living things that cannot make their... a \n", "8410 the evaporation of water from the skin cools t... g \n", "8411 plants are essential for cellular respiration ... f \n", "8412 living cells in follicles help insulate and pr... b \n", "\n", " topic gpt3_5_reasoning \\\n", "0 Technology a) Seconds and minutes: This option is incorre... \n", "1 Food science (a) Relieve pain: This option is not correct b... \n", "2 Biology b) Exfoliation: Exfoliation is the process of ... \n", "3 Biology a) Dies: This option is not correct because ea... \n", "4 Electricity b) Rainstorms: Lightning is actually a natural... \n", "... ... ... \n", "8408 Biology a) Bandaging open sores is not the correct ans... \n", "8409 Biology b) Fungi are living things that can make their... \n", "8410 Biology a) Metabolic reaction: This option is incorrec... \n", "8411 Biology a) Electrons are involved in cellular respirat... \n", "8412 Biology a) H2O: Water is essential for life, but it do... \n", "\n", " question_text \\\n", "0 What is satellite technology used for predicting? \n", "1 What does irradiating food do? \n", "2 What protects a mammal's skin? \n", "3 What do earthworms do when a segment breaks off? \n", "4 Lightning can be bad for what? \n", "... ... \n", "8408 Organisms that can cause infection do what? \n", "8409 Fungi are living things that cannot make their... \n", "8410 An overheated body can use water for:? \n", "8411 What is essential for cellular respiration for... \n", "8412 What helps insulate and protect the body? \n", "\n", " answer_choices \\\n", "0 (a) Seconds and minutes (b) The strength and m... \n", "1 (a) Relieve pain (b) Enhance food's nutrients ... \n", "2 (a) Fiber follicles (b) Exfoliation (c) Resist... \n", "3 (a) Dies (b) Regrows it (c) Reproduces (d) Sed... \n", "4 (a) The environment (b) Rainstorms (c) Destruc... \n", "... ... \n", "8408 (a) Bandage open sores (b) Keep flesh clean (c... \n", "8409 (a) Food (b) Cells (c) Energy (d) Fruits (e) H... \n", "8410 (a) Metabolic reaction (b) Dehydrating (c) Rai... \n", "8411 (a) Electron (b) Glucose (c) Energy (d) Energy... \n", "8412 (a) H2o (b) Living cells in follicles (c) Laye... \n", "\n", " mistral_reasoning \n", "0 Incorrect answers and explanations:\\n\\n1. Elec... \n", "1 Sure, let's examine each answer and justify wh... \n", "2 Sure, let's go through each of the provided an... \n", "3 1. Reading the question carefully, we can see ... \n", "4 1. Food: While essential for the growth and he... \n", "... ... \n", "8408 1. Read the question and options carefully: Th... \n", "8409 1. Read the question and options carefully: Th... \n", "8410 1. Read the question and options carefully: Th... \n", "8411 1. First, let's read the question and options ... \n", "8412 1. Read the question and options carefully: Th... \n", "\n", "[8413 rows x 8 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Load dataset from Hugging Face Hub\n", "dataset = load_dataset(INPUT_DATASET, split='train')\n", "\n", "# Convert to pandas dataframe\n", "df = dataset.to_pandas()\n", "print(f\"Before Cleaning: {len(df)} rows\")\n", "\n", "# Drop the __index_level_0__ column if it exists\n", "df.drop(columns=['mistral_reasoning_prompt'], errors='ignore', inplace=True)\n", "\n", "# Ensure all values in 'formatted_question' are strings\n", "df.rename(columns={\n", " 'explanation': 'gpt3_5_reasoning',\n", "}, inplace=True)\n", "df" ] }, { "cell_type": "markdown", "id": "2511bc04-f611-4dc7-b3ed-e477907b0200", "metadata": {}, "source": [ "## Create Prompts from Processed Data" ] }, { "cell_type": "markdown", "id": "d124c7cf-a369-46a9-94db-069894145959", "metadata": {}, "source": [ "We need to convert our sample into a format similar to below for each of the scenarios.\n", "\n", "```\n", "[\n", " {\"content\": user_content, \"role\": \"user\"},\n", " {\"content\": assistant_response, \"role\": \"assistant\"}\n", "]\n", "```\n", "\n", "We should include a helpful system_prompt with a general trivia prefix, and a suffix that contains instructions that fit each scenario.\n", "The `user_content` will have the Question and answer choices.\n", "The `assistant_response` should reflect the scenario. " ] }, { "cell_type": "code", "execution_count": 7, "id": "1c6554a6-4717-4bf0-ae51-102630d40fd7", "metadata": { "tags": [] }, "outputs": [], "source": [ "df['user_prompt'] = df.apply(lambda row: f\"Question: {row['question_text']}\\nAnswer Choices: {row['answer_choices']}\", axis=1)" ] }, { "cell_type": "markdown", "id": "1391b7e1-2462-41e3-b2f0-5a8f6c95859b", "metadata": {}, "source": [ "Here we need to create the structure of our conversation. Each system prompt should reflect the instructions we want, so we can start with a prefix and add in the specifics for each scenario." ] }, { "cell_type": "markdown", "id": "2c817304-9ecc-43d9-83b9-5bb8dd662797", "metadata": {}, "source": [ "### Reasoning Final Answer Structured Generation" ] }, { "cell_type": "code", "execution_count": 8, "id": "878727dc-4801-4376-be26-1cc601cb5f92", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", " | topic | \n", "question_text | \n", "answer_key | \n", "gpt3_5_reasoning | \n", "mistral_reasoning | \n", "answer_choices | \n", "user_prompt | \n", "user_prompt_RFA | \n", "conversation_RFA_gpt3_5 | \n", "conversation_RFA_mistral | \n", "user_prompt_FAR | \n", "conversation_FAR_gpt3_5 | \n", "conversation_FAR_mistral | \n", "user_prompt_FA | \n", "conversation_FA | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Technology | \n", "What is satellite technology used for predicting? | \n", "c | \n", "a) Seconds and minutes: This option is incorre... | \n", "Incorrect answers and explanations:\\n\\n1. Elec... | \n", "(a) Seconds and minutes (b) The strength and m... | \n", "Question: What is satellite technology used fo... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
1 | \n", "Food science | \n", "What does irradiating food do? | \n", "c | \n", "(a) Relieve pain: This option is not correct b... | \n", "Sure, let's examine each answer and justify wh... | \n", "(a) Relieve pain (b) Enhance food's nutrients ... | \n", "Question: What does irradiating food do?\\nAnsw... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
2 | \n", "Biology | \n", "What protects a mammal's skin? | \n", "a | \n", "b) Exfoliation: Exfoliation is the process of ... | \n", "Sure, let's go through each of the provided an... | \n", "(a) Fiber follicles (b) Exfoliation (c) Resist... | \n", "Question: What protects a mammal's skin?\\nAnsw... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
3 | \n", "Biology | \n", "What do earthworms do when a segment breaks off? | \n", "b | \n", "a) Dies: This option is not correct because ea... | \n", "1. Reading the question carefully, we can see ... | \n", "(a) Dies (b) Regrows it (c) Reproduces (d) Sed... | \n", "Question: What do earthworms do when a segment... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
4 | \n", "Electricity | \n", "Lightning can be bad for what? | \n", "a | \n", "b) Rainstorms: Lightning is actually a natural... | \n", "1. Food: While essential for the growth and he... | \n", "(a) The environment (b) Rainstorms (c) Destruc... | \n", "Question: Lightning can be bad for what?\\nAnsw... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
8408 | \n", "Biology | \n", "Organisms that can cause infection do what? | \n", "g | \n", "a) Bandaging open sores is not the correct ans... | \n", "1. Read the question and options carefully: Th... | \n", "(a) Bandage open sores (b) Keep flesh clean (c... | \n", "Question: Organisms that can cause infection d... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
8409 | \n", "Biology | \n", "Fungi are living things that cannot make their... | \n", "a | \n", "b) Fungi are living things that can make their... | \n", "1. Read the question and options carefully: Th... | \n", "(a) Food (b) Cells (c) Energy (d) Fruits (e) H... | \n", "Question: Fungi are living things that cannot ... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
8410 | \n", "Biology | \n", "An overheated body can use water for:? | \n", "g | \n", "a) Metabolic reaction: This option is incorrec... | \n", "1. Read the question and options carefully: Th... | \n", "(a) Metabolic reaction (b) Dehydrating (c) Rai... | \n", "Question: An overheated body can use water for... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
8411 | \n", "Biology | \n", "What is essential for cellular respiration for... | \n", "f | \n", "a) Electrons are involved in cellular respirat... | \n", "1. First, let's read the question and options ... | \n", "(a) Electron (b) Glucose (c) Energy (d) Energy... | \n", "Question: What is essential for cellular respi... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
8412 | \n", "Biology | \n", "What helps insulate and protect the body? | \n", "b | \n", "a) H2O: Water is essential for life, but it do... | \n", "1. Read the question and options carefully: Th... | \n", "(a) H2o (b) Living cells in follicles (c) Laye... | \n", "Question: What helps insulate and protect the ... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "<s>[INST] Answer the Question and include your... | \n", "
8413 rows × 15 columns
\n", "