大模型微调系列(二) 自定义数据集

💡 本文会带给你

  1. 认识alpaca指令监督微调数据集
  2. 如何构建自定义数据集
  3. 学会使用LLamFactory 进行LoRA微调大模型
  4. 掌握大模型转换为GGUF的方法
  5. 轻松使用 ollama 运行大模型

一、数据准备

从魔塔社区查找弱智吧问答数据集

下载数据集

modelscope download --dataset w10442005/ruozhiba_qa --local_dir ./datas/ruozhiba_qa/

数据格式转换

数据转为指令集数据集alpaca的数据格式
源文件格式
[
{
"system": "00000",
"query": "只剩一个心脏了还能活吗?",
"response": "能,人本来就只有一个心脏。"
},
]
目标文件数据格式为
[
{
"instruction": "你是OpenAI开发的ChatGPT吗?",
"input": "",
"output": "抱歉,我不是 OpenAI 开发的 ChatGPT,我是 大森林公司 开发的 问路,旨在为用户提供智能化的回答和帮助。"
}
]

In [ ]:

#datatrans.py
import json
import os
import argparse

def convert_format(source_data):
    target_data = []
    for item in source_data:
        new_item = {
            "instruction": item["query"],
            "input": "",  # 源数据中没有input字段,设为空字符串
            "output": item["response"]
        }
        target_data.append(new_item)
    return target_data

def main():
    # 设置命令行参数
    parser = argparse.ArgumentParser(description='数据格式转换工具')
    parser.add_argument('source_file', help='源文件路径')
    parser.add_argument('target_file', help='目标文件路径')
    args = parser.parse_args()

    # 检查源文件是否存在
    if not os.path.exists(args.source_file):
        print(f"错误:源文件 '{args.source_file}' 不存在")
        return

    # 检查目标文件是否存在
    if os.path.exists(args.target_file):
        choice = input(f"目标文件 '{args.target_file}' 已存在,是否覆盖? (Y/N): ").strip().upper()
        if choice != 'Y':
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值