Skip to main content

A universal metric for Generative Large Language Models (GLLMs)

Project description

ANLS ★

🌟 A Universal Metric for Generative Large Language Models 🌟

arXiv Unit Tests

@misc{anls_star,
    title={ANLS* -- A Universal Document Processing Metric for Generative Large Language Models}, 
    author={David Peer and Philemon Schöpf and Volckmar Nebendahl and Alexander Rietzler and Sebastian Stabinger},
    year={2024},
    eprint={2402.03848},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}

How to use the ANLS* score?

  1. pip install anls_star
  2. Add to your code
from anls_star import anls_score
anls = anls_score("Hello World", "Hello Wrld")
print(anls)
  1. Thats it!

Supported Types

Simply copy this file to your project and import the anls_score function from it. Then call the function with the ground truth and the predictions.

The following types (and all combinations of it) are supported:

  • String: To compare strings against each other using the normalized Levenshtein similarity.
  • None: Sometimes questions are not answerable. With this type it can be checked, whether the model does not answer. Any answer other than None will be penalized. On the other hand, if a model generates e.g. a None key in a dictionary that is not in the ground truth, ANLS* ignores it rather than penalizing or rewarding it.
  • Tuple: Compare the given answer with each element in the tuple and select the element that produces the maximum ANLS* score. This is also provided by the classical ANLS metric.
  • List: Sometimes it is required to information in the form of lists from a document. For example, extracting all purchased items found in an invoice. While the order is not important, the list should contain all items. Note that the same item can occur multiple times in lists. Hungarian matching is used to compare the ground truth and the predicted list against each other. Both missing elements as well as hallucinated elements are penalized as previously introduced.
  • Dict: For document information extraction it is usually required to extract key-value pairs. For example, when extracting the date and total value from an invoice. Missing keys as well as hallucinated keys are penalized.

Benchmarks

The following table shows the ANLS* score for the different models and prompt methods on different datasets. Note that we evaluate the models and prompt methods on 100 samples for single page datasets and 20 samples for multi page datasets in order to reduce the execution time and costs. Note that the provided validation set is used for the report.

table

How To Execute

  1. Install all dependencies via pip install -r requirements_dev.txt
  2. Setup the keys
  • OpenAI: Ensure that your OpenAI API key is set as environment variable OPENAI_API_KEY.
  • Gemini: Ensure that your VertexAI setup is correct in case you wanna benchmark gemini-pro too.
  • Mistral: Setup the MISTRAL_API_KEY env variable as well as MISTRAL_ENDPOINT (Azure)
  • Anthropic: Setup the ANTHROPIC_API_KEY env variable
  1. Download all datasets - the download link is provided when executing the benchmark script for the first time. Please note that the datasets folder should be on the same level as the repository folder.
  2. Execute the corresponding benchmark script. For example:
    python3 src/benchmark_doc_vqa.py "gpt-3.5-turbo-16k" "simple"

Note that we always benchmark the latest version of each model and report those values in the table above. In the paper, we additionally report the performance of intermediate versions of each model such as gpt-4-1106-preview and gpt-4-turbo-2024-04-09.

The following prompt methods are supported:

  • simple - Simple text concatenation after OCR with GooleOCR
  • latin - Method as introduced by Wang et al.
  • sft - DeepOpinion internal only
  • vision - If images should directly be used. Requires a model with vision capabilities e.g. gpt-4-vision
  1. The final ANLS* is shown on the console.

How to Execute all Unit Tests

To run all unit tests simply execute pytest

Packaging

See https://packaging.python.org/en/latest/tutorials/packaging-projects/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anls_star-0.0.9.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

anls_star-0.0.9-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file anls_star-0.0.9.tar.gz.

File metadata

  • Download URL: anls_star-0.0.9.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for anls_star-0.0.9.tar.gz
Algorithm Hash digest
SHA256 0eb455138129fdc1e2b9807859ae3815ccdd83548f38f5cf967a3d663010d57c
MD5 860d10ea9ea8fcc46050379d76e1d65b
BLAKE2b-256 20eeaf1949b41a508608ca2976455b1c5f70e0d0a16b0248b3908a1486c75380

See more details on using hashes here.

File details

Details for the file anls_star-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: anls_star-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for anls_star-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 db7cabb64611d7401830055dc0ee5a754461c0290ff167a95b8b7897b78fa9f1
MD5 5101cfd87efeca7f76e331e4f0d4cc7b
BLAKE2b-256 bd639d5cc3d77756418849b5290ad4806ee3c118d06f7934873cb87fe2cee093

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page