OPUS-MT Indonesian-to-Arabic Hybrid Translation Model

Model ID: Ik45/opus-mt-id-ar-hybrid
Architecture: MarianMT (Encoder-Decoder Transformer)
Source Language: Indonesian (id)
Target Language: Arabic (ar)
Model Type: Hybrid Cross-Lingual Transfer Model


🎯 Overview

This model is a hybrid neural machine translation model that translates from Indonesian to Arabic, created using a novel encoder-decoder swap technique. Instead of training from scratch, the model leverages pre-trained components from existing OPUS-MT models through strategic component transfer, followed by fine-tuning on parallel Indonesian-Arabic data.

Hybrid Architecture Strategy

Component Source Model Description
Encoder Helsinki-NLP/opus-mt-id-en Indonesian-to-English encoder, pre-trained to understand Indonesian language patterns
Decoder Helsinki-NLP/opus-mt-en-ar English-to-Arabic decoder, pre-trained to generate Arabic text
Shared Embeddings From Decoder Model Arabic vocabulary embeddings preserved from the en-ar model

Key Insight: MarianMT uses shared embeddings between encoder and decoder. The decoder determines the output vocabulary, so the decoder model serves as the base while only the encoder layers are replaced.


πŸ”§ Technical Details

Architecture Compatibility

The following architecture checks were performed to ensure compatibility between source models:

Check opus-mt-id-en opus-mt-en-ar Status
d_model 512 512 βœ… Pass
encoder_layers 6 6 βœ… Pass
decoder_layers 6 6 βœ… Pass
encoder_attention_heads 8 8 βœ… Pass
decoder_attention_heads 8 8 βœ… Pass
encoder_ffn_dim 2048 2048 βœ… Pass
decoder_ffn_dim 2048 2048 βœ… Pass

Vocabulary Size: 62,802 tokens (from Arabic target vocabulary)
Hidden Dimensions: 512
Attention Heads: 8
Encoder/Decoder Layers: 6 each

Training Configuration

# Fine-tuning Hyperparameters
learning_rate: 2e-5
batch_size: 16
num_train_epochs: 3
max_length: 512
weight_decay: 0.01
fp16: True
optimizer: AdamW

Data Packing Strategy

To maximize training efficiency, a sentence packing technique was employed:

  • Multiple short sentence pairs are concatenated with a </sep> token
  • Packed sequences are truncated to max_length=512
  • This increases effective batch utilization and reduces padding overhead

Packed Dataset Statistics:

  • Original parallel sentences: 536,463
  • Packed training examples: 97,140
  • Train/Validation Split: 99.9% / 0.1%

πŸ“Š Training Data

The model was fine-tuned on a combined corpus of Indonesian-Arabic parallel texts extracted from the OPUS collection:

Dataset Source Sentence Pairs Bible UEDIN Religious texts 31,000 Tanzil Quran translations 77,000 NeuLab-TedTalks TED Talks 4,000 TED2020 TED Talks 2020 8,000 QED Educational dialogues 2,000 Total 536,463

Data preprocessing included:

  • Alignment of .ar and .id parallel files
  • Minimum length filtering (removing empty lines)
  • UTF-8 normalization for Arabic script

πŸ“ˆ Performance Metrics

BLEU Scores During Training

The model was evaluated using SacreBLEU at regular intervals:

Step Training Loss Validation Loss BLEU 10,000 2.795 2.530 0.866 11,000 2.761 2.503 0.631 12,000 2.725 2.482 0.601 13,000 2.711 2.471 0.526 14,000 2.713 2.455 0.587 15,000 2.682 2.447 0.597 16,000 2.669 2.439 0.772 17,000 2.673 2.435 0.807 18,000 2.659 2.432 0.618 18,216 (Final) 2.664 2.432 0.516

Note: BLEU scores during training reflect the packed validation set and may not represent final translation quality on standard benchmarks.


πŸš€ Usage

Quick Start

from transformers import MarianMTModel, MarianTokenizer

# Load model and tokenizer
model_name = "Ik45/opus-mt-id-ar-hybrid"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)

# Translate Indonesian to Arabic
def translate(text: str) -> str:
    inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
    translated = model.generate(
        **inputs,
        max_length=128,
        num_beams=4,
        early_stopping=True
    )
    return tokenizer.decode(translated[0], skip_special_tokens=True)

# Example
indonesian_text = "Selamat pagi, apa kabar?"
arabic_translation = translate(indonesian_text)
print(f"ID: {indonesian_text}")
print(f"AR: {arabic_translation}")

