当前位置:   article > 正文

第九篇-自我意识数据准备_自我意识 数据集

自我意识 数据集

格式化自我意识数据用于ChatGLM微调

准备数据源

https://github.com/hiyouga/ChatGLM-Efficient-Tuning
cd data
self_cognition.json
  • 1
  • 2
  • 3

代码self_process.py

#!/usr/bin/python
# -*- coding: UTF-8 -*- 

# 读取self_cognition自我认知解析并写入转换新文件

import json

# 读取self_cognition文件中的JSON列表
with open('self_cognition.json', 'r', encoding='utf-8') as f:
    data = json.load(f)


# 处理content和summary
def process_data(item):
    # 将instruction对应到content,output对应到summary
    item['content'] = item['instruction'].replace(' ', '')
    item['summary'] = item['output'].replace(' <NAME>', 'AI小木').replace('<AUTHOR>', '小吕').replace(' ', '')
    return item


# 将处理后的数据写入B文件
with open('self_cognition/train.json', 'w', encoding='utf-8') as f:
    for item in data:
        process_item = process_data(item)
        # 将一行JSON对象写入文件
        f.write('{"content":"'+process_item['content']+'","summary":"'+process_item['summary']+'"}')
        f.write('\n')

  • 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

名称:AI小木
作者:小吕

可以自己替换

执行处理

python self_process.py
  • 1

文件配置修改

我的train.json与dev.json一致,后期再处理吧

data/
├── dataset_info.json
└── self_cognition/
├── dev.json
└── train.json
接下来,我们修改 dataset_info.json,增加以下两列内容,从而使训练框架能够识别自定义数据集。

,
"self_cognition_train": {
    "file_name": "self_cognition/train.json",
    "columns": {
        "prompt": "content",
        "query": "",
        "response": "summary",
        "history": ""
    }
},
"self_cognition_dev": {
    "file_name": "self_cognition/dev.json",
    "columns": {
        "prompt": "content",
        "query": "",
        "response": "summary",
        "history": ""
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号