gomate-community/rageval

Evaluation tools for Retrieval-augmented Generation (RAG) methods.

Python

172

395 commits

updated Nov 18, 2024

See the code

README

Rageval

Evaluation tools for Retrieval-augmented Generation (RAG) methods.

python workflow status codecov pydocstyle PEP8

Rageval is a tool that helps you evaluate RAG system. The evaluation consists of six sub-tasks, including query rewriting, document ranking, information compression, evidence verify, answer generating, and result validating.

Definition of tasks and metrics

1. The generate task

The generate task is to answer the question based on the contexts provided by retrieval modules in RAG. Typically, the context could be extracted/generated text snippets from the compressor, or relevant documents from the re-ranker. Here, we divide metrics used in the generate task into two categories, namely answer correctness and answer groundedness.

(1) Answer Correctness: this category of metrics is to evaluate the correctness by comparing the generated answer with the groundtruth answer. Here are some commonly used metrics:

(2) Answer Groundedness: this category of metrics is to evaluate the groundedness (also known as factual consistency) by comparing the generated answer with the provided contexts. Here are some commonly used metrics:

2. The rewrite task

The rewrite task is to reformulate user question into a set of queries, making them more friendly to the search module in RAG.

3. The search task

The search task is to retrieve relevant documents from the knowledge base.

(1) Context Adequacy: this category of metrics is to evaluate the adequacy by comparing the retrieved documents with the groundtruth contexts. Here are some commonly used metrics:

(2) Context Relevance: this category of metrics is to evaluate the relevance by comparing the retrieved documents with the groundtruth answers. Here are some commonly used metrics:

Setup Evaluator LLMs

Some metrics evaluations rely on LLMs as evaluators. You can either directly call OpenAI's API or deploy an open-source model as a RESTful API in the OpenAI format for evaluation.

  • OpenAI
os.environ["OPENAI_API_KEY"] = "<your_openai_api_key>"
  • Open source LLMs

Please use vllm to setup the API server for open source LLMs. For example, use the following command to deploy a Llama-3-8B model hosted on HuggingFace:

python -m vllm.entrypoints.openai.api_server \
  --model meta-llama/Meta-Llama-3-8B-Instruct \
  --tensor-parallel-size 8 \
  --dtype auto \
  --api-key sk-123456789 \
  --gpu-memory-utilization 0.9 \
  --port 5000

Benchmark Results

1. ASQA benchmark

ASQA dataset is a question-answering dataset that contains factoid questions and long-form answers. The benchmark evaluates the correctness of the answer in the dataset. All detailed results can be download from this repo. Besides, these results can be reproduced based on the script in this repo.

ModelRetrieverMetric
String EMRouge LDisambig F1D-R Score
gpt-3.5-turbo-instructno-retrieval33.830.230.730.5
mistral-7bno-retrieval20.631.126.628.7
llama2-7b-chatno-retrieval21.730.728.029.3
llama3-8b-baseno-retrieval25.731.028.429.7
llama3-8b-instructno-retrieval27.130.929.430.1
solar-10.7b-instructno-retrieval23.024.928.126.5

2. ALCE Benchmark

ALCE is a benchmark for Automatic LLMs' Citation Evaluation. ALCE contains three datasets: ASQA, QAMPARI, and ELI5. All detailed results can be download from this repo. Besides, these results can be reproduced based on the script in this repo.

For more evaluation results, please view the benchmark's README: ALCE-ASQA and ALCE-ELI5.

DatasetModelMethodMetric
retrieverpromptMAUVEEM RecallClaim RecallCitation RecallCitation Precision
ASQAllama2-7b-chatGTRvanilla(5-psg)-33.3-55.980.0
DPRvanilla(5-psg)-29.2-49.281.0
Oraclevanilla(5-psg)-41.7-58.178.9
ELI5llama2-7b-chatBM25vanilla(5-psg)--11.526.674.5
Oraclevanilla(5-psg)--17.834.075.6

Installation

git clone https://github.com/gomate-community/rageval.git
cd rageval
python setup.py install

Usage

1. Metric

Take F1 as an example.

from datasets import Dataset
import rageval as rl

sample = {
    "answers": [
        "Democrat rick kriseman won the 2016 mayoral election, while re- publican former mayor rick baker did so in the 2017 mayoral election."
    ],
    "gt_answers": [
        [
            "Kriseman",
            "Rick Kriseman"
        ]
    ]
}
dataset = Dataset.from_dict(sample)
metric = rl.metrics.AnswerF1Correctness()
score, dataset = metric.compute(dataset)

2. Benchmark

Benchmarks can be run directly using scripts (Take ALCE-ELI5 as an example).

bash benchmarks/ALCE/ELI5/run.sh

Contribution

Please make sure to read the Contributing Guide before creating a pull request.

About

This project is currently at its preliminary stage.

evalution
llm
rag

gomate-community/rageval

