Source code for the LUNA project
Project description
LUNA: a Framework for Language Understanding and Naturalness Assessment
The framework provides a set of well-known automated evaluation metrics for text generation tasks.
The library includes the following metrics:
- Blanc: paper
- Mover score: paper
- BLEU: paper
- METEOR: paper
- ROUGE: paper
- chrF: paper
- BERTScore: paper
- BARTScore: paper
- Data statistics metrics: paper
- Compression
- Coverage
- Length
- Novelty
- Density
- Repetition
- ROUGE-We: paper
- S3: paper
- BaryScore: paper
- DepthScore: paper
- InfoLM: paper
Installation
Installation from PyPI
Install it via pip
:
pip install luna-nlg
Installation from the source
Clone the repository and install the library from the root:
git clone https://github.com/Moonlight-Syntax/LUNA.git
pip install .
Another way is to use poetry
. Then, run poetry install
from the root.
Quick start
The user can either trigger the Calculator
to evaluate metrics or integrate the code itself.
Calculator
The easiest way to evaluate NLG models is to execute the following snippet:
from luna.calculate import Calculator
# Choose to compute in a sequential or a parallel setting
calculator = Calculator(execute_parallel=True)
metrics_dict = calculator.calculate(
metrics=[depth_score, s3_metrics], # both are LUNA's metrics
candidates=candidates,
references=references
)
print(metrics_dict)
>>> {"DepthScore": ..., "S3": ...}
Integrate the evaluations
All the metrics in the library follow the same interface:
class Metrics:
def evaluate_batch(self, hypothesyses: List[str], references: Optional[List[str]]) -> List[float]:
*some code here*
def evaluate_example(self, hypothesys: str, reference: Optional[str]) -> float:
*some code here*
Thus, to evaluate your examples run the following code:
from luna import MetricName
metric = MetricName()
result = metric.evaluate_example("Generated bad model by example", "Gold example")
results = metric.evaluate_batch(["Generated bad model by example 1", "Generated bad model by example 2"],
["Gold example 1", "Gold example 2"])
You may find more examples here: examples/metrics.ipynb
or in the tests.
Development
Contribute to the library
We are open for issues and pull requests. We hope that LUNA's functionality is wide enough but we believe that it can always be elaborated and improved.
Pre-commit hooks
We use pre-commit hooks to check the code before commiting.
To install the hooks run the following:
pip install pre-commit
pre-commit install
After that every commit will trigger standard checks on code style, including black
, isort
etc.
Tests
Tests for luna
are located in the tests
directory. To run them, execute:
pytest tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file luna_nlg-1.0.0.tar.gz
.
File metadata
- Download URL: luna_nlg-1.0.0.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.8 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 681c52aeb3885406457a937cc532a46dfdddc9af9a19ed7cdbcf5f2ba95f6e7d |
|
MD5 | 2cca75deab1d3c4089d858ca6ede3806 |
|
BLAKE2b-256 | 04e407e4c8f1c60a184bdce47c0f2bf5ed3b49ed3da88ee40aa73ac09f6338a6 |
File details
Details for the file luna_nlg-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: luna_nlg-1.0.0-py3-none-any.whl
- Upload date:
- Size: 43.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.8 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 588be2a242d98b9f07eecf6d83faf695bde5c907617571258326139725c0ba06 |
|
MD5 | 037e135edf94d909aa818d5d2ba39247 |
|
BLAKE2b-256 | 61222ac7b14d36cf94e2dd3f9a7eecc31e9f2428de37bb84ced32a9b9a1bf049 |