PraneetNS/codesentinel-full
234
๐ CodeSentinel โ Smart Code Assistant for Bug Detection & Safe Generation
โก "Write better code. Catch bugs early. Avoid unsafe outputs."
๐ง Model Overview
CodeSentinel is a fine-tuned Large Language Model built on top of Qwen2.5-Coder-3B-Instruct, designed specifically for:
- ๐ Detecting and fixing bugs in code
- ๐ง Reducing hallucinations in generated code
- ๐ Enforcing safe and responsible code generation
- โก Assisting developers with clean, reliable solutions
This model is optimized for real-world developer workflows, especially for students and engineers in Tier-2/3 ecosystems.
๐ Key Features
- โ Bug Detection & Fixing
- โ Hallucination Reduction
- โ Safe Code Refusal (malicious prompts blocked)
- โ Structured & Clean Outputs
- โ Lightweight LoRA Fine-tuning (efficient)
๐๏ธ Model Details
- Base Model: Qwen/Qwen2.5-Coder-3B-Instruct
- Fine-tuning Method: LoRA (PEFT)
- Training Stages:
- Stage 1 โ Supervised Fine-Tuning (SFT)
- Stage 2 โ Direct Preference Optimization (DPO)
- Framework: Hugging Face Transformers + PEFT
- Precision: FP16
- Hardware: Tesla T4 (Kaggle)
๐ฏ Intended Use
๐ก Direct Use
- Debugging Python / general code
- Improving code quality
- Generating safe code snippets
๐ง Downstream Use
- IDE plugins
- Code review assistants
- Educational tools
- Developer copilots
โ Out-of-Scope Use
- Generating malware or exploits
- Bypassing security systems
- Illegal or harmful automation
๐ The model is trained to refuse such requests
โ ๏ธ Limitations
- May still hallucinate in rare edge cases
- Limited to training distribution (mostly Python-centric)
- Not a replacement for production-level code review
๐ ๏ธ How to Use
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-Coder-3B-Instruct",
device_map="auto",
torch_dtype="auto"
)
model = PeftModel.from_pretrained(base_model, "PraneetNS/codesentinel-adapter")
tokenizer = AutoTokenizer.from_pretrained("PraneetNS/codesentinel-adapter")
prompt = "Fix this bug: KeyError in dictionary access"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=200)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))๐ Training Details
๐ Dataset
Custom curated dataset including:
- Buggy vs correct code pairs
- Hallucination traps (e.g., fake functions)
- Safe vs unsafe response pairs
โ๏ธ Training Setup
- Batch size: 2 (effective 16 via accumulation)
- Learning rate: 2e-4 (SFT), 5e-6 (DPO)
- Epochs: 1โ2
- Optimizer: AdamW
๐ Evaluation
โ Improvements Observed
- Reduced incorrect API usage
- Better structured responses
- Improved refusal for unsafe prompts
๐งช Example
Input:
users = {'alice': {'score': 80}}
print(users['bob']['score'])Output:
- Detects
KeyError - Suggests safe access (
dict.get())
๐ Impact
- Helps beginner developers avoid common mistakes
- Encourages safe AI usage
- Reduces debugging time
โก Technical Highlights
- LoRA-based fine-tuning (memory efficient)
- Runs on low-cost GPUs (T4)
- Easily deployable
๐ป Compute
- GPU: Tesla T4
- Platform: Kaggle
- Training Time: ~1โ2 hours
๐ Links
- Model: https://huggingface.co/PraneetNS/codesentinel-adapter
๐ข Why CodeSentinel?
Most code models generate answers. CodeSentinel understands correctness and safety.
๐ Acknowledgements
- Hugging Face ๐ค
- Qwen Team
- Open-source ML community
๐ฌ Contact
Author: Praneet Savant ๐ง savantpraneet@gmail.com
โญ If you find this useful, consider starring the repo!
