Skip to content

FudanSELab/TransAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TransAGENT: Enhancing LLM-Based Code Translation via Fine-Grained Execution Alignment

Overview

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.

Project Structure

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/

Requirements

  • Python 3.8+
  • PyTorch
  • Transformers
  • CUDA-capable GPU (recommended)
  • Compilers for C++ (g++), Java (javac), and Python (CPython)

Installation

# 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.txt

Usage

Basic Translation

from 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)

Running Experiments

cd Code-CodeTranslation
python main_run_repair_testInputs.py --source_lang python --target_lang cpp --model_type deepseek

Evaluation

from Code-CodeTranslation.CodeBleu import calc_code_bleu

bleu_score = calc_code_bleu(reference_code, translated_code)
print(f"CodeBLEU Score: {bleu_score}")

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors