--- library_name: transformers tags: - code-generation - bug-fixing - ai-safety - llm - qwen - fine-tuned - peft - developer-tools license: mit language: - en - hi base_model: - Qwen/Qwen2.5-Coder-3B-Instruct pipeline_tag: question-answering --- --- # ๐Ÿš€ 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!