Unbabel COMET

raw JSON →
2.2.7 verified Sat May 09 auth: no python

High-quality Machine Translation Evaluation library using neural models. Version 2.2.7. Active development on GitHub, with minor releases every few months.

pip install unbabel-comet
error KeyError: 'src'
cause Missing required key in input data dict.
fix
Ensure each sample dict has 'src' and 'mt' keys.
error requests.exceptions.ConnectionError: HTTPConnectionPool
cause Network issue downloading model from Hugging Face hub.
fix
Check internet connection or set HF_HUB_OFFLINE=1 to use cached models.
error AttributeError: module 'comet' has no attribute 'download_model'
cause Incorrect import path.
fix
Use 'from comet import download_model' instead of 'from comet.models import download_model'.
gotcha The `predict` method expects a list of dicts with keys 'src', 'mt', and optionally 'ref'. Missing keys cause KeyError.
fix Ensure each dict contains 'src' and 'mt' keys (and 'ref' if required).
gotcha Model downloads can be large (several GB). The download_model function caches in ~/.cache/comet by default.
fix Set environment variable COMET_CACHE_DIR to a custom path.
deprecated The `comet-score` CLI uses model.half() by default starting v2.2.5, which slightly changes scores compared to v2.2.4.
fix Upgrade to v2.2.6+ for consistent half-precision behavior.
gotcha Some models (like XCOMET) are only for inference and not for training in current releases.
fix Check model documentation to confirm training support.

Load a COMET model and score translation pairs.

from comet import download_model, load_from_checkpoint

model_path = download_model("Unbabel/wmt22-comet-da")
model = load_from_checkpoint(model_path)

data = [
    {
        "src": "This is a source sentence.",
        "mt": "Ceci est une phrase source.",
        "ref": "This is a reference translation."
    }
]

seg_scores, sys_score = model.predict(data, batch_size=8, gpus=1)
print(seg_scores, sys_score)