CoolFace
Modelpublic

PraneetNS/codesentinel-full

sourceHugging Facemitupdated 6mo agoView on Hugging Face
2likes34downloads
Model Card

๐Ÿš€ 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

python
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:

python
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!