Downloads · 30 days
0
Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE
Code-Completion-using-GPT-2-CodeXGLUE is a text generation model from Sai-Nandu. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
This repository contains a fine-tuned GPT-2 model for Python source code completion. The model was trained on the CodeXGLUE Python Code Completion dataset using the Hugging Face Transformers library and PyTorch.
Downloads · 30 days
0
Access
Public
Updated Jul 7, 2026
Repo size
1.5 GB
Likes
0
Public
Click a slice to open those files.
.pt996 MB · 67%
From the Hugging Face model README
This repository contains a fine-tuned GPT-2 model for Python source code completion. The model was trained on the CodeXGLUE Python Code Completion dataset using the Hugging Face Transformers library and PyTorch.
This model is designed to predict the next tokens in Python source code, enabling intelligent code completion for software development tasks.
Dataset: CodeXGLUE – Python Code Completion
The dataset contains Python source code snippets used to train language models for next-token code prediction.
Note: A subset of approximately 13,000 training samples from the CodeXGLUE Python dataset was used for fine-tuning.
| Parameter | Value |
|---|---|
| Model | GPT-2 |
| Epochs | 3 |
| Learning Rate | 2e-4 |
| Batch Size | 4 |
| Gradient Accumulation | 4 |
| Weight Decay | 0.01 |
| Max Sequence Length | 512 |
| Optimizer | AdamW |
| Framework | PyTorch |
Training was performed using the Hugging Face Trainer API.
| Metric | Value |
|---|---|
| Validation Loss | 1.1869 |
| Perplexity | 3.28 |
The decreasing validation loss throughout training indicates successful adaptation of GPT-2 to the Python code completion task.
| Step | Training Loss | Validation Loss |
|---|---|---|
| 100 | 1.5613 | 1.3592 |
| 200 | 1.3962 | 1.2877 |
| 300 | 1.3317 | 1.2537 |
| 400 | 1.2437 | 1.2308 |
| 500 | 1.2253 | 1.2142 |
| 600 | 1.2014 | 1.2000 |
| Final | — | 1.1869 |
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/MODEL_NAME")
model = AutoModelForCausalLM.from_pretrained("YOUR_USERNAME/MODEL_NAME")
prompt = "def fibonacci(n):"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
**inputs,
max_new_tokens=50,
do_sample=True,
temperature=0.7
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Sai Nandu Vajhala