This project focuses on fine-tuning Microsoft's phi-1.5 language model for Python code generation using natural language problem descriptions. It leverages the CodeParrot/APPS dataset and utilizes efficient fine-tuning techniques like PEFT and LoRA to achieve significant performance improvements on code synthesis tasks.
- Goal: Enhance Python code generation capabilities of a pretrained LLM using domain-specific fine-tuning.
- Base Model: Microsoft phi-1.5 (a small yet effective LLM)
- Dataset: CodeParrot / APPS (10,000 Python problems with solutions)
- Techniques Used: PEFT (Parameter-Efficient Fine-Tuning), LoRA (Low-Rank Adaptation)
- Environment: Google Colab (GPU-enabled)
This repository contains the following files:
-
Fine-Tuning LLM Tasks.ipynb: Jupyter Notebook with the code and implementation for fine-tuning the language model (LLM) for code generation tasks. You can open this notebook to explore the step-by-step code and results. -
Fine_tune_LLM_for_Code_Generation.pdf: A detailed & complete documentation file that explains the methodology, techniques, and findings from the fine-tuning process. It provides in-depth insights into the code generation improvements achieved through fine-tuning. -
Datasets: The dataset folder includes the following JSON files:
trainDataset.json: The training dataset used for fine-tuning the model for first time.SyntheticDataset.json: Includes the synthetic dataset generated using LLM for fine-tuning the model for second time.CombinedDataset.json: Contains the combined dataset (train + synthetic) used for final fine-tuning.testDataset.json: The test dataset used for evaluating the model's performance.
- Source: CodeParrot / APPS
- Description: A collection of English programming problem statements paired with corresponding Python solutions.
- Dataset Used: First 500 samples.
- Training: 300 samples
- Validation: 100 samples
- Testing: 100 samples
- Python – Core language used for training and scripting.
- Google Colab – Platform for training with free GPU resources.
- Hugging Face Transformers – Loading and interacting with pretrained models.
- PEFT Library – Implements LoRA for efficient model fine-tuning.
- Datasets – Used to load and process the CodeParrot/APPS dataset.
- Accelerate – Facilitates training on available hardware (Colab GPU).
- ROUGE Evaluation – Used to evaluate generated Python code quality.
- Filter and clean dataset
- Tokenize using
phi-1.5tokenizer - Split into training, validation, and test sets
- Original Data Training: Fine-tune using human-annotated problems
- Synthetic Data Training: Generate synthetic problem-code pairs using ChatGPT and fine-tune
- Combined Data Training: Merge both datasets and perform final fine-tuning
- Used LoRA to fine-tune efficiently on limited hardware
- Conducted training on Google Colab with ~16GB GPU memory
- Metrics: ROUGE (Recall-Oriented Understudy for Gisting Evaluation)
- ROUGE-1: Unigram overlap
- ROUGE-2: Bigram overlap
- ROUGE-L: Longest common subsequence
- Results:
- Best performance observed when trained on combined dataset
- Achieved ~30% improvement in code generation quality (based on ROUGE scores)
- Domain-specific fine-tuning greatly enhances LLM performance for code generation.
- Synthetic data generated using OPEN AI API helps boost generalization.
- LoRA + PEFT allows efficient training even on resource-limited platforms like Google Colab.
- Expand to support multiple programming languages.
- Evaluate using additional metrics like BLEU, CodeBLEU, and Human Eval.
- Explore model deployment as a code-assist tool or IDE extension.
If you have any questions or would like to collaborate, feel free to reach out:
Prateek Kumar Sharma
📧 Prateeksharma0112@gmail.com
🌐 LinkedIn