TransAGENT is an advanced cross-language code translation system that leverages large language models (LLMs) to achieve high-quality, automated code translation between C++, Java, and Python. The system incorporates automated testing, code repair, and verification mechanisms to ensure translation accuracy and correctness.
TransAGENT/
├── Code-CodeTranslation/ # Core implementation code
│ ├── CodeBLEU/ # CodeBLEU evaluation metrics
│ ├── codeAlignment/ # Code alignment algorithms
│ ├── Dataloader.py # Dataset loading utilities
│ ├── main_run_repair_testInputs.py # Main execution script
│ ├── handcraftPrompt.py # Translation prompts
│ └── ...
├── CollectedDataset/ # Manually collected experimental dataset
│ ├── cpp.jsonl # C++ dataset
│ ├── java.jsonl # Java dataset
│ └── python.jsonl # Python dataset
├── Demonstration/ # Concrete translation examples
│ ├── CodeTranslationPrompt.png
│ └── ExampleInstrumentedJavaCode.png
└── ExperimentResult/ # Experimental data for research questions
├── RQ1-TranslationEffectivenessEvaluation/
├── RQ2-AblationEvaluation/
├── RQ3-RepairAccuracy/
└── RQ4-GeneralizationEvaluation/
- Python 3.8+
- PyTorch
- Transformers
- CUDA-capable GPU (recommended)
- Compilers for C++ (g++), Java (javac), and Python (CPython)
# Clone the repository
git clone git@github.com:FudanSELab/TransAgent_codeTranslation.git
cd TransAGENT
# Install Python dependencies (if requirements.txt exists)
pip install -r requirements.txtfrom Code-CodeTranslation.main_run_repair_testInputs import HuggingfaceModel
# Initialize model
model = HuggingfaceModel(model_name_or_path="path/to/model", model_type="deepseek")
# Perform translation
source_code = """
def add(a, b):
return a + b
"""
translation = model.generate(f"Translate this Python code to C++:\n{source_code}")
print(translation)cd Code-CodeTranslation
python main_run_repair_testInputs.py --source_lang python --target_lang cpp --model_type deepseekfrom Code-CodeTranslation.CodeBleu import calc_code_bleu
bleu_score = calc_code_bleu(reference_code, translated_code)
print(f"CodeBLEU Score: {bleu_score}")