How unbabel/comet works
Main components and layers
• CLI Interface: This is exposed via commands like comet-score, comet-compare, comet-mbr, and comet-train. The CLI layer handles user input (text files, model selection, flags) and forwards requests to the underlying Python API.
• Core Library (Package Structure): The core functionality is encapsulated in the “comet” Python package. Within this package:
• CLI Submodule (comet/cli): Contains scripts to trigger scoring, comparison, training, and MBR decoding.
• Encoders (comet/encoders): Implements various transformer-based encoders (BERT, MiniLM, ReMBERT, XLM-R, etc.) for preparing textual representations.
• Models (comet/models): Houses the evaluation models and metrics (including ranking, regression, and multitask approaches). Also contains utility functions (download, caching, pooling, metrics calculation) and components for error detection and explanation.
• Modules (comet/modules): Provides additional building blocks such as feedforward layers and layerwise attention modules that support the evaluation/pipeline.
• Configuration Files: YAML files in the “configs” directory (e.g., models, trainer, early stopping) guide training/hyperparameter selection and inference settings.
• Testing and Documentation: The “tests” directory (unit and integration tests) ensures robustness, and the “docs” directory provides installation, usage, and internal architectural details.
• External Dependencies & Integration: The toolkit integrates with external services such as Hugging Face Hub for model downloads, sacreBLEU for test sets, and xTower for natural language explanations.
Relationships and data flow
• The CLI tools serve as the entry point for users. They call functions within the comet library, which in turn invoke specific encoders and models.
• The encoders convert raw text into embeddings/data formats required for evaluation.
• The evaluation models (which have sub-divisions for regression, ranking, and multitask evaluation) then process these representations to produce scores, error spans, and overall system-level assessments.
• Configurations are loaded from YAML files to customize model training and scoring behavior.
• Test pipelines (via tests) validate the functionality while the docs offer user guidance and examples.
• External services (e.g., Hugging Face Hub) are linked to the model download and license-checking processes.
Architectural Patterns and Design Principles
• Modular Design: Each functional unit (CLI, encoders, models, modules) is isolated and can be maintained independently.
• Separation of Concerns: The responsibilities are clearly divided between user interfaces, business logic (model inference and training), configuration management, and error analysis.
• Extensibility: The structure allows for the integration of additional transformer models and evaluation techniques as new submodules or encoder implementations without disrupting existing functionality.
• Reusability: Common utility functions (like caching, download utilities, and pooling) are centralized, reducing code duplication.