Skip to content

EasyCam/TransCoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.

About

A tool to use Ollama and LLM to translate stuff

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors