{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9b02e0f0-c17f-4193-997c-61df2165b094",
   "metadata": {},
   "source": [
    "## Create mixed sources file (a mixture of human samples and LLM samples)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1372fd6c-a723-42c3-92cf-7a032e11d532",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import random\n",
    "\n",
    "# Implement the process for all of the 10 score functions\n",
    "with open(file_path, 'r') as file:\n",
    "    data = json.load(file)\n",
    "\n",
    "# Remain the related items\n",
    "new_data = {\n",
    "    'name': data['name'],\n",
    "    'info': data['info'],\n",
    "    'predictions': data['predictions']\n",
    "}\n",
    "\n",
    "# Get the scores for human-written texts and that for LLM-generated texts\n",
    "real_samples = new_data['predictions']['real']\n",
    "sampled_data = new_data['predictions']['samples']\n",
    "\n",
    "# Let new_data['predictions']['samples'] consist of: 200 human-written samples and 300 LLM-generated samples\n",
    "indices = random.sample(range(500), 200)\n",
    "for idx in indices:\n",
    "    sampled_data[idx] = real_samples[idx]\n",
    "\n",
    "with open('add_exp_for_rebuttal/data/mixsource_olympic.palm2.roberta-large-openai-detector.json', 'w') as file:\n",
    "    json.dump(new_data, file, indent=4)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3825825-d7f4-41a1-8766-16cbf66665cc",
   "metadata": {},
   "source": [
    "## Create mixed LLMs file (samples consists text scores of different LLMs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ceaf80d1-f67b-4465-9498-fa43c6f088a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import random\n",
    "\n",
    "# Implement the process for all of the 10 score functions\n",
    "file_path1 = 'exp_main/data/olympic.gemini_1.5_flash.roberta-large-openai-detector.json'\n",
    "file_path2 = 'exp_main/data/olympic.gemini_1.5_pro.roberta-large-openai-detector.json'\n",
    "file_path3 = 'exp_main/data/olympic.palm2.roberta-large-openai-detector.json'\n",
    "output_path = 'add_exp_for_rebuttal/data/olympic.mixllms.roberta-large-openai-detector.json'  \n",
    "\n",
    "\n",
    "with open(file_path1, 'r') as file:\n",
    "    data1 = json.load(file)\n",
    "with open(file_path2, 'r') as file:\n",
    "    data2 = json.load(file)\n",
    "with open(file_path3, 'r') as file:\n",
    "    data3 = json.load(file)\n",
    "\n",
    "samples1 = data1['predictions']['samples']\n",
    "samples2 = data2['predictions']['samples']\n",
    "samples3 = data3['predictions']['samples']\n",
    "real_data = data1['predictions']['real']\n",
    "\n",
    "\n",
    "new_samples = []\n",
    "\n",
    "\n",
    "new_samples.extend(random.sample(samples1, 200))  # 200 samples of gemini_1.5_flash\n",
    "new_samples.extend(random.sample(samples2, 100))  # 100 samples of gemini_1.5_pro\n",
    "new_samples.extend(random.sample(samples3, 200))  # 200 samples of palm2\n",
    "\n",
    "\n",
    "new_data = {\n",
    "    'name': data1['name'],\n",
    "    'info': data1['info'],\n",
    "    'predictions': {\n",
    "        'real': real_data,\n",
    "        'samples': new_samples\n",
    "    }\n",
    "}\n",
    "\n",
    "with open(output_path, 'w') as file:\n",
    "    json.dump(new_data, file, indent=4)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