Evaluation tools for Retrieval-augmented Generation (RAG) methods.

Python

172

395 commits

updated Nov 18, 2024

See the code

README

Rageval

Evaluation tools for Retrieval-augmented Generation (RAG) methods.

python workflow status codecov pydocstyle PEP8

Rageval is a tool that helps you evaluate RAG system. The evaluation consists of six sub-tasks, including query rewriting, document ranking, information compression, evidence verify, answer generating, and result validating.

Definition of tasks and metrics

1. The generate task

The generate task is to answer the question based on the contexts provided by retrieval modules in RAG. Typically, the context could be extracted/generated text snippets from the compressor, or relevant documents from the re-ranker. Here, we divide metrics used in the generate task into two categories, namely answer correctness and answer groundedness.

(1) Answer Correctness: this category of metrics is to evaluate the correctness by comparing the generated answer with the groundtruth answer. Here are some commonly used metrics:

(2) Answer Groundedness: this category of metrics is to evaluate the groundedness (also known as factual consistency) by comparing the generated answer with the provided contexts. Here are some commonly used metrics:

2. The rewrite task

The rewrite task is to reformulate user question into a set of queries, making them more friendly to the search module in RAG.

3. The search task

The search task is to retrieve relevant documents from the knowledge base.

(1) Context Adequacy: this category of metrics is to evaluate the adequacy by comparing the retrieved documents with the groundtruth contexts. Here are some commonly used metrics:

(2) Context Relevance: this category of metrics is to evaluate the relevance by comparing the retrieved documents with the groundtruth answers. Here are some commonly used metrics:

Setup Evaluator LLMs

Some metrics evaluations rely on LLMs as evaluators. You can either directly call OpenAI's API or deploy an open-source model as a RESTful API in the OpenAI format for evaluation.

  • OpenAI
os.environ["OPENAI_API_KEY"] = "<your_openai_api_key>"
  • Open source LLMs

Please use vllm to setup the API server for open source LLMs. For example, use the following command to deploy a Llama-3-8B model hosted on HuggingFace:

python -m vllm.entrypoints.openai.api_server \
  --model meta-llama/Meta-Llama-3-8B-Instruct \
  --tensor-parallel-size 8 \
  --dtype auto \
  --api-key sk-123456789 \
  --gpu-memory-utilization 0.9 \
  --port 5000

Benchmark Results

1. ASQA benchmark

ASQA dataset is a question-answering dataset that contains factoid questions and long-form answers. The benchmark evaluates the correctness of the answer in the dataset. All detailed results can be download from this repo. Besides, these results can be reproduced based on the script in this repo.

ModelRetrieverMetric
String EMRouge LDisambig F1D-R Score
gpt-3.5-turbo-instructno-retrieval33.830.230.730.5
mistral-7bno-retrieval20.631.126.628.7
llama2-7b-chatno-retrieval21.730.728.029.3
llama3-8b-baseno-retrieval25.731.028.429.7
llama3-8b-instructno-retrieval27.130.929.430.1
solar-10.7b-instructno-retrieval23.024.928.126.5

2. ALCE Benchmark

ALCE is a benchmark for Automatic LLMs' Citation Evaluation. ALCE contains three datasets: ASQA, QAMPARI, and ELI5. All detailed results can be download from this repo. Besides, these results can be reproduced based on the script in this repo.

For more evaluation results, please view the benchmark's README: ALCE-ASQA and ALCE-ELI5.

DatasetModelMethodMetric
retrieverpromptMAUVEEM RecallClaim RecallCitation RecallCitation Precision
ASQAllama2-7b-chatGTRvanilla(5-psg)-33.3-55.980.0
DPRvanilla(5-psg)-29.2-49.281.0
Oraclevanilla(5-psg)-41.7-58.178.9
ELI5llama2-7b-chatBM25vanilla(5-psg)--11.526.674.5
Oraclevanilla(5-psg)--17.834.075.6

Installation

git clone https://github.com/gomate-community/rageval.git
cd rageval
python setup.py install

Usage

1. Metric

Take F1 as an example.

from datasets import Dataset
import rageval as rl

sample = {
    "answers": [
        "Democrat rick kriseman won the 2016 mayoral election, while re- publican former mayor rick baker did so in the 2017 mayoral election."
    ],
    "gt_answers": [
        [
            "Kriseman",
            "Rick Kriseman"
        ]
    ]
}
dataset = Dataset.from_dict(sample)
metric = rl.metrics.AnswerF1Correctness()
score, dataset = metric.compute(dataset)

2. Benchmark

Benchmarks can be run directly using scripts (Take ALCE-ELI5 as an example).

bash benchmarks/ALCE/ELI5/run.sh

Contribution

Please make sure to read the Contributing Guide before creating a pull request.

About

This project is currently at its preliminary stage.

evalution
llm
rag

Significant stargazers

Jiejun Tan

63 followers · starred Apr 2024