Skip to main content

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

Metadata

Release files for luna-nlg 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for luna-nlg 1.0.0
File Size Uploaded
luna_nlg-1.0.0.tar.gz 33.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for luna-nlg 1.0.0
File Interpreter ABI Platform
luna_nlg-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.1 kB

Release files / luna_nlg-1.0.0.tar.gz

Download URL luna_nlg-1.0.0.tar.gz
Size 33.7 kB
Tags Source
SHA-256 checksum
How to use checksums
681c52aeb3885406457a937cc532a46dfdddc9af9a19ed7cdbcf5f2ba95f6e7d
BLAKE2b-256 checksum
How to use checksums
04e407e4c8f1c60a184bdce47c0f2bf5ed3b49ed3da88ee40aa73ac09f6338a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.8 Darwin/22.5.0

Release files / luna_nlg-1.0.0-py3-none-any.whl

Download URL luna_nlg-1.0.0-py3-none-any.whl
Size 43.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
588be2a242d98b9f07eecf6d83faf695bde5c907617571258326139725c0ba06
BLAKE2b-256 checksum
How to use checksums
61222ac7b14d36cf94e2dd3f9a7eecc31e9f2428de37bb84ced32a9b9a1bf049
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.8 Darwin/22.5.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page