💡 本文会带给你
- 认识alpaca指令监督微调数据集
- 如何构建自定义数据集
- 学会使用LLamFactory 进行LoRA微调大模型
- 掌握大模型转换为GGUF的方法
- 轻松使用 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':