File size: 8,356 Bytes
f7634a7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting pandas\n",
" Downloading pandas-2.2.3-cp311-cp311-win_amd64.whl.metadata (19 kB)\n",
"Collecting numpy>=1.23.2 (from pandas)\n",
" Downloading numpy-2.2.4-cp311-cp311-win_amd64.whl.metadata (60 kB)\n",
" ---------------------------------------- 0.0/60.8 kB ? eta -:--:--\n",
" -------------------------- ------------- 41.0/60.8 kB ? eta -:--:--\n",
" ---------------------------------------- 60.8/60.8 kB 1.1 MB/s eta 0:00:00\n",
"Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\user\\appdata\\local\\packages\\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\\localcache\\local-packages\\python311\\site-packages (from pandas) (2.9.0.post0)\n",
"Collecting pytz>=2020.1 (from pandas)\n",
" Downloading pytz-2025.2-py2.py3-none-any.whl.metadata (22 kB)\n",
"Collecting tzdata>=2022.7 (from pandas)\n",
" Downloading tzdata-2025.2-py2.py3-none-any.whl.metadata (1.4 kB)\n",
"Requirement already satisfied: six>=1.5 in c:\\users\\user\\appdata\\local\\packages\\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\\localcache\\local-packages\\python311\\site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n",
"Downloading pandas-2.2.3-cp311-cp311-win_amd64.whl (11.6 MB)\n",
" ---------------------------------------- 0.0/11.6 MB ? eta -:--:--\n",
" - -------------------------------------- 0.4/11.6 MB 24.3 MB/s eta 0:00:01\n",
" --- ------------------------------------ 1.0/11.6 MB 20.5 MB/s eta 0:00:01\n",
" --------- ------------------------------ 2.8/11.6 MB 22.0 MB/s eta 0:00:01\n",
" ----------- ---------------------------- 3.3/11.6 MB 20.9 MB/s eta 0:00:01\n",
" ------------------ --------------------- 5.3/11.6 MB 28.1 MB/s eta 0:00:01\n",
" ----------------------- ---------------- 6.8/11.6 MB 27.1 MB/s eta 0:00:01\n",
" ------------------------ --------------- 7.2/11.6 MB 22.9 MB/s eta 0:00:01\n",
" ----------------------------- ---------- 8.6/11.6 MB 26.0 MB/s eta 0:00:01\n",
" -------------------------------------- - 11.3/11.6 MB 31.1 MB/s eta 0:00:01\n",
" ---------------------------------------- 11.6/11.6 MB 28.5 MB/s eta 0:00:00\n",
"Downloading numpy-2.2.4-cp311-cp311-win_amd64.whl (12.9 MB)\n",
" ---------------------------------------- 0.0/12.9 MB ? eta -:--:--\n",
" ----------- ---------------------------- 3.7/12.9 MB 120.6 MB/s eta 0:00:01\n",
" ------------------- -------------------- 6.2/12.9 MB 79.0 MB/s eta 0:00:01\n",
" ------------------------ --------------- 7.9/12.9 MB 63.4 MB/s eta 0:00:01\n",
" ------------------------ --------------- 8.0/12.9 MB 56.5 MB/s eta 0:00:01\n",
" ------------------------- -------------- 8.3/12.9 MB 40.8 MB/s eta 0:00:01\n",
" ---------------------------- ----------- 9.2/12.9 MB 34.5 MB/s eta 0:00:01\n",
" ------------------------------------ --- 11.7/12.9 MB 34.4 MB/s eta 0:00:01\n",
" ---------------------------------------- 12.9/12.9 MB 31.2 MB/s eta 0:00:00\n",
"Downloading pytz-2025.2-py2.py3-none-any.whl (509 kB)\n",
" ---------------------------------------- 0.0/509.2 kB ? eta -:--:--\n",
" --------------------------------------- 509.2/509.2 kB 31.2 MB/s eta 0:00:00\n",
"Downloading tzdata-2025.2-py2.py3-none-any.whl (347 kB)\n",
" ---------------------------------------- 0.0/347.8 kB ? eta -:--:--\n",
" --------------------------------------- 347.8/347.8 kB 21.1 MB/s eta 0:00:00\n",
"Installing collected packages: pytz, tzdata, numpy, pandas\n",
"Successfully installed numpy-2.2.4 pandas-2.2.3 pytz-2025.2 tzdata-2025.2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"[notice] A new release of pip is available: 24.0 -> 25.0.1\n",
"[notice] To update, run: C:\\Users\\USER\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\\python.exe -m pip install --upgrade pip\n"
]
}
],
"source": [
"!pip install pandas"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"โ
๋ณํ ์๋ฃ: 376๊ฐ์ ๋ํ๊ฐ sad_couple.jsonl์ ์ ์ฅ๋จ.\n"
]
}
],
"source": [
"import pandas as pd\n",
"import json\n",
"import glob\n",
"import os\n",
"\n",
"# TSV ํ์ผ๋ค์ด ์๋ ํด๋ ๊ฒฝ๋ก\n",
"folder_path = r\"C:\\Users\\USER\\Desktop\\empathy_data\\data\\046.๊ณต๊ฐํ ๋ํ (์ฐ์ธ๋ง)\\046.๊ณต๊ฐํ ๋ํ (์ฐ์ธ๋ง)\\01-1.์ ์๊ฐ๋ฐฉ๋ฐ์ดํฐ\\Training\\01.์์ฒ๋ฐ์ดํฐ\\TS_์ฌํ_์ฐ์ธ\"\n",
"\n",
"# ํด๋ ๋ด ๋ชจ๋ .tsv ํ์ผ ์ฐพ๊ธฐ\n",
"tsv_files = glob.glob(os.path.join(folder_path, \"*.tsv\"))\n",
"\n",
"# ๊ฒฐ๊ณผ ์ ์ฅํ ๋์
๋๋ฆฌ\n",
"conversations = {}\n",
"\n",
"# ๋ชจ๋ TSV ํ์ผ ์ฒ๋ฆฌ\n",
"for file in tsv_files:\n",
" df = pd.read_csv(file, sep=\"\\t\") # TSV ํ์ผ ์ฝ๊ธฐ\n",
" \n",
" for _, row in df.iterrows():\n",
" conv_id = row[\"id\"] # ๋ํ ID\n",
" utterance_type = \"user\" if row[\"utterance_type\"] == 0 else \"assistant\"\n",
" \n",
" # ์๋ก์ด ๋ํ ID๊ฐ ๋์ค๋ฉด ๋ฆฌ์คํธ ์ด๊ธฐํ\n",
" if conv_id not in conversations:\n",
" conversations[conv_id] = []\n",
" \n",
" # ๋ฐํ ์ถ๊ฐ\n",
" conversations[conv_id].append({\n",
" \"role\": utterance_type,\n",
" \"content\": row[\"utterance_text\"]\n",
" })\n",
"\n",
"# JSONL ํ์ผ๋ก ์ ์ฅ\n",
"output_file = \"sad_couple.jsonl\"\n",
"with open(output_file, \"w\", encoding=\"utf-8\") as f:\n",
" for conv_id, convo in conversations.items():\n",
" json.dump({\"conversation\": convo}, f, ensure_ascii=False)\n",
" f.write(\"\\n\")\n",
"\n",
"print(f\"โ
๋ณํ ์๋ฃ: {len(conversations)}๊ฐ์ ๋ํ๊ฐ {output_file}์ ์ ์ฅ๋จ.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## combine"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"โ
๋ณํ ์๋ฃ: 6๊ฐ์ JSONL ํ์ผ์ด merged_train.jsonl์ ํฉ์ณ์ก์ต๋๋ค.\n"
]
}
],
"source": [
"import json\n",
"import glob\n",
"import os\n",
"\n",
"# JSONL ํ์ผ๋ค์ด ์๋ ํด๋ ๊ฒฝ๋ก\n",
"folder_path = r\"C:\\Users\\USER\\Desktop\\empathy_data\\data\"\n",
"\n",
"# ํด๋ ๋ด ๋ชจ๋ .jsonl ํ์ผ ์ฐพ๊ธฐ\n",
"jsonl_files = glob.glob(os.path.join(folder_path, \"*.jsonl\"))\n",
"\n",
"# ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ ์ต์ข
JSONL ํ์ผ ๊ฒฝ๋ก\n",
"output_file = \"merged_train.jsonl\"\n",
"\n",
"# ๋ชจ๋ JSONL ํ์ผ์ ํ๋๋ก ํฉ์นจ\n",
"with open(output_file, \"w\", encoding=\"utf-8\") as outfile:\n",
" for file in jsonl_files:\n",
" with open(file, \"r\", encoding=\"utf-8\") as infile:\n",
" # ํ์ผ ๋ด์ฉ ์ฝ๊ณ ๊ทธ๋๋ก ์ถ๋ ฅ ํ์ผ์ ์์ฑ\n",
" for line in infile:\n",
" outfile.write(line)\n",
"\n",
"print(f\"โ
๋ณํ ์๋ฃ: {len(jsonl_files)}๊ฐ์ JSONL ํ์ผ์ด {output_file}์ ํฉ์ณ์ก์ต๋๋ค.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|