{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from datasets import load_dataset, load_from_disk" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "boolq = load_dataset(\"google/boolq\")\n", "boolq" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_boolq = []\n", "for data in boolq['train']:\n", " question = data['question']\n", " answer = {True:'true', False:'false'}[data['answer']]\n", " commonsense_boolq.append(\n", " {\n", " 'instruction': f\"Please answer the following question with true or false, question: {question}?\\n\\nAnswer format: true/false\",\n", " 'answer': answer,\n", " 'input': '',\n", " 'output': f'the correct answer is {answer}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "piqa = load_dataset(\"skrishna/piqa_preop\")\n", "piqa" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_piqa = []\n", "for data in piqa['train']:\n", " goal = data['goal']\n", " sol1 = data['sol1']\n", " sol2 = data['sol2']\n", " label = data['label']+1\n", " commonsense_piqa.append(\n", " {\n", " 'instruction': f\"Please choose the correct solution to the question: {goal}\\n\\nSolution1: {sol1}\\n\\nSolution2: {sol2}\\n\\nAnswer format: solution1/solution2\",\n", " 'answer': f\"solution{label}\",\n", " 'input': '',\n", " 'output': f'the correct answer is solution{label}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "siqa = load_dataset(\"lighteval/siqa\")\n", "siqa" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_siqa = []\n", "for data in siqa['train']:\n", " context = data['context']\n", " question = data['question']\n", " answerA = data['answerA']\n", " answerB = data['answerB']\n", " answerC = data['answerC']\n", " label = data['label']\n", " commonsense_siqa.append(\n", " {\n", " 'instruction': f\"Please choose the correct answer to the question: {context} {question}\\n\\nAnswer1: {answerA} Answer2: {answerB} Answer3: {answerC}\\n\\nAnswer format: answer1/answer2/answer3\",\n", " 'answer': f\"answer{label}\",\n", " 'input': '',\n", " 'output': f'the correct answer is answer{label}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hellaswag = load_dataset(\"/Users/mengfanxu/hellaswag/hellaswag_train\")\n", "hellaswag" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_hellaswag = []\n", "for data in hellaswag['train']:\n", " activity_label = data['activity_label']\n", " ctx = data['ctx']\n", " ed1 = data['endings'][0]\n", " ed2 = data['endings'][1]\n", " ed3 = data['endings'][2]\n", " ed4 = data['endings'][3]\n", " label = data['label']+1\n", " commonsense_hellaswag.append(\n", " {\n", " 'instruction': f\"Please choose the correct ending to complete the given sentence: {activity_label}: {ctx}\\n\\nEnding1: {ed1} Ending2: {ed2} Ending3: {ed3} Ending4: {ed4}\\n\\nAnswer format: ending1/ending2/ending3/ending4\",\n", " 'answer': f\"ending{label}\",\n", " 'input': '',\n", " 'output': f'the correct answer is ending{label}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "openbookqa = load_from_disk(\"/Users/mengfanxu/openbookqa\")\n", "openbookqa" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_openbookqa = []\n", "for data in openbookqa['train']:\n", " question_stem = data['question_stem']\n", " ed1 = data['choices']['text'][0]\n", " ed2 = data['choices']['text'][1]\n", " ed3 = data['choices']['text'][2]\n", " ed4 = data['choices']['text'][3]\n", " label = {\"A\":1,\"B\":2,\"C\":3,\"D\":4}[data['answerKey']]\n", " commonsense_openbookqa.append(\n", " {\n", " 'instruction': f\"Please choose the correct answer to the question: {question_stem}\\n\\nAnswer1: {ed1} Answer2: {ed2} Answer3: {ed3} Answer4: {ed4}\\n\\nAnswer format: answer1/answer2/answer3/answer4\",\n", " 'answer': f\"answer{label}\",\n", " 'input': '',\n", " 'output': f'the correct answer is answer{label}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "arc_c = load_dataset(\"allenai/ai2_arc\", \"ARC-Challenge\")\n", "arc_c" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_arc_c = []\n", "for data in arc_c['train']:\n", " question = data['question']\n", " ed1 = data['choices']['text'][0]\n", " ed2 = data['choices']['text'][1]\n", " ed3 = data['choices']['text'][2]\n", " instruction = f\"Please choose the correct answer to the question: {question}\\n\\nAnswer1: {ed1} Answer2: {ed2} Answer3: {ed3}\\n\\nAnswer format: answer1/answer2/answer3\"\n", " if len(data['choices']['text'])>=4:\n", " ed4 = data['choices']['text'][3]\n", " instruction = f\"Please choose the correct answer to the question: {question}\\n\\nAnswer1: {ed1} Answer2: {ed2} Answer3: {ed3} Answer4: {ed4}\\n\\nAnswer format: answer1/answer2/answer3/answer4\"\n", " if len(data['choices']['text'])>=5:\n", " ed5 = data['choices']['text'][4]\n", " instruction = f\"Please choose the correct answer to the question: {question}\\n\\nAnswer1: {ed1} Answer2: {ed2} Answer3: {ed3} Answer4: {ed4} Answer5: {ed5}\\n\\nAnswer format: answer1/answer2/answer3/answer4/answer5\"\n", " label = {\"A\":1,\"B\":2,\"C\":3,\"D\":4,\"E\":5, \"2\":2, \"4\":4, \"1\":1, \"3\":3}[data['answerKey']]\n", " \n", " commonsense_arc_c.append(\n", " {\n", " 'instruction': instruction,\n", " 'answer': f\"answer{label}\",\n", " 'input': '',\n", " 'output': f'the correct answer is answer{label}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "arc_e = load_dataset(\"allenai/ai2_arc\", \"ARC-Easy\")\n", "arc_e" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_arc_e = []\n", "for data in arc_e['train']:\n", " question = data['question']\n", " ed1 = data['choices']['text'][0]\n", " ed2 = data['choices']['text'][1]\n", " ed3 = data['choices']['text'][2]\n", " instruction = f\"Please choose the correct answer to the question: {question}\\n\\nAnswer1: {ed1} Answer2: {ed2} Answer3: {ed3}\\n\\nAnswer format: answer1/answer2/answer3\"\n", " if len(data['choices']['text'])>=4:\n", " ed4 = data['choices']['text'][3]\n", " instruction = f\"Please choose the correct answer to the question: {question}\\n\\nAnswer1: {ed1} Answer2: {ed2} Answer3: {ed3} Answer4: {ed4}\\n\\nAnswer format: answer1/answer2/answer3/answer4\"\n", " if len(data['choices']['text'])>=5:\n", " ed5 = data['choices']['text'][4]\n", " instruction = f\"Please choose the correct answer to the question: {question}\\n\\nAnswer1: {ed1} Answer2: {ed2} Answer3: {ed3} Answer4: {ed4} Answer5: {ed5}\\n\\nAnswer format: answer1/answer2/answer3/answer4/answer5\"\n", " label = {\"A\":1,\"B\":2,\"C\":3,\"D\":4,\"E\":5, \"2\":2, \"4\":4, \"1\":1, \"3\":3}[data['answerKey']]\n", " \n", " commonsense_arc_e.append(\n", " {\n", " 'instruction': instruction,\n", " 'answer': f\"answer{label}\",\n", " 'input': '',\n", " 'output': f'the correct answer is answer{label}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "winogrande = load_dataset(\"/Users/mengfanxu/Downloads/winogrande_1.1/train\")\n", "winogrande" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "commonsense_winogrande = []\n", "for data in winogrande['train']:\n", " sentence = data['sentence']\n", " option1 = data['option1']\n", " option2 = data['option2']\n", " answer = data['answer']\n", "\n", " commonsense_winogrande.append(\n", " {\n", " 'instruction': f\"Please choose the correct answer to fill in the blank to complete the given sentence: {sentence}\\n\\nOption1: {option1} Option2: {option2} Answer format: option1/option2\",\n", " 'answer': f\"option{answer}\",\n", " 'input': '',\n", " 'output': f'the correct answer is option{answer}'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "eval_boolq = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_boolq\")\n", "eval_piqa = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_piqa\")\n", "eval_social_interaction_qa = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_social_interaction_qa\")\n", "eval_hellaswag = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_hellaswag\")\n", "eval_winogrande = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_winogrande\")\n", "eval_arc_challenge = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_arc_challenge\")\n", "eval_arc_easy = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_arc_easy\")\n", "eval_openbookqa = load_from_disk(\"/Users/mengfanxu/Downloads/winogrande_1.1/PiSSA/inference/data/eval_openbookqa\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/boolq/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_boolq:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/boolq/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_boolq:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/piqa/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_piqa:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/piqa/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_piqa:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/siqa/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_siqa:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/siqa/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_social_interaction_qa:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/hellaswag/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_hellaswag:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/hellaswag/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_hellaswag:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/winogrande/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_winogrande:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/winogrande/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_winogrande:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/arc_challenge/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_arc_c:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/arc_challenge/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_arc_challenge:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/arc_easy/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_arc_e:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/arc_easy/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_arc_easy:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "with open(\"commonsense_filtered/openbookqa/train.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in commonsense_openbookqa:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")\n", "\n", "with open(\"commonsense_filtered/openbookqa/test.json\", \"w\", encoding=\"utf-8\") as f:\n", " for item in eval_openbookqa:\n", " f.write(json.dumps(item, ensure_ascii=False) + \"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "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.9.16" } }, "nbformat": 4, "nbformat_minor": 2 }