diff --git a/.gitignore b/.gitignore index 10fdd19..1a5c7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,10 @@ env/ upload_data.py genies-datasets.tar distributions/ +.venv/ +__pycache__/ +*.pyc + +# jypter notebook +.ipynb_checkpoints/ + diff --git a/__pycache__/download_data.cpython-310.pyc b/__pycache__/download_data.cpython-310.pyc deleted file mode 100644 index d694dc9..0000000 Binary files a/__pycache__/download_data.cpython-310.pyc and /dev/null differ diff --git a/nbs/01_mjc_convert_data_to_preference.ipynb b/nbs/01_mjc_convert_data_to_preference.ipynb new file mode 100644 index 0000000..cc807ce --- /dev/null +++ b/nbs/01_mjc_convert_data_to_preference.ipynb @@ -0,0 +1,2803 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# convert `genies` datasets to [open_pref_eval](https://github.com/wassname/open_pref_eval)\n", + "\n", + "\n", + "Here I'm taking the GENIE datasets, and \n", + "1. converting them to preference (compatible with open_pref_eval)\n", + "2. hosting on huggingface" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "## Setup\n", + "\n", + "```sh\n", + "python -m venv .venv --prompt GENIES\n", + ". .venv/bin/activate\n", + "pip install wheel fire requests\n", + "pip install -r requirements.txt\n", + "python ./download_data.py\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "%reload_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "from datasets import load_dataset\n", + "import datasets\n", + "\n", + "from pathlib import Path\n", + "import json" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'source': 'alpaca_easy', 'target': 'alpaca_hard'},\n", + " {'source': 'arc_easy', 'target': 'arc_hard'},\n", + " {'source': 'math_easy', 'target': 'math_hard'},\n", + " {'source': 'code_easy', 'target': 'code_hard'},\n", + " {'source': 'ranking_logic_easy', 'target': 'ranking_logic_hard'},\n", + " {'source': 'raven_easy', 'target': 'raven_matrices'},\n", + " {'source': 'alpaca_mmlu', 'target': 'spanish_input'},\n", + " {'source': 'alpaca_mmlu', 'target': 'spanish_output'},\n", + " {'source': 'alpaca_mmlu', 'target': 'comma_separated_input'},\n", + " {'source': 'alpaca_mmlu', 'target': 'comma_separated_output'},\n", + " {'source': 'alpaca_mmlu', 'target': 'ranking_logic'},\n", + " {'source': 'alpaca_mmlu', 'target': 'raven_matrices'},\n", + " {'source': 'alpaca_mmlu', 'target': 'word_swap'},\n", + " {'source': 'code', 'target': 'counterfactual_python'},\n", + " {'source': 'code', 'target': 'us_history'},\n", + " {'source': 'code', 'target': 'change_my_view'},\n", + " {'source': 'cooking', 'target': 'math'},\n", + " {'source': 'cooking', 'target': 'raven_matrices'},\n", + " {'source': 'math', 'target': 'change_my_view'},\n", + " {'source': 'math', 'target': 'cooking'},\n", + " {'source': 'change_my_view', 'target': 'raven_matrices'},\n", + " {'source': 'change_my_view', 'target': 'cooking'},\n", + " {'source': 'raven_matrices', 'target': 'us_history'},\n", + " {'source': 'raven_matrices', 'target': 'code'},\n", + " {'source': 'us_history', 'target': 'math'},\n", + " {'source': 'us_history', 'target': 'code'},\n", + " {'source': 'us_history', 'target': 'us_history_textbook'},\n", + " {'source': 'us_history_textbook', 'target': 'us_history_fiction'},\n", + " {'source': 'us_history_fiction', 'target': 'us_history_make_questions'},\n", + " {'source': 'us_history_make_questions', 'target': 'us_history'},\n", + " {'source': 'math', 'target': 'math_fiction'},\n", + " {'source': 'math_fiction', 'target': 'math_textbook'},\n", + " {'source': 'math_textbook', 'target': 'math_make_questions'},\n", + " {'source': 'math_make_questions', 'target': 'math'},\n", + " {'source': 'alpaca_low_quality', 'target': 'alpaca_high_quality'},\n", + " {'source': 'shp_low_quality', 'target': 'shp_high_quality'},\n", + " {'source': 'code_low_quality', 'target': 'code'},\n", + " {'source': 'alpaca_mmlu', 'target': 'truthful_qa'},\n", + " {'source': 'alpaca_mmlu', 'target': 'personality_traits'},\n", + " {'source': 'alpaca_mmlu', 'target': 'survival_influence'},\n", + " {'source': 'alpaca_mmlu', 'target': 'gender_bias'},\n", + " {'source': 'alpaca_mmlu', 'target': 'punishment_avoidance'},\n", + " {'source': 'alpaca_mmlu', 'target': 'reward_seeking'},\n", + " {'source': 'alpaca_mmlu', 'target': 'crt_1'},\n", + " {'source': 'alpaca_mmlu', 'target': 'crt_2'},\n", + " {'source': 'alpaca_mmlu', 'target': 'crt_3'},\n", + " {'source': 'alpaca_mmlu',\n", + " 'target': 'sycophancy_mimicry',\n", + " 'target_reference': 'quote_attribution'},\n", + " {'source': 'alpaca_mmlu',\n", + " 'target': 'sycophancy_answer',\n", + " 'target_reference': 'arc_easy'},\n", + " {'source': 'alpaca_mmlu',\n", + " 'target': 'sycophancy_feedback',\n", + " 'target_reference': 'code_is_correct'},\n", + " {'source': 'alpaca_chat',\n", + " 'target': 'sycophancy_are_you_sure',\n", + " 'target_reference': 'arc_easy'},\n", + " {'source': 'pursue_goals', 'target': 'relinquish_power'},\n", + " {'source': 'creative_writing', 'target': 'biology_with_literary_style'},\n", + " {'source': 'alpaca_short',\n", + " 'target': 'alpaca_long',\n", + " 'target_reference': 'alpaca_mmlu'},\n", + " {'source': 'alpaca_chat', 'target': 'illegal_dont_help'},\n", + " {'source': 'alpaca_mmlu', 'target': 'wrong_arc'},\n", + " {'source': 'alpaca_mmlu', 'target': 'unhelpful_alpaca'},\n", + " {'source': 'alpaca_mmlu', 'target': 'truthful_qa'},\n", + " {'source': 'alpaca_mmlu', 'target': 'personality_traits'},\n", + " {'source': 'alpaca_mmlu', 'target': 'gender_bias'},\n", + " {'source': 'alpaca_mmlu', 'target': 'survival_influence'},\n", + " {'source': 'alpaca_mmlu', 'target': 'punishment_avoidance'},\n", + " {'source': 'alpaca_mmlu', 'target': 'reward_seeking'},\n", + " {'source': 'alpaca_mmlu', 'target': 'crt_1'},\n", + " {'source': 'alpaca_mmlu', 'target': 'crt_2'},\n", + " {'source': 'alpaca_mmlu', 'target': 'crt_3'},\n", + " {'source': 'alpaca_mmlu',\n", + " 'target': 'sycophancy_mimicry',\n", + " 'target_reference': 'quote_attribution'},\n", + " {'source': 'alpaca_mmlu',\n", + " 'target': 'sycophancy_answer',\n", + " 'target_reference': 'arc_easy'},\n", + " {'source': 'alpaca_mmlu',\n", + " 'target': 'sycophancy_feedback',\n", + " 'target_reference': 'code_is_correct'},\n", + " {'source': 'alpaca_chat',\n", + " 'target': 'sycophancy_are_you_sure',\n", + " 'target_reference': 'arc_easy'}]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "path_to_distribution_shift_pairs = Path('../distribution_shifts/all.json')\n", + "pairs_data = json.load(open(path_to_distribution_shift_pairs))\n", + "pairs_data" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'alpaca_easy', 'external_datasets': [], 'overlapping_datasets': []}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [], + "source": [ + "from datasets import DatasetInfo, Dataset\n", + "\n", + "def genie2ds(train: list) -> pd.DataFrame:\n", + " \"\"\"takes the GENIE format and convert it to to a dataframe of preference format.\"\"\"\n", + " outs = []\n", + " for i, row in enumerate(train):\n", + " s = pd.Series(row['responses'])\n", + " chosen = s[s==1].index[0]\n", + " rejected = s[s==0].index\n", + " outs += [dict(prompt=row['prompt'], chosen=chosen, rejected=r, i=i) for r in rejected]\n", + "\n", + " df = pd.DataFrame(outs)\n", + " return df\n", + "\n", + "\n", + "\n", + "def json2ds(source_dir: Path) -> Dataset:\n", + " test = json.load(open(source_dir / 'test.json'))\n", + " train = json.load(open(source_dir / 'train.json'))\n", + " metadata = json.load(open(source_dir / 'metadata.json'))\n", + " ds_info = DatasetInfo(\n", + " description= f\"GENIE:{metadata['id']}\",\n", + " citation= \"\"\"@misc{clymer2023generalizationanalogiestestbedgeneralizing,\n", + " title={Generalization Analogies: A Testbed for Generalizing AI Oversight to Hard-To-Measure Domains}, \n", + " author={Joshua Clymer and Garrett Baker and Rohan Subramani and Sam Wang},\n", + " year={2023},\n", + " eprint={2311.07723},\n", + " archivePrefix={arXiv},\n", + " primaryClass={cs.AI},\n", + " url={https://arxiv.org/abs/2311.07723}, \n", + " }\"\"\",\n", + " homepage= \"https://joshuaclymer.github.io/generalization-analogies-website/\",\n", + " license= \"MIT\",\n", + " config_name=f\"{metadata['id']}\",\n", + " )\n", + "\n", + "\n", + " df_train = genie2ds(train)\n", + " df_test = genie2ds(test)\n", + " dataset2 = datasets.DatasetDict(\n", + " {'train': datasets.Dataset.from_pandas(df_train, info=ds_info),\n", + " 'test': datasets.Dataset.from_pandas(df_test, info=ds_info)}\n", + " )\n", + " return dataset2" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "../distributions/alpaca_easy alpaca_easy\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "70cf450126b54157bab78571208e91d4", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Pushing dataset shards to the dataset hub: 0%| | 0/1 [00:00