Huggingface Evaluate包使用小坑

准备使用evaluate进行模型效果的统计,按照相关参考资料

pip install evaluate

这一步没有什么问题,于是运行简单示例测试:

import evaluate

metric_name = 'accuracy'
accuracy = evaluate.load(metric_name)
result = accuracy.compute(references=[0,1,0,1], predictions=[1,0,0,1])

print(result)

 发现一直卡在 load 迟迟没有结果,控制台也没有显示任何错误,经过逐步 debug 找到问题所在。

首先根据官方的说明

'''
path (str): Path or name of the metric script.

    - if ``path`` is a local metric script or a directory containing a local metric script (if the script has the same name as the directory):
      -> load the module from the metric script
      e.g. ``'./metrics/accuracy'`` or ``'./metrics/accuracy/accuracy.py'``.
    - if ``path`` is a metric on the Hugging Face Hub (ex: `glue`, `squad`)
      -> load the module from the metric script in the github repository at huggingface/datasets
      e.g. ``'accuracy'`` or ``'rouge'``.
'''

如果直接使用指标名称“accuracy”等,程序将会从 huggingface 上下载相应模块到缓存中使用,实际上我的问题就是无法顺利下载【HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /spaces/evaluate-metric/accuracy/resolve/v0.4.0/accuracy.py (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1059: The handshake operation timed out')))】(这个错误不会显示ヽ(`Д´)ノ)

因此只能将相关文件下载到本地,采用 local metric script 方法:

打开官方Github GitHub - huggingface/evaluate: 🤗 Evaluate: A library for easily evaluating machine learning models and datasets. 下载 metrics 文件夹,放在测试脚本的目录下,将'accuracy' 改为 './metrics/accuracy',再次运行文件即可得到正确结果

{'accuracy': 0.5}

  • 43
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值