YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

mt-en-id-latex-translation

English β†’ Indonesian Neural Machine Translation for LaTeX Documents

Hugging Face License Python PyTorch


πŸ“‹ Overview

A specialized neural machine translation model designed to translate natural language text within LaTeX documents from English to Indonesian while rigorously preserving document structure, LaTeX commands, mathematical expressions, and formatting.

This model is particularly suited for:

  • Academic papers and journal articles
  • Theses and dissertations
  • Technical books and monographs
  • Scientific reports and documentation

πŸ—οΈ Model Architecture

Attribute Specification
Base Architecture MarianMT (Transformer)
Encoder Layers 6
Decoder Layers 6
Total Parameters ~72.3M
Source Language English (en)
Target Language Indonesian (id)
Model Format Safetensors + PyTorch
License MIT

πŸš€ Quick Start

Installation

pip install transformers torch

Basic Usage

from transformers import MarianTokenizer, MarianMTModel

# Load model and tokenizer
model_name = "Ik45/mt-en-id-latex-translation"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)

# Example LaTeX input
latex_text = r"""
The \\textbf{quick brown fox} jumps over the lazy dog.
This is an important \\textit{result}.
We use \\begin{equation} E = mc^2 \\end{equation} in physics.
"""

# Tokenize and translate
inputs = tokenizer(latex_text, return_tensors="pt", padding=True)
translated = model.generate(
    **inputs,
    max_length=512,
    num_beams=5,
    early_stopping=True
)

# Decode output
output = tokenizer.decode(translated[0], skip_special_tokens=True)
print(output)

Advanced Configuration

For production-grade translation quality, the following generation parameters are recommended:

translated = model.generate(
    **inputs,
    max_length=512,
    num_beams=8,              # Beam search width
    num_beam_groups=2,        # Diverse beam search
    diversity_penalty=0.5,    # Encourage lexical diversity
    length_penalty=1.2,       # Favor longer translations
    early_stopping=True,
    no_repeat_ngram_size=3    # Prevent repetition
)

πŸ“ Recommended LaTeX Translation Workflow

For optimal results, integrate this model into a structured pipeline:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Raw LaTeX     │───▢│  Text Extraction │───▢│   Translation   β”‚
β”‚    Document     β”‚    β”‚  (pylatexenc)    β”‚    β”‚  (This Model)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                        β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  Final Output   │◀───│  Reconstruction  β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚  (Indonesian)   β”‚    β”‚   & Validation   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Recommended Tools

Tool Purpose Link
pylatexenc LaTeX tokenization and command protection GitHub
LaTeXMT Structure-preserving translation framework GitHub
latex2text Extract translatable text from LaTeX Built-in with pylatexenc

Example Pipeline Script

from pylatexenc.latex2text import LatexNodes2Text
from transformers import MarianTokenizer, MarianMTModel

def translate_latex_document(latex_source: str, model, tokenizer) -> str:
    \"\"\"
    Translate a LaTeX document while preserving structure.
    
    Args:
        latex_source: Raw LaTeX source string
        model: Loaded MarianMTModel
        tokenizer: Loaded MarianTokenizer
    
    Returns:
        Translated LaTeX string with preserved commands
    \"\"\"
    # Step 1: Extract text nodes
    l2t = LatexNodes2Text()
    text_nodes = l2t.nodelist_to_text(latex_source)
    
    # Step 2: Translate extracted text
    # (Implement your extraction/translation logic here)
    
    # Step 3: Reconstruct LaTeX with translated content
    # (Preserve commands, environments, and math mode)
    
    return translated_latex

πŸŽ“ Training Details

Data

The model was fine-tuned on a curated parallel corpus of English-Indonesian text with emphasis on:

  • Academic writing (journal articles, conference proceedings)
  • Technical documentation (engineering, computer science, mathematics)
  • LaTeX-structured content (theses, dissertations, textbooks)

Fine-Tuning Approach

  • Base Model: Pre-trained MarianMT (Helsinki-NLP/opus-mt-en-id)
  • Specialization: Continual fine-tuning on LaTeX-enriched parallel data
  • Objective: Cross-entropy loss with label smoothing
  • Validation: BLEU, chrF++, and human evaluation on LaTeX-specific test sets

⚠️ Limitations & Considerations

Scenario Recommendation
Complex nested LaTeX (e.g., heavy TikZ, custom macros) Manual post-editing strongly advised
Mathematical expressions Verify symbol consistency and notation standards
Domain-specific terminology Cross-reference with field-specific glossaries
Bibliographic entries Translate with caution; preserve citation keys
Custom commands Ensure commands are defined before translation

Note: While the model preserves LaTeX syntax, manual review is recommended for documents requiring publication-quality accuracy.


πŸ“Š Evaluation

Metric Score Dataset
BLEU To be evaluated LaTeX-Academic-Test
chrF++ To be evaluated LaTeX-Academic-Test
TER To be evaluated LaTeX-Academic-Test

Evaluation results will be updated upon completion of benchmark testing.


🀝 Contributing

Contributions are welcome. Areas of interest include:

  • Expanding the training corpus with domain-specific LaTeX data
  • Improving handling of complex LaTeX environments
  • Developing automated evaluation benchmarks for LaTeX translation
  • Creating integration plugins for popular LaTeX editors

Please open an issue or submit a pull request on the Hugging Face repository.


πŸ“„ License

This project is licensed under the MIT License. See LICENSE for details.


πŸ“š Citation

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

@misc{ik45-mt-en-id-latex-translation,
  author       = {Ik45},
  title        = {mt-en-id-latex-translation: English-Indonesian Neural Machine Translation for LaTeX Documents},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {\\url{https://huggingface.co/Ik45/mt-en-id-latex-translation}},
  note         = {Accessed: 2026-07-17}
}

Made with ❀️ for the Indonesian academic community.

⭐ Star on Hugging Face Β· πŸ› Report Issue Β· πŸ“– Documentation

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