跳转到主要内容

检索增强指令跟随模型的实证评估。

项目描述

评估问答指令跟随模型的正确性和忠实度

arXiv License PyPi

快速开始

安装

确保您已安装Python 3.7+。使用虚拟环境也是一个好主意。

显示创建虚拟环境的说明
python3 -m venv instruct-qa-venv
source instruct-qa-venv/bin/activate

您可以通过pip安装此库

# Install the latest release
pip3 install instruct-qa

# Install the latest version from GitHub
pip3 install git+https://github.com/McGill-NLP/instruct-qa

对于开发,您可以使用以下命令以可编辑模式安装:

git clone https://github.com/McGill-NLP/instruct-qa
cd instruct-qa/
pip3 install -e .

用法

以下是一个简单的示例,以开始使用。使用此库,您可以在大约25行代码中轻松利用检索增强的问答模型。此示例的源文件是examples/get_started.py

from instruct_qa.collections.utils import load_collection
from instruct_qa.retrieval.utils import load_retriever, load_index
from instruct_qa.prompt.utils import load_template
from instruct_qa.generation.utils import load_model
from instruct_qa.response_runner import ResponseRunner

collection = load_collection("dpr_wiki_collection")
index = load_index("dpr-nq-multi-hnsw")
retriever = load_retriever("facebook-dpr-question_encoder-multiset-base", index)
model = load_model("flan-t5-xxl")
prompt_template = load_template("qa")

queries = ["what is haleys comet"]

runner = ResponseRunner(
    model=model,
    retriever=retriever,
    document_collection=collection,
    prompt_template=prompt_template,
    queries=queries,
)

responses = runner()
print(responses[0]["response"])
# Halley's Comet Halley's Comet or Comet Halley, officially designated 1P/Halley, is a short-period comet visible from Earth every 75–76 years. Halley is the only known short-period comet that is regularly visible to the naked eye from Earth, and the only naked-eye comet that might appear twice in a human lifetime. Halley last appeared...

您还可以检查提供给指令跟随模型的输入提示,其中包含指令和检索到的段落。

print(responses[0]["prompt"])
"""
Please answer the following question given the following passages:
- Title: Bill Haley
then known as Bill Haley's Saddlemen...

- Title: C/2016 R2 (PANSTARRS)
(CO) with a blue coma. The blue color...

...

Question: what is haleys comet
Answer:
"""

有关库中不同模块的详细文档,请在此处查看

为整个数据集生成响应

我们的库支持问答(QA)和对话问答(ConvQA)数据集。以下数据集目前包含在库中

以下是一个使用DPR检索器和Flan-T5生成器为自然问题生成响应的示例。

python experiments/question_answering.py \
--prompt_type qa \
--dataset_name natural_questions \
--document_collection_name dpr_wiki_collection \
--index_name dpr-nq-multi-hnsw \
--retriever_name facebook-dpr-question_encoder-multiset-base \
--batch_size 1 \
--model_name flan-t5-xxl \
--k 8

默认情况下,在存储库中创建一个用于存储模型响应的 results 目录。默认目录位置可以通过提供额外的命令行参数 --persistent_dir <OUTPUT_DIR> 来覆盖。更多示例可以在 示例 目录中找到。

下载模型响应和人工评估数据

我们发布了使用上述命令生成的所有三个数据集的模型响应。论文中报告的分数是基于这些响应的。可以使用以下命令下载响应

python download_data.py --resource results

响应将自动解压并存储在以下目录结构中的 JSON 行中

results
├── {dataset_name}
│   ├── response
│   │   ├── {dataset}_{split}_c-{collection}_m-{model}_r-{retriever}_prompt-{prompt}_p-{top_p}_t-{temperature}_s-{seed}.jsonl

目前包含以下模型

  • fid (Fusion-in-Decoder,在各个数据集上分别微调)
  • gpt-3.5-turbo (GPT-3.5)
  • alpaca-7b (Alpaca)
  • llama-2-7b-chat (Llama-2)
  • flan-t5-xxl (Flan-T5)

我们还发布了所有数据集的响应子集的正确性和忠实度的人工标注。可以使用以下命令下载标注

python download_data.py --resource human_eval_annotations

响应将自动解压到以下目录结构中

human_eval_annotations
├── correctness
│   ├── {dataset_name}
│   │   ├── {model}_human_eval_results.json
|
├── faithfulness
│   ├── {dataset_name}
│   │   ├── {model}_human_eval_results.json

评估模型响应(即将推出!)

评估模型响应和添加您自己的评估标准的文档即将推出!请保持关注!

许可

本作品受 Apache 2 许可证的许可。有关详细信息,请参阅 LICENSE

引用

要引用此工作,请使用以下引用

@article{adlakha2023evaluating,
      title={Evaluating Correctness and Faithfulness of Instruction-Following Models for Question Answering}, 
      author={Vaibhav Adlakha and Parishad BehnamGhader and Xing Han Lu and Nicholas Meade and Siva Reddy},
      year={2023},
      journal={arXiv:2307.16877},
}

联系

有关查询和澄清,请联系 vaibhav.adlakha (at) mila (dot) quebec

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

instruct-qa-0.0.2.tar.gz (40.8 kB 查看哈希)

上传

构建分布

instruct_qa-0.0.2-py3-none-any.whl (52.1 kB 查看哈希)

上传 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面