Skip to main content

🍐 PEAR: Pairwise Evaluation for Automatic Relative Scoring in Machine Translation

ACL 2026 ACL Anthology Hugging Face PyPI Python CI License Code style: black

This repository provides the inference toolkit for 🍐PEAR: Pairwise Evaluation for Automatic Relative Scoring in Machine Translation.

PEAR reframes reference-free machine translation evaluation as a graded pairwise comparison: given a source segment and two candidate translations, it predicts both the direction and magnitude of their quality difference. The toolkit also supports reference-anchored PEAR scoring and PEAR-based minimum Bayes risk (MBR) decoding.

Installation

PEAR supports Python 3.11, 3.12, and 3.13. Install the published package from PyPI:

python -m pip install pear-mt

The PyPI distribution is named pear-mt; the Python import package is named pear, and the primary command-line program is also pear:

import pear

To install from a local clone instead:

git clone https://github.com/prosho-97/pear.git
cd pear
python -m pip install .

For local development, install the development extra too:

python -m pip install -e ".[dev]"

Loading a model

import pear

metric = pear.load_metric("pear")       # resolves to Prosho/pear on Hugging Face
metric_xl = pear.load_metric("pear-xl") # resolves to Prosho/pear-xl on Hugging Face

You can also pass a Hugging Face repository ID or a local PEAR model checkpoint path:

metric = pear.load_metric("Prosho/pear")
metric = pear.load_metric("/path/to/checkpoints/model.ckpt")

Reproducible model revisions

The official pear and pear-xl aliases use checkpoint and encoder revisions pinned by this package. This keeps their results stable even when files on the Hugging Face Hub change.

The aliases and their full Prosho/pear and Prosho/pear-xl repository IDs load those immutable official snapshots as trusted Lightning checkpoints. PEAR therefore suppresses PyTorch's full-checkpoint deserialization warning for those exact revisions. Local checkpoints, third-party repositories, and revision overrides retain PyTorch's default security behavior.

For another Hugging Face repository, PEAR follows that repository's default branch unless you provide revisions explicitly. revision pins the PEAR checkpoint repository; encoder_revision pins the underlying Transformers encoder. A full commit hash gives the strongest reproducibility:

metric = pear.load_metric(
    "organization/custom-pear",
    revision="<checkpoint-commit>",
    encoder_revision="<encoder-commit>",
)

The same controls are available from the CLI:

pear score \
    --hf-model organization/custom-pear \
    --revision <checkpoint-commit> \
    --encoder-revision <encoder-commit> \
    --input pairs.tsv \
    --output scored.tsv

Passing either option overrides the corresponding default. Local checkpoint paths do not use a Hub checkpoint revision, although encoder_revision can still pin an encoder that the checkpoint configuration loads from the Hub.

Pairwise QE scoring

scores = pear.score_pairwise(
    metric,
    sources=["The cat is on the mat."],
    translations_a=["El gato está en la alfombra."],
    translations_b=["El gato está en el mapa."],
)

Positive scores mean translations_a is preferred over translations_b.

To score both candidate orders:

scores = pear.score_pairwise(
    metric,
    sources=["The cat is on the mat."],
    translations_a=["El gato está en la alfombra."],
    translations_b=["El gato está en el mapa."],
    mode="both",
)
# {"forward": [...], "reverse": [...]}

Reference-anchored scoring

Reference-anchored PEAR uses the human reference (or any other list of candidate translations) as the second candidate/anchor.

scores = pear.score_reference_anchored(
    metric,
    sources=["The cat is on the mat."],
    translations=["El gato está en la alfombra."],
    references=["El gato está sobre la alfombra."],
)

As with pairwise QE scoring, set mode="both" to score both candidate orders for reference-anchored inputs.

PEAR for MBR decoding

from pear.mbr import pear_utility_matrix, select_mbr_hypothesis

hyps = ["This is a good translation.", "This is a very good translation.", "This is a bad translation."]
utility = pear_utility_matrix(metric, "Questa è una traduzione molto buona.", hyps, mode="half")
index, expected_utility = select_mbr_hypothesis(utility)
best = hyps[index]
# best -> "This is a very good translation."

Use mode="full" to score all off-diagonal ordered pairs (N2 - N comparisons). Use mode="half" to score one triangular half and fill the opposite direction by PEAR antisymmetry.

Batching, devices, and progress bars

Python and CLI inference are batched. Use batch_size / --batch-size to control the number of pairwise examples per PEAR forward batch.

By default, PEAR uses:

gpus="auto"

This selects one available CUDA/MPS accelerator when present. Pass gpus=0 or --gpus 0 to force CPU. Progress bars are shown by default; in Python calls, control them with the progress_bar argument (progress_bar=True by default, or progress_bar=False to disable them).

