Skip to main content

Multilingual Parallel Translation Platform with Reflection-based Improvement using Local LLMs

Project description

TransCoder

PyPI version Python 3.8+ License: MIT

Multilingual Parallel Translation Platform with Reflection-based Improvement using Local LLMs

TransCoder is a powerful translation platform that leverages local Large Language Models (LLMs) through Ollama, featuring innovative Reflection-based Translation methods that significantly improve translation quality through AI self-evaluation and iterative refinement.

Key Features

🌟 Core Innovations

  • 三省吾身模式 (Three Reflections Mode): Translation → AI Reflection → Improvement cycle
  • 千锤百炼模式 (Iterative Refinement Mode): Configurable 1-10 iteration optimization for maximum quality

🚀 Main Features

  • Multilingual Parallel Translation: Translate to multiple languages simultaneously
  • 14 Language Variants: Including Chinese variants (Simplified, Traditional, Classical)
  • Local LLM Support: Works with Ollama (Qwen, Llama, Mistral, etc.)
  • Translation Memory: FAISS-based vector database for consistency
  • Terminology Management: Professional term consistency across translations
  • Quality Evaluation: BLEU, BERTScore, ROUGE metrics

Installation

From PyPI (Recommended)

pip install transcoder-llm

# With all features
pip install transcoder-llm[all]

# With specific features
pip install transcoder-llm[web]      # Web interface
pip install transcoder-llm[vector-db] # Translation memory
pip install transcoder-llm[evaluation] # Quality metrics

From Source

git clone https://github.com/EasyCam/TransCoder.git
cd TransCoder
pip install -e .

Quick Start

1. Install and Start Ollama

# Install Ollama (macOS/Linux)
curl -fsSL https://ollama.ai/install.sh | sh

# Download a model
ollama pull qwen3:0.6b

2. Start TransCoder

# Web interface
transcoder web

# Or with production server
transcoder web --production

# CLI translation
transcoder cli -i input.txt -t en,ja,ko -o output.txt

3. Python API

from transcoder import TransCoderAPI

api = TransCoderAPI(model="qwen3:0.6b")

# Simple translation
result = api.translate("Hello world", "en", ["zh-cn", "ja"])
print(result.data["translations"])

# Reflection mode (三省吾身)
result = api.translate_with_reflection(
    "Hello world", "en", "zh-cn"
)

# Iterative refinement (千锤百炼)
result = api.translate_iterative(
    "Hello world", "en", "zh-cn", iterations=3
)

Translation Modes

Simple Mode

Fast one-pass translation for everyday use.

Reflection Mode (三省吾身)

Initial Translation → AI Reflection Analysis → Improved Translation

The AI analyzes translation quality from four dimensions:

  • Accuracy: Is the meaning fully preserved?
  • Fluency: Is the expression natural?
  • Style: Is the tone appropriate?
  • Terminology: Are terms translated correctly?

Iterative Refinement (千锤百炼)

Initial → Reflect → Improve → Reflect → Improve → ... → Final

Configure 1-10 iterations to balance quality vs. speed.

API Reference

REST API

# Translation
POST /api/translate
{
    "source_text": "Hello world",
    "source_lang": "en",
    "target_langs": ["zh-cn", "ja"]
}

# Reflection
POST /api/translate/reflect
{
    "source_text": "Hello world",
    "translation": "你好世界",
    "source_lang": "en",
    "target_lang": "zh-cn"
}

# Improvement
POST /api/translate/improve
{
    "source_text": "Hello world",
    "current_translation": "你好世界",
    "reflection": "...",
    "source_lang": "en",
    "target_lang": "zh-cn"
}

Python API

from transcoder import TransCoderAPI

api = TransCoderAPI()

# Translate
result = api.translate(text, source_lang, target_langs)

# With reflection
result = api.translate_with_reflection(text, source_lang, target_lang)

# Iterative
result = api.translate_iterative(text, source_lang, target_lang, iterations=3)

# Evaluate quality
result = api.evaluate_translation(source, translated, reference)

Supported Languages

Code Language
zh-cn Chinese (Simplified)
zh-tw Chinese (Traditional)
zh-classical-cn Classical Chinese (Simplified)
zh-classical-tw Classical Chinese (Traditional)
en English
ja Japanese
ko Korean
es Spanish
fr French
de German
ru Russian
ar Arabic
pt Portuguese

Project Structure

transcoder/
├── __init__.py      # Package exports
├── cli.py           # Command-line interface
├── api.py           # Unified Python API
├── core.py          # Core services
├── app.py           # Flask web application
└── templates/       # HTML templates

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

# Run linter
ruff check transcoder/

# Build package
python -m build

# Upload to PyPI
./upload_pypi.sh

License

MIT License - See LICENSE for details.

Citation

If you use TransCoder in your research, please cite:

@software{transcoder2024,
  title = {TransCoder: Multilingual Parallel Translation Platform with Reflection-based Improvement},
  author = {TransCoder Team},
  year = {2024},
  url = {https://github.com/EasyCam/TransCoder}
}

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting PRs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transcoder_llm-1.0.0.tar.gz (50.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

transcoder_llm-1.0.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file transcoder_llm-1.0.0.tar.gz.

File metadata

  • Download URL: transcoder_llm-1.0.0.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for transcoder_llm-1.0.0.tar.gz
Algorithm Hash digest
SHA256 480d600d79d48dbb7ce6760f2f9c971075615f444c4ab579daca856da4ddec94
MD5 2316c6058752d8e46c395762922b3d68
BLAKE2b-256 7ece9490f08f200aadad0fcda1875d7bab68426432ce5eff9e8665a6dfdd6f97

See more details on using hashes here.

File details

Details for the file transcoder_llm-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: transcoder_llm-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for transcoder_llm-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d80eaeff77e6694ad1f400bc8d91054a42c6991d3c118d18c77c1ba1b3e4526a
MD5 86159b113169c52b6bbe8f5bbe2f8bba
BLAKE2b-256 6b87ac0ab8a96ef8176e668467d13a3347b6dc2961f9e537dcfaeb4f68c23886

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page