datatosave = { evalres, Testeval # 假设 testeval 是你想要添加的新结果 }…
- User
data_to_save = { eval_res, Test_eval # 假设 test_eval 是你想要添加的新结果 } pkl_save(f'{run_dir}/eval_res_{args.dist_type}.pkl', data_to_save) 这种编写方式出现了这样的错误: Traceback (most recent call last): File "train.py", line 235, in data_to_save = { TypeError: unhashable type: 'dict' 这是为什么
Assistant
这个错误是因为你在尝试创建一个集合(set)或字典(dict)时,使用了不可哈希(unhashable)的对象。在 Python 中,字典(dict)是不能直接作为集合或字典的元素的。
正确的写法应该是使用字典(dictionary)来保存数据:
data_to_save = { 'eval_res': eval_res, 'Test_eval': Test_eval } pkl_save(f'{run_dir}/eval_res_{args.dist_type}.pkl', data_to_save)主要的修改点:
- 将
{eval_res, Test_eval}改为{'eval_res': eval_res, 'Test_eval': Test_eval} - 使用键值对的方式存储数据
- 这样可以确保数据被正确地打包到字典中
这种方式可以确保:
- 数据被正确地组织
- 可以通过键名访问各个结果
- 避免了不可哈希类型的错误
如果
eval_res或Test_eval本身是字典,这种写法尤其重要。- 将
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.