CLI

Score a TSV file

Pairwise input TSV must contain src, mt_0, and mt_1 columns:

pear score --model pear --input pairs.tsv --output scored.tsv --batch-size 16
pear score --hf-model Prosho/pear --input pairs.tsv --output scored.tsv --batch-size 16
pear score --checkpoint /path/to/model.ckpt --input pairs.tsv --output scored.tsv --batch-size 16

Reference-anchored input TSV must contain src, mt, and ref columns:

pear score --model pear --mode reference --input refs.tsv --output scored.tsv --batch-size 16

Add --both to score both candidate orders.

Run MBR

Input JSONL rows must contain src and hypotheses:

{"src": "source text", "hypotheses": ["hyp A", "hyp B"]}

Run half- or full-matrix PEAR MBR:

pear mbr --model pear --input nbest.jsonl --output selected.jsonl --utility half --batch-size 16
pear mbr --hf-model Prosho/pear-xl --input nbest.jsonl --output selected.jsonl --utility full --batch-size 16
pear mbr --checkpoint /path/to/model.ckpt --input nbest.jsonl --output selected.jsonl --batch-size 16

Development

Install the development extra before running formatter checks:

python -m pip install -e ".[dev]"

Then run:

python -m black --check pear tests
python -m pytest
python -m compileall pear

Network tokenizer regressions use immutable encoder snapshots and run in CI against both Transformers 4.40.2 and the latest supported 5.x release. The multi-gigabyte checkpoint regression remains opt-in. Before creating a release tag, record its baseline under Transformers 4.40.2:

python -m pytest \
    tests/test_regressions.py::test_released_checkpoints_match_440_scores_and_key_mismatches \
    --run-checkpoint-integration \
    --write-checkpoint-baseline=/tmp/pear-checkpoints-4.40.2.json

Then, on the same hardware and dtype under the latest Transformers 5.x, compare against that file:

python -m pytest \
    tests/test_regressions.py::test_released_checkpoints_match_440_scores_and_key_mismatches \
    --run-checkpoint-integration \
    --checkpoint-baseline=/tmp/pear-checkpoints-4.40.2.json

The comparison requires the same checkpoint-key mismatch sets, finite scores, preference directions and rankings, and scores within rtol=1e-4 and atol=1e-4.

Citation

PEAR has been published at ACL 2026 (Main Conference). If you use it, please consider citing our paper as follows:

@inproceedings{proietti-etal-2026-pear,
    title = "{PEAR}: Pairwise Evaluation for Automatic Relative Scoring in Machine Translation",
    author = "Proietti, Lorenzo  and
      Grundkiewicz, Roman  and
      Post, Matt",
    editor = "Liakata, Maria  and
      Moreira, Viviane P.  and
      Zhang, Jiajun  and
      Jurgens, David",
    booktitle = "Proceedings of the 64th Annual Meeting of the {A}ssociation for {C}omputational {L}inguistics (Volume 1: Long Papers)",
    month = jul,
    year = "2026",
    address = "San Diego, California, United States",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2026.acl-long.1953/",
    doi = "10.18653/v1/2026.acl-long.1953",
    pages = "42189--42207",
    ISBN = "979-8-89176-390-6"
}

License

This project is released under the Apache License 2.0. See LICENSE for the full license text.

Download files

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

Source Distribution

pear_mt-1.1.0.tar.gz (38.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pear_mt-1.1.0-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file pear_mt-1.1.0.tar.gz.

File metadata

  • Download URL: pear_mt-1.1.0.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pear_mt-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fa9c2fea1e8e0e50305e1ec7073c25215419394209c79dfec47c403a83150baf
MD5 d10988025ee7ac6e22d619780e222247
BLAKE2b-256 d0f650cdcde811ad2f2a9276a1ab3a896b40c61973fd828208527a54d7e63ba9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pear_mt-1.1.0.tar.gz:

Publisher: release.yml on prosho-97/pear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pear_mt-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pear_mt-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pear_mt-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec50914aa66260f014e1bdcc1741e13e90955e3eb37dd3f6beb97a744c376db0
MD5 6e1ad67a0a3df16ffc3e74c7ae54f0ee
BLAKE2b-256 4e42a4b1beebdb8118a27edb1e44c01dde51ed68643231fe41a60bb531b9e834

See more details on using hashes here.

Provenance

The following attestation bundles were made for pear_mt-1.1.0-py3-none-any.whl:

Publisher: release.yml on prosho-97/pear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.1.1

2 files

This release

1.1.0 This release

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 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