马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
之前我也碰到过这样的错误就是在LLAMA-Factory微调chatglm3-6b时报错KeyError: ‘instruction‘。那时间是因为数据现存在少部分格式不同,这才导致KeyError: 'instruction'错误。
但是候来又碰到了KeyError: ‘instruction‘,但这次没有格式不同的问题。
究其原因,LLAMA-Factory只能担当特定格式的数据集
- {
- "instruction": "描述面向对象编程(OOP)的原则。",
- "input": "OOP 原则包括封装、继承、多态和抽象,促进了有组织和可维护的代码。",
- "output": "输出评价:你对面向对象编程的原则有很好的理解。在你的开发经验中,这些原则是如何指导你编写代码的?"
- }
复制代码 其中,instruction这些叫什么不重要,重要的是要在LLAMA-Factory的data文件夹下的dataset_info.json中注册这个数据集,同时要形貌映射关系(这里是关键,llama-factory现实使用的是prompt,query这些键,你要形貌instruction对应的是promot(即提示),还是query(问题)还是response(回复))
- "self_cognition": {
- "file_name": "self_cognition.json", #你数据集的名字
- "file_sha1": "eca3d89fa38b35460d6627cefdc101feef507eb5",#这是生成的独特编码
- "columns": {
- "prompt": "instruction", #映射关系的描述
- "query": "input",
- "response": "output",
- "history": "history"#有就加上,没有就不加
- }
- }
复制代码 这样注册了就不会报错了。
附上生成独特编码的代码
- import hashlib
- def calculate_sha1(file_path):
- sha1 = hashlib.sha1()
- try:
- with open(file_path, 'rb') as file:
- while True:
- data = file.read(8192) # Read in chunks to handle large files
- if not data:
- break
- sha1.update(data)
- return sha1.hexdigest()
- except FileNotFoundError:
- return "File not found."
-
- # 使用示例
- file_path = 'test3.json' # 替换为您的文件路径
- sha1_hash = calculate_sha1(file_path)
- print("SHA-1 Hash:", sha1_hash)
复制代码 ps:往期回首python划分数据集时出现KeyError: ‘instruction‘错误
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |