A universal metric for Generative Large Language Models (GLLMs)
Actively maintained. Last release 3 weeks ago, commits in 13 of the last 26 weeks. A safe choice.
pip install anls-starANLS ★
🌟 A Universal Metric for Generative Large Language Models 🌟 Now with benchmarks for gpt-4.5 preview as well as claude-37 and llama-3.1-405B
@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?
pip install anls_star- Add to your code
from anls_star import anls_score
anls = anls_score("Hello World", "Hello Wrld")
print(anls)
- Thats it!
Returning the closest match
The anls_score function can also be used to return the object which best matches the prediction and can be derived from the ground truth by re-ordering lists, selecting options from tuples etc. by setting the return_gt argument to True (default is False).
As an example:
gt = {"a": ("hello", "world"), "b": ["this", "is", "a", "test"]}
pred = {"a": "hello!", "b": ["a", "test", "this", "be"]}
score, closest_gt = anls_score(gt, pred, return_gt=True)
# score = 0.766...
# closest_gt = {'a': 'hello', 'b': ['a', 'test', 'this', 'is']}
This result can then be used e.g. with the deepdiff package for further analysis:
from deepdiff import DeepDiff
diff = DeepDiff(closest_gt, pred)
# diff = {'values_changed': {"root['a']": {'new_value': 'hello!', 'old_value': 'hello'},
# "root['b'][3]": {'new_value': 'be', 'old_value': 'is'}}}
Returning key scores
The anls_score function can also return a dictionary containing aggregated ANLS* scores for dictionary keys in the ground truth and prediction. This is useful for gaining insights into what parts of the predictions are correct and what parts are incorrect. To use this feature, set the argument to .
