COMET

repository·master·Indexed 20 days ago

https://github.com/unbabel/comet

Cross-lingual Optimized Metric for Evaluation of Translation (COMET) is a framework for evaluating Machine Translation (MT) quality using neural models. It supports reference-based, reference-free (Quality Estimation), and explainable (XCOMET) evaluation modes. The toolkit includes CLI tools for scoring (comet-score), statistical comparison of multiple systems (comet-compare), and quality-aware decoding (comet-mbr), as well as a Python API for programmatic evaluation.

Tokens
11.1K
Snippets
29
Records
42
Agent score
73%

What's inside unbabel-comet

  1. Overview of COMET for MT Evaluation

    master

    COMET is an open-source framework designed for Machine Translation (MT) evaluation. It serves two primary purposes:

    1. Evaluating MT systems: Using existing high-performing metrics provided by the framework.
    2. Metric development: Providing a foundation to train and develop new evaluation metrics.

    For technical details on specific metrics, refer to the COMET Metrics section in the documentation.

  2. Overview of COMET Models

    master

    COMET provides several types of models for MT evaluation:

    • Reference-based Models: (e.g., Unbabel/wmt22-comet-da) Use source and reference to predict quality. Scores typically range from 0 to 1.
    • Reference-free Models (QE): (e.g., Unbabel/wmt22-cometkiwi-da, Unbabel/wmt23-cometkiwi-da-xl, Unbabel/wmt23-cometkiwi-da-xxl) Predict quality using only the source and hypothesis. These are useful when no reference is available.
    • eXplainable COMET (XCOMET): (e.g., Unbabel/XCOMET-XL, Unbabel/XCOMET-XXL) These models identify error spans and assign quality scores, allowing for error analysis based on the MQM typology (minor, major, or critical errors).

    For older research compatibility (pre-2022), use Unbabel/wmt20-comet-da or Unbabel/wmt20-comet-qe-da.

  3. Select a COMET metric model

    master

    COMET provides several models optimized for different types of human judgments. When evaluating translation systems, choose a model based on whether you want to estimate Direct Assessment (DA) scores or Human Targeted Edit Rate (HTER).

    Important Usage Notes:

    • Directionality: Models trained on DA (Direct Assessment) produce higher scores for better translations (indicated by ). Models trained on HTER (Human Targeted Edit Rate) produce lower scores for better translations (indicated by ), as HTER measures the amount of editing required.
    • Comparability: Do not compare scores across different model architectures. For example, a score from a large model is not directly comparable to a score from a base model, even if they were trained on the same type of judgment. Always use the same metric when comparing two different translation systems.
    | Model                      | Description                                                                                                   |
    | :------------------------- | :------------------------------------------------------------------------------------------------------------ |
    | ↑`wmt-large-da-estimator-1719` | **RECOMMENDED:** Estimator model build on top of XLM-R (large) trained on DA from WMT17, WMT18 and WMT19           |
    | ↑`wmt-base-da-estimator-1719`  | Estimator model build on top of XLM-R (base) trained on DA from WMT17, WMT18 and WMT19                          |
    | ↓`wmt-large-hter-estimator`  | Estimator model build on top of XLM-R (large) trained to regress on HTER.                                   |
    | ↓`wmt-base-hter-estimator`   | Estimator model build on top of XLM-R (base) trained to regress on HTER.                                      |
    | ↑`emnlp-base-da-ranker`      | Translation ranking model that uses XLM-R to encode sentences. Trained with WMT17 and WMT18 DARR.              |
  4. Interpreting COMET scores

    master

    COMET scores are typically normalized between 0 and 1:

    • 1.0: Indicates a high-quality translation.
    • 0.0: Indicates a translation that is no better than random chance.

    While raw scores are useful for ranking translations and systems, you should use comet-compare when comparing two different systems to ensure the difference is statistically significant. For XCOMET models, scores can also be used to identify specific error types (minor, major, or critical) according to the MQM typology.

  5. Run toolkit unit tests

    master

    To run the toolkit's test suite using poetry and coverage, use the following commands. Note that testing on a CPU can be slow.

    poetry run coverage run --source=comet -m unittest discover
    poetry run coverage report -m # Expected coverage 76%
  6. Use UniTE models in COMET

    master

    COMET supports UniTE (Unified Translation Evaluation) models. You can use the original checkpoints or Unbabel-trained variants:

    • Unbabel/unite-mup: The original UniTE Metric.
    • Unbabel/wmt22-unite-da: Trained on the same data as wmt22-comet-da, producing scores between 0 and 1.
    • Unbabel/unite-xxl and Unbabel/unite-xl: Earlier curriculum phases of the XCOMET models.
  7. Train a custom COMET metric

    master

    To train a new COMET metric, use the comet train CLI command and provide a configuration file in YAML format. COMET uses PyTorch Lightning for training, so all models are implemented as Lightning Modules.

    Training Data Format

    Your training data must be a CSV file containing the following columns:

    • src: The source segment.
    • mt: The machine translation hypothesis.
    • ref: The reference segment.
    • score: The human judgment score.

    Example CSV structure:

    src,mt,ref,score
    Hello world!,Oi mundo.,Olá mundo!,0.5
    This is a sample,este é um exemplo,isto é um exemplo!,0.8
    comet train -f {my_configs}.yaml
  8. Select the appropriate COMET evaluation model

    master

    COMET provides several types of models depending on your evaluation needs (reference-based, reference-free, or explainable).

    Primary Models

    • Reference-based (Default): Unbabel/wmt22-comet-da. Uses XLM-R architecture. Scores range from 0 to 1 (1 is perfect).
    • Reference-free: Unbabel/wmt22-cometkiwi-da. Uses InfoXLM architecture. Does not require a reference translation. Available in larger versions: Unbabel/wmt23-cometkiwi-da-xl (3.5B params) and Unbabel/wmt23-cometkiwi-da-xxl (10.7B params).
    • Explainable (XCOMET): Unbabel/XCOMET-XXL or Unbabel/XCOMET-XL. These models identify error spans and assign quality scores. They show the highest correlation with MQM (Multidimensional Quality Metric) and are the best performing.

    Compatibility Note

    If comparing results with research published before 2022, use older checkpoints like Unbabel/wmt20-comet-da or Unbabel/wmt20-comet-qe-da to ensure parity.

  9. Install unbabel-comet via pip

    master

    To install COMET for standard use, ensure you have Python 3.8 or above and run the following commands:

    pip install --upgrade pip
    pip install unbabel-comet

    Note: Some models (e.g., Unbabel/wmt22-cometkiwi-da) require you to acknowledge their license on the Hugging Face Hub and log in using the Hugging Face CLI.

  10. Train and use a custom COMET metric

    master

    You can train a custom COMET model using a configuration YAML file and then use it for scoring via the CLI. Once trained, you can also upload your model to the Hugging Face Hub to use it directly by its hub name.

    # Train your own metric
    comet-train --cfg configs/models/{your_model_config}.yaml
    
    # Score using your trained checkpoint
    comet-score -s src.de -t hyp1.en -r ref.en --model PATH/TO/CHECKPOINT