Spaces:
Sleeping
Sleeping
from dataclasses import dataclass | |
from enum import Enum | |
class Task: | |
benchmark: str | |
metric: str | |
col_name: str | |
class Tasks(Enum): | |
# task_key in the json file, metric_key in the json file, name to display in the leaderboard | |
hallucination_rate = Task("hallucination_rate", | |
"hallucination_rate", "Humanlike Score (%)") | |
# factual_consistency_rate = Task("factual_consistency_rate", "factual_consistency_rate", "Factual Consistency Rate (%)") | |
# answer_rate = Task("answer_rate", "answer_rate", "Answer Rate (%)") | |
# average_summary_length = Task("average_summary_length", | |
# "average_summary_length", "Average Summary Length") | |
# Your leaderboard name | |
TITLE = """<h1 align="center" id="space-title">Humanlike Evaluation Model (HEM) leaderboard</h1>""" | |
# What does your leaderboard evaluate? | |
INTRODUCTION_TEXT = """ | |
This leaderboard (by [Vectara](https://vectara.com)) evaluates how often an LLM introduces hallucinations when summarizing a document. <br> | |
The leaderboard utilizes [HHEM](https://huggingface.co/vectara/hallucination_evaluation_model), an open source hallucination detection model.<br> | |
An improved version (HHEM v2) is integrated into the [Vectara platform](https://console.vectara.com/signup/?utm_source=huggingface&utm_medium=space&utm_term=integration&utm_content=console&utm_campaign=huggingface-space-integration-console). | |
""" | |
# Which evaluations are you running? how can people reproduce what you have? | |
LLM_BENCHMARKS_TEXT = """ | |
## Introduction | |
This study aims to compare the similarities between human and model responses in language use by employing ten psycholinguistic tasks. Each task consists of multiple stimuli, with each stimulus having both expected and unexpected responses. | |
To quantify the similarity, we collected responses from 2000 human participants, creating a binomial distribution for each stimulus within each task. The same stimuli were then presented to a language model, generating another binomial distribution for comparison. | |
## How it works | |
To measure the similarity between human and model responses, we utilize the Jensen-Shannon (JS) divergence. This method allows us to compare the two binomial distributions (one from human responses and one from model responses) for each stimulus. | |
The similarity is quantified by calculating 1 minus the JS divergence, where a value closer to 1 indicates higher similarity. | |
## Evaluation Dataset | |
Our evaluation dataset consists of 1006 documents from multiple public datasets, primarily [CNN/Daily Mail Corpus](https://huggingface.co/datasets/cnn_dailymail/viewer/1.0.0/test). | |
We generate summaries for each of these documents using submitted LLMs and compute hallucination scores for each pair of document and generated summary. (Check the prompt we used [here](https://huggingface.co/spaces/vectara/Hallucination-evaluation-leaderboard)) | |
## Metrics Explained | |
- Individual Task Similarity: For each psycholinguistic task, we calculate the humanlike score for each stimulus, providing a measure of how closely the model’s responses resemble those of humans. | |
- Average Similarity: The average of the humanlike scores across all stimuli and tasks, giving an overall indication of the model’s performance in mimicking human language use. | |
## Note on non-Hugging Face models | |
On HHEM leaderboard, There are currently models such as GPT variants that are not available on the Hugging Face model hub. We ran the evaluations for these models on our own and uploaded the results to the leaderboard. | |
If you would like to submit your model that is not available on the Hugging Face model hub, please contact us at [email protected]. | |
## Model Submissions and Reproducibility | |
You can submit your model for evaluation, whether it's hosted on the Hugging Face model hub or not. (Though it is recommended to host your model on the Hugging Face) | |
### For models available on the Hugging Face model hub: | |
To replicate the evaluation result for a Hugging Face model: | |
1) Clone the Repository | |
```python | |
git lfs install | |
git clone https://huggingface.co/spaces/Simondon/HumanLikeness | |
``` | |
2) Install the Requirements | |
```python | |
pip install -r requirements.txt | |
``` | |
3) Set Up Your Hugging Face Token | |
```python | |
export HF_TOKEN=your_token | |
``` | |
4) Run the Evaluation Script | |
```python | |
python main_backend.py --model your_model_id --precision float16 | |
``` | |
5) Check Results | |
After the evaluation, results are saved in "eval-results-bk/your_model_id/results.json". | |
## Results Format | |
The results are structured in JSON as follows: | |
```python | |
{ | |
"config": { | |
"model_dtype": "float16", | |
"model_name": "your_model_id", | |
"model_sha": "main" | |
}, | |
"results": { | |
"hallucination_rate": { | |
"hallucination_rate": ... | |
}, | |
"factual_consistency_rate": { | |
"factual_consistency_rate": ... | |
}, | |
"answer_rate": { | |
"answer_rate": ... | |
}, | |
"average_summary_length": { | |
"average_summary_length": ... | |
} | |
} | |
} | |
``` | |
For additional queries or model submissions, please contact [email protected]. | |
""" | |
EVALUATION_QUEUE_TEXT = """ | |
## Some good practices before submitting a model | |
### 1) Make sure you can load your model and tokenizer using AutoClasses: | |
```python | |
from transformers import AutoConfig, AutoModel, AutoTokenizer | |
config = AutoConfig.from_pretrained("your model name", revision=revision) | |
model = AutoModel.from_pretrained("your model name", revision=revision) | |
tokenizer = AutoTokenizer.from_pretrained("your model name", revision=revision) | |
``` | |
If this step fails, follow the error messages to debug your model before submitting it. It's likely your model has been improperly uploaded. | |
Note: make sure your model is public! | |
Note: if your model needs `use_remote_code=True`, we do not support this option yet but we are working on adding it, stay posted! | |
### 2) Convert your model weights to [safetensors](https://huggingface.co/docs/safetensors/index) | |
It's a new format for storing weights which is safer and faster to load and use. It will also allow us to add the number of parameters of your model to the `Extended Viewer`! | |
### 3) Make sure your model has an open license! | |
This is a leaderboard for Open LLMs, and we'd love for as many people as possible to know they can use your model 🤗 | |
### 4) Fill up your model card | |
When we add extra information about models to the leaderboard, it will be automatically taken from the model card | |
## In case of model failure | |
If your model is displayed in the `FAILED` category, its execution stopped. | |
Make sure you have followed the above steps first. | |
""" | |
CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results" | |
CITATION_BUTTON_TEXT = r""" | |
@dataset{HughesBae2023, | |
author = {Simon Hughes and Minseok Bae}, | |
title = {Vectara Hallucination Leaderboard}, | |
year = {2023}, | |
month = {11}, | |
publisher = {Vectara, Inc}, | |
doi = {}, | |
url = {https://github.com/vectara/hallucination-leaderboard}, | |
abstract = {A leaderboard comparing LLM performance at maintaining factual consistency when summarizing a set of facts.}, | |
keywords = {nlp, llm, hallucination, nli, machine learning}, | |
license = {Apache-2.0}, | |
}""" |