Fine-tuned binary classifier on top of microsoft/codebert-base that
scores code snippets by P(buggy). Used in the CodePulse analysis engine
as a confidence validator: it filters GPT-predicted bugs by checking
whether the flagged line is statistically likely to be buggy, reducing
false positives before they reach the end user.
CodePulse-CodeBERT is a binary sequence classifier fine-tuned from
microsoft/codebert-base. Given a short code snippet (typically one bug
line plus optional surrounding context), the model outputs a probability
that the snippet contains a bug. Predictions below a configurable
threshold are marked as low-confidence and excluded from the final
quality score.
Classify short code snippets as buggy or not buggy:
from transformers import pipeline
clf = pipeline("text-classification", model="aidencary/codepulse-codebert")
result = clf("return user_list[index]")
# [{'label': 'buggy', 'score': 0.87}]
Integrated into the CodePulse backend
(app/services/codebert_validator.py) as a post-processing layer over
GPT-generated bug predictions. Each predicted bug line is extracted,
comment-stripped, and scored. Bugs whose P(buggy) falls below the
configured threshold are flagged and excluded from the penalty applied
to the code quality score.
# ...
comments are removed before scoring) to prevent label leakage from
annotated datasets. Code with semantically meaningful comments may
lose signal.Use P(buggy) as a soft signal, not a hard gate. Combine with static analysis or human review for critical codepaths.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import torch.nn.functional as F
tokenizer = AutoTokenizer.from_pretrained("aidencary/codepulse-codebert")
model = AutoModelForSequenceClassification.from_pretrained("aidencary/codepulse-codebert")
model.eval()
snippet = "items[i] = value"
inputs = tokenizer(snippet, return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
logits = model(**inputs).logits
p_buggy = float(F.softmax(logits, dim=-1)[0][model.config.label2id["buggy"]])
print(f"P(buggy): {p_buggy:.3f}")
Fine-tuned on labeled code snippets where each sample is a short code line or block annotated as buggy or clean. Training data sourced from public bug datasets and synthetic bug injection into clean Python code.
# comments stripped to prevent label leakageHeld-out split from the same labeled snippet dataset used for training.
Metric Value
Accuracy [add yours] F1 (macro) [add yours]
Model performs well on Python snippets matching training distribution. Performance degrades on heavily commented code (comments stripped at inference) and on languages outside the training set.
RobertaForSequenceClassification (CodeBERT backbone) with a 2-class classification head. Objective: binary cross-entropy, labels = {clean, buggy}.
Consumer GPU (training)
Aiden Cary, Keller Willhite, Zachery Atchley
microsoft/codebert-base