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),但是集合中的元素必须是可哈希的(hashable),而字典(dict)是不可哈希的类型。从你的代码来看,
eval_res很可能是一个字典类型,当你试图把它放入集合中时就会出现 "unhashable type: 'dict'" 的错误。解决方案:
如果你想要保存多个结果,应该使用列表或元组,而不是集合:
python# 使用列表 data_to_save = [eval_res, Test_eval] # 或者使用元组 data_to_save = (eval_res, Test_eval) # 或者使用字典来组织数据(推荐) data_to_save = { 'eval_res': eval_res, 'test_eval': Test_eval }为什么会出现这个错误:
{}创建的是集合(set),集合要求所有元素都是可哈希的
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.