From de1b467e20749568bd0e9df92e3bc915179230b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B8=B9?= Date: Thu, 27 Jun 2024 21:14:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E4=B8=93=E9=97=A8=E4=B8=BAmlx=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- finetune/data_processing.ipynb | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 finetune/data_processing.ipynb diff --git a/finetune/data_processing.ipynb b/finetune/data_processing.ipynb new file mode 100644 index 0000000..7e2b7df --- /dev/null +++ b/finetune/data_processing.ipynb @@ -0,0 +1,66 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. 准备数据集\n", + "\n", + "将数据集转换为更通用的格式\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# 转换为 ChatML 格式\n", + "import os\n", + "import shutil\n", + "import json\n", + "\n", + "input_dir = \"data/AdvertiseGen\"\n", + "output_dir = \"data/mlx_AdvertiseGen\"\n", + "if os.path.exists(output_dir):\n", + " shutil.rmtree(output_dir)\n", + "os.makedirs(output_dir, exist_ok=True)\n", + "\n", + "for fn in [\"train.json\", \"dev.json\"]:\n", + " data_out_list = []\n", + " with open(os.path.join(input_dir, fn), \"r\") as f, open(os.path.join(output_dir, fn), \"w\") as fo:\n", + " for line in f:\n", + " if len(line.strip()) > 0:\n", + " data = json.loads(line)\n", + " data_out = {\"input\":data['content'],'prompt':\"/n请为以下关键词生成一条广告语。\",'output':data['summary']}\n", + " data_out_list.append(data_out)\n", + "\n", + " for d in data_out_list:\n", + " json_str = json.dumps(d,ensure_ascii=False) # 将字典转换为JSON字符串\n", + " fo.write(json_str + '\\n') # 写入字符串并添加换行符\n", + "\n" + ] + } + ], + "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.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}