Advanced Usage with Pipeline

from transformers import pipeline

translator = pipeline("translation", model="Ik45/opus-mt-id-ar-hybrid")
result = translator("Saya sedang belajar pemrograman kecerdasan buatan.")
print(result[0]['translation_text'])

πŸ§ͺ Model Verification

Architecture Validation

The following tests were performed to verify model integrity:

Test Status Details Config Validity βœ… Pass pad_token_id (62801) < vocab_size (62802) Embedding Shape βœ… Pass torch.Size([62802, 512]) Encoder Forward βœ… Pass Output shape: (batch, seq_len, 512) Decoder Forward βœ… Pass Output shape: (batch, seq_len, 512) Full Generation βœ… Pass Successful token generation Parameter Count βœ… Pass 76,817,408 parameters

Comparison with Parent Models

Model Parameters Vocab Size Pad Token ID opus-mt-id-en 72,718,336 54,796 54,795 opus-mt-en-ar 76,817,408 62,802 62,801 opus-mt-id-ar-hybrid 76,817,408 62,802 62,801


⚠️ Limitations

  1. Fine-tuning Required: The hybrid architecture requires fine-tuning to align the Indonesian encoder with the Arabic decoder. Without fine-tuning, output quality is very low.

  2. Domain Coverage: Training data is primarily from religious texts (Bible, Quran) and TED Talks. Performance may vary on:

    • Technical/scientific texts
    • Colloquial Indonesian
    • Dialectal Arabic
    • Legal or medical documents
  3. Arabic Script: The model outputs standard Arabic script. It does not support:

    • Transliteration (Latin script Arabic)
    • Arabic dialects (Egyptian, Levantine, Gulf, etc.)
    • Diacritical marks (tashkeel) are generated based on context but may not be perfect
  4. Sentence Length: Optimal performance for sentences under 50 tokens. Very long sentences may suffer from attention degradation.

  5. Packing Artifacts: Due to the sentence packing strategy during training, the model may occasionally generate </sep> tokens or concatenate unrelated sentences if not properly handled.


πŸ”¬ Research Notes

Why This Approach Works

The encoder-decoder swap strategy exploits the modular nature of transformer architectures:

  1. Encoder Independence: The encoder processes source language into language-agnostic hidden representations
  2. Decoder Specialization: The decoder generates target language from these representations
  3. Shared Embedding Constraint: MarianMT ties encoder/decoder embeddings, so the decoder's vocabulary must be preserved

By combining an Indonesian encoder (trained to map Indonesian β†’ hidden space) with an Arabic decoder (trained to map hidden space β†’ Arabic), we create a bridge that only needs alignment through fine-tuning.

Alternative: Full Vocabulary Expansion

An alternative approach explored was vocabulary merging:

  • Merge Indonesian source vocabulary with Arabic target vocabulary
  • Resize embeddings and initialize new tokens
  • Train with standard seq2seq objective

However, the encoder-decoder swap proved more parameter-efficient and leveraged stronger pre-trained representations.


πŸ“š Citation

If you use this model in your research, please cite:

@misc{opus-mt-id-ar-hybrid,
  title={OPUS-MT Indonesian-to-Arabic Hybrid Translation Model},
  author={Ik45},
  year={2025},
  howpublished={\url{https://huggingface.co/Ik45/opus-mt-id-ar-hybrid}},
  note={Hybrid model combining encoder from opus-mt-id-en and decoder from opus-mt-en-ar}
}

Parent Models

@article{tiedemann2020opus,
  title={OPUS-MT – Building open translation services for the World},
  author={Tiedemann, JΓΆrg and Thottingal, Santhosh},
  journal={Proceedings of the 22nd Annual Conference of the European Association for Machine Translation},
  year={2020}
}

🀝 Acknowledgments

  • Helsinki-NLP for the original OPUS-MT models
  • OPUS Project for the parallel corpora
  • Hugging Face for the Transformers library and model hosting infrastructure

πŸ“„ License

This model is released under the Apache 2.0 License, following the licensing of the parent OPUS-MT models.


πŸ› Issues and Contributions

For issues, questions, or contributions related to this model, please open an issue on the Hugging Face model repository or contact the model author.

Model Repository: https://huggingface.co/Ik45/opus-mt-id-ar-hybrid


---
Downloads last month
44
Safetensors
Model size
76.4M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Evaluation results

  • BLEU on OPUS Indonesian-Arabic Parallel Corpus
    self-reported
    0.520