Skip to main content

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:

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


Download files

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

Source Distribution

luna_nlg-1.0.0.tar.gz (33.7 kB view hashes)

Uploaded Source

Built Distribution

luna_nlg-1.0.0-py3-none-any.whl (43.3 kB view hashes)

Uploaded Python 3

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