Welcome to the FineOPUS repository. This project provides a robust, end-to-end, high-performance computing (HPC) pipeline designed to download, clean, normalize, filter, and evaluate multilingual parallel corpora derived from the OPUS collection.
The pipeline is organized into numbered stages (00–07) that lead you from raw, unverified downloads to a clean, high-quality translation corpus suitable for training large language models (LLMs) or machine translation (MT) systems. It is optimized to run on SLURM-managed clusters (such as CSC Mahti and LUMI) via job arrays, but also supports local execution for debugging.
- 00_preprocess — Metadata retrieval, zip streaming, ISO language mapping, validation, and initial 100M-line sharding.
- 01_language_reID — Multi-model (GlotLID + ConLID) language re-identification, confidence quantiles, and ensembling.
- 02_deduplication — SQL-based exact bitext deduplication using DuckDB disk-based memory spilling.
- 03_heuristics_filter — Two-stage hybrid filtering (univariate adaptive heuristics & unsupervised multivariate Isolation Forest).
- 04_parallelism_check — Embedding-based semantic similarity scoring, model selection (MRR), and thresholding.
- 05_quality_estimation — Distributed scoring across 5 backends: COMET, MetricX-24, ReMedy, Bicleaner, and offline vLLM (Qwen3, M-Prometheus).
- 06_frontier_llm_as_judge — High-quality evaluation using Azure-hosted DeepSeek-V4-Flash with token bucket rate limiters.
- 07_human_eval — Static HTML-based interface for broad quality evaluation (languages, fluency, translation correspondence).
Queries, downloads, normalizes, and reshards raw OPUS zip bundles.
- Key Scripts:
- get_corpora_list.py: Retrieves metadata from the OPUS REST API.
- download_convert_save.py: Streams zips, extracts parallel texts, maps to standardized ISO 639-3 + script codes, and writes Snappy-compressed Parquet.
- check_conversion.py: Uses
GlotScriptto validate and normalize language codes. - sharding.py: Consolidates data into balanced 100M-row shards.
- Prerequisites: Python 3.9+,
pyarrow,requests,GlotScript,langcodes[data].
Re-estimates source and target language labels to handle mislabeled translation text.
- Flow:
- shard_filelists.py: Partitions Parquet files into balanced file lists.
- re_lang_identify.py: Predicts language labels using GlotLID and ConLID.
- get_conf_stats.py & collect_conf_stats.py: Accumulate prediction confidences per language into binary float16 files.
- quantiles_conf_stats.py: Derives a per-language threshold (
median - stdclipped to[0.3, 0.9]). - ensemble_relid.py: Ensembles predictions. Replaces the original label only when both models confidently agree on the same new language. routes small volume pairs into a
_mixedbucket. - aggregate_ensembled_relid.py: Restructures the ensembled
.tarshards into canonical pair folders.
Executes exact duplicate removal across sentence pairs.
- Key Scripts:
- exact_dedup.py: Uses DuckDB SQL commands (
SELECT DISTINCT) to remove duplicates. Integrates memory limit configs (--memory_limit) and disk-based temp directories to prevent Out-Of-Memory (OOM) failures on massive datasets. - dedup_exact_all.sh: Runs SLURM job arrays dynamically based on incomplete folders logged in
exact_dedup_stats.csv.
- exact_dedup.py: Uses DuckDB SQL commands (
- Dependencies:
duckdb, Python 3.8+.
Implements a hybrid out-of-core filtering pipeline.
- Architecture:
- Stage 1 (Deterministic): filter_feature_eda.py calculates empirical percentiles per language pair and generates adaptive threshold boundaries. filter_stage1.py drops extreme outliers (character ratios, HTML tags, severe length mismatches).
- Stage 2 (Unsupervised): filter_stage2.py trains an
IsolationForestmodel on a subset of the data (capped at 400M rows) to detect and isolate multidimensional anomalies.
- Technical Details: Streams data in batches using PyArrow (
iter_batches) to maintain a bounded memory footprint.
Embedding-based filter to drop semantic mismatches.
-
Flow:
- Benchmarking: Evaluates embedding models (Harrier, Multilingual E5, GTE, Jina, Qwen) on gold FLORES-200 and BOUQuET test sets.
- Scoring: Scores every parallel sentence pair via cosine similarity using the best-performing model for that language pair.
-
Thresholding: Computes custom thresholds
$T$ based on the gold test distributions and benchmark Mean Reciprocal Rank (MRR), clipped to[0.3, 0.95]. -
Filtering: Streams Parquet shards and drops rows with scores below
$T$ .
A modular, distributed scoring pipeline supporting both FLORES-200 and OPUS datasets.
- Supported Backends:
- COMET: Translation evaluation.
- MetricX-24: Hybrid regression model (outputs adjusted from
0-25to0-1). - ReMedy: Gemma-2 based offline model calibrated using isolated master ports. Patched to support 140+ language configurations.
- Bicleaner: Standard Bitextor classifier.
- LLM Scorer: Offline vLLM execution of Qwen3/M-Prometheus models using structured schemas.
- Key Infrastructure:
- Manifest System: Deterministic shard assignment using BLAKE2b hashing.
- Stage Writer: Safe checkpointing (
checkpoint.jsonl) and transaction tracking.
Scores sentence pairs with a frontier model (Azure-hosted DeepSeek-V4-Flash).
- Features:
- Rate Limiting: Implements sliding-60s token buckets for TPM/RPM budgets.
- RAI Fallback: When Azure Responsible AI content filters block a multi-row batch, the script automatically falls back to individual scoring, saving failed segments as
nulland continuing without losing progress.
Lightweight, serverless human evaluation interface that generates static HTML pages to audit translation quality.
- Evaluation Criteria: Focuses on broad quality verification: 1) language code correctness, 2) sentence fluency/naturalness, and 3) translation equivalence.
- Flow:
- 0_create_sample_data.py: Streams data from Hugging Face and pseudo-samples it into shuffled JSONL files in
data/samples/. - 1_create_annotation_html.py: Reads the sample data and compiles an interactive index page and individual language pair annotation pages under
data/annotation_html. - create_annotation.sh: Helper script orchestrating the sample creation and HTML generation.
- 0_create_sample_data.py: Streams data from Hugging Face and pseudo-samples it into shuffled JSONL files in
- Storage: Since it runs serverless in the browser, annotation progress is saved in local storage and can be exported as JSONL files.
Create a virtual environment and install dependencies. Note that individual folders (such as 02_deduplication, 03_heuristics_filter, 05_quality_estimation, etc.) may require specialized dependencies (like duckdb, comet-mt, vllm):
# General setup
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtJob array submissions are supported by shell wrappers in each directory. Before running, configure your SLURM accounts, partitions, and HF API Tokens in the corresponding environment wrappers.
# Example: Submitting Stage 1 Heuristic Filtering
cd 03_heuristics_filter
sbatch --array=1-16 3_filter_stage1.shWhen modifying this repository:
- Preserve all existing comments and docstrings.
- If folders are relocated or stages are renumbered, update:
- The global directory paths in the root
.gitignore. - This global README.md file.
- References in scripts across all stage directories.
- The global directory paths in the root