CodeMentor — AI Programming Tutor

A fine-tuned Qwen2.5-Coder-7B-Instruct model trained to guide students through programming problems — never giving away answers, always teaching.


Model Details

Field Value
Base Model Qwen/Qwen2.5-Coder-7B-Instruct
Fine-tuning Method LoRA (r=16, alpha=32)
Training 3 epochs, 1585 examples
Languages Supported Python, Java, C, C++
Task Socratic code mentoring / tutoring
License MIT

What It Does

CodeMentor is not a code generator. It's a programming tutor that:

  • Guides students with hints and questions instead of answers
  • Detects what stage the student is at (confused, attempting, stuck, copy-pasting)
  • Validates correct thinking and gently corrects wrong reasoning
  • Never writes the full solution for the student

Intended Use

Built as the core AI engine for BuildEx — an educational IDE and VS Code-style browser extension developed by BuildForU. CodeMentor powers the in-editor tutoring experience, guiding students through code in real time without giving away solutions.

Primary integrations:

  • BuildEx IDE — embedded tutor panel inside the coding environment
  • BuildEx Extension — VS Code / browser extension that attaches CodeMentor to any editor session

Suitable for any educational setting where Socratic mentoring is preferred over direct answer generation.


How to Use

Requirements

Python >= 3.9
RAM >= 8GB
Storage >= 5GB (model download, cached after first run)
GPU: Optional (runs on CPU too, slower)

Install dependencies

pip install transformers bitsandbytes accelerate torch

Run locally

from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch

HF_MODEL = "likithyadavv/codementor-7b"
HF_TOKEN = "your_hf_read_token"  # from huggingface.co/settings/tokens

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16,
)

print("Loading CodeMentor... (first run downloads ~4GB, cached after)")
tokenizer = AutoTokenizer.from_pretrained(HF_MODEL, token=HF_TOKEN)
model = AutoModelForCausalLM.from_pretrained(
    HF_MODEL,
    quantization_config=bnb_config,
    device_map="auto",
    token=HF_TOKEN
)
print("Ready!\n")

def ask(instruction, code, language="Python"):
    prompt = f"""### System:
You are CodeMentor — a sharp, patient programming tutor for Python, Java, C, and C++.
You NEVER give away full solutions. Guide step by step.

### Instruction:
{instruction}

### Input:
[Language: {language}]
{code}

### Response:
"""
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=300,
            do_sample=True,
            temperature=0.7,
            top_p=0.9,
            repetition_penalty=1.2,
        )
    full = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return full.split("### Response:")[-1].strip()

while True:
    print("\n" + "="*40)
    lang = input("Language (Python/Java/C/C++): ").strip() or "Python"
    question = input("Your question: ").strip()
    code = input("Your code (press Enter to skip): ").strip()
    print(f"\n🤖 CodeMentor:\n{ask(question, code or 'None', lang)}")

Training Details

  • Dataset: 1585 hand-crafted instruction-response pairs covering Socratic guidance, error explanation, copy-paste detection, and concept doubts
  • LoRA config: r=16, alpha=32, targets: q_proj, k_proj, v_proj, o_proj
  • Quantization during training: 4-bit NF4 with double quant
  • Hardware: Kaggle 2x T4 GPU (15.6GB VRAM each)
  • Optimizer: AdamW with cosine LR scheduler
  • Batch size: 2 per device, 4 gradient accumulation steps

Limitations

  • Optimized for beginner-to-intermediate level programming questions
  • Not suitable for production code review or advanced algorithmic analysis

Built By

G N Likith Yadav — AIML Undergraduate, MVJCE Bangalore | Tensor Club Technical Lead

Downloads last month
131
Safetensors
Model size
8B params
Tensor type
F16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for likithyadavv/codementor-7b

Base model

Qwen/Qwen2.5-7B
Finetuned
(352)
this model
Adapters
1 model
Quantizations
2 models

Space using likithyadavv/codementor-7b 1