Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,314 +1,121 @@
|
|
| 1 |
-
---
|
| 2 |
-
language:
|
| 3 |
-
- en
|
| 4 |
-
license: mit
|
| 5 |
-
library_name: transformers
|
| 6 |
-
tags:
|
| 7 |
-
- text-classification
|
| 8 |
-
- code-quality
|
| 9 |
-
- documentation
|
| 10 |
-
- code-comments
|
| 11 |
-
- developer-tools
|
| 12 |
-
- code-review
|
| 13 |
-
- distilbert
|
| 14 |
-
datasets:
|
| 15 |
-
- synthetic
|
| 16 |
-
metrics:
|
| 17 |
-
- accuracy
|
| 18 |
-
- f1
|
| 19 |
-
- precision
|
| 20 |
-
- recall
|
| 21 |
-
base_model: distilbert-base-uncased
|
| 22 |
-
pipeline_tag: text-classification
|
| 23 |
-
widget:
|
| 24 |
-
- text: "This function calculates the Fibonacci sequence using dynamic programming to avoid redundant calculations. Time complexity: O(n), Space complexity: O(n)"
|
| 25 |
-
example_title: "Excellent Comment"
|
| 26 |
-
- text: "Calculates the sum of two numbers and returns the result"
|
| 27 |
-
example_title: "Helpful Comment"
|
| 28 |
-
- text: "does stuff with numbers"
|
| 29 |
-
example_title: "Unclear Comment"
|
| 30 |
-
- text: "DEPRECATED: Use calculate_new() instead. This method will be removed in v2.0"
|
| 31 |
-
example_title: "Outdated Comment"
|
| 32 |
-
- text: "Validates user input against SQL injection attacks using parameterized queries"
|
| 33 |
-
example_title: "Excellent Example 2"
|
| 34 |
-
- text: "magic happens here"
|
| 35 |
-
example_title: "Unclear Example 2"
|
| 36 |
-
model-index:
|
| 37 |
-
- name: code-comment-classifier
|
| 38 |
-
results:
|
| 39 |
-
- task:
|
| 40 |
-
type: text-classification
|
| 41 |
-
name: Text Classification
|
| 42 |
-
dataset:
|
| 43 |
-
name: Synthetic Code Comments
|
| 44 |
-
type: synthetic
|
| 45 |
-
metrics:
|
| 46 |
-
- type: accuracy
|
| 47 |
-
value: 0.9485
|
| 48 |
-
name: Accuracy
|
| 49 |
-
verified: false
|
| 50 |
-
- type: f1
|
| 51 |
-
value: 0.9468
|
| 52 |
-
name: F1 Score
|
| 53 |
-
verified: false
|
| 54 |
-
- type: precision
|
| 55 |
-
value: 0.9535
|
| 56 |
-
name: Precision
|
| 57 |
-
verified: false
|
| 58 |
-
- type: recall
|
| 59 |
-
value: 0.9485
|
| 60 |
-
name: Recall
|
| 61 |
-
verified: false
|
| 62 |
-
---
|
| 63 |
-
|
| 64 |
# Code Comment Quality Classifier ๐
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
## ๐ฏ Model Description
|
| 69 |
-
|
| 70 |
-
This fine-tuned DistilBERT model analyzes code comments and classifies them into **4 quality categories**:
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|----------|-----------|--------|-------------|
|
| 74 |
-
| ๐ **Excellent** | 100% | 100% | Clear, comprehensive, highly informative comments with context |
|
| 75 |
-
| โ
**Helpful** | 88.9% | 100% | Good comments that add value but could be more detailed |
|
| 76 |
-
| โ ๏ธ **Unclear** | 100% | 79.2% | Vague, confusing, or uninformative comments |
|
| 77 |
-
| ๐ซ **Outdated** | 92.3% | 100% | Deprecated, obsolete, or TODO comments |
|
| 78 |
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
- **F1 Score**: 94.68%
|
| 83 |
-
- *๐ Quick Start
|
| 84 |
|
| 85 |
-
###
|
| 86 |
|
| 87 |
-
```
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
# Load the classifier
|
| 91 |
-
classifier = pipeline("text-classification", model="Snaseem2026/code-comment-classifier")
|
| 92 |
-
|
| 93 |
-
# Classify comments
|
| 94 |
-
comments = [
|
| 95 |
-
"This function uses dynamic programming for O(n) time complexity",
|
| 96 |
-
"does stuff",
|
| 97 |
-
"DEPRECATED: use new_function() instead"
|
| 98 |
-
]
|
| 99 |
-
|
| 100 |
-
results = classifier(comments)
|
| 101 |
-
for comment, result in zip(comments, results):
|
| 102 |
-
print(f"{comment}: {result['label']} ({result['score']:.2%} confidence)")
|
| 103 |
```
|
| 104 |
|
| 105 |
-
###
|
| 106 |
|
| 107 |
```python
|
| 108 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 109 |
import torch
|
| 110 |
|
| 111 |
-
# Load model and tokenizer
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
Automatically flag low-quality comments during pull request reviews:
|
| 116 |
-
```python
|
| 117 |
-
def check_pr_comments(file_comments):
|
| 118 |
-
classifier = pipeline("text-classification", model="Snaseem2026/code-comment-classifier")
|
| 119 |
-
results = classifier(file_comments)
|
| 120 |
-
return [c for c, r in zip(file_comments, results) if r['label'] in ['unclear', 'outdated']]
|
| 121 |
-
```
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
### 3. **Developer Education**
|
| 127 |
-
Help developers learn what constitutes good documentation practices.
|
| 128 |
-
|
| 129 |
-
### 4. **IDE Integration**
|
| 130 |
-
Provide real-time feedback on comment quality while coding.
|
| 131 |
-
|
| 132 |
-
### 5. **Technical Debt Analysis**
|
| 133 |
-
Identify outdated comments and TODOs that need addressing.
|
| 134 |
-
|
| 135 |
-
## ๐๏ธ Training Details
|
| 136 |
-
|
| 137 |
-
### Model Architecture
|
| 138 |
-
- **Base Model**: [distilbert-base-uncased](https://huggingface.co/distilbert-base-uncased)
|
| 139 |
-
- **Parameters**: 66.96 million
|
| 140 |
-
- **Model Type**: Sequence Classification
|
| 141 |
-
- **Framework**: PyTorch + Hugging Face Transformers
|
| 142 |
-
|
| 143 |
-
### Training Data
|
| 144 |
-
- **Dataset Size**: 970 samples (776 train, 97 validation, 97 test)
|
| 145 |
-
- **Data Source**: Synthetic code comments
|
| 146 |
-
- **Classes**: 4 (balanced distribution)
|
| 147 |
-
- **Language**: English
|
| 148 |
-
|
| 149 |
-
### Training Hyperparameters
|
| 150 |
-
- **Epochs**: 3
|
| 151 |
-
- **Batch Size**: 16 (train), 32 (eval)
|
| 152 |
-
- **Learning Rate**: 2e-5
|
| 153 |
-
- **Optimizer**: AdamW
|
| 154 |
-
- **Weight Decay**: 0.01
|
| 155 |
-
- **Warmup Steps**: 500
|
| 156 |
-
- **Max Sequence Length**: 512 tokenselpful", "unclear", "outdated"]
|
| 157 |
-
print(f"Quality: {labels[predicted_class]} (confidence: {confidence:.2%})")
|
| 158 |
-
```
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
"Implements binary search with O(log n) time complexity",
|
| 169 |
-
"TODO fix later",
|
| 170 |
-
"Handles user authentication",
|
| 171 |
-
๐ Evaluation Results
|
| 172 |
|
| 173 |
-
|
| 174 |
|
|
|
|
|
|
|
| 175 |
```
|
| 176 |
-
precision recall f1-score support
|
| 177 |
|
| 178 |
-
|
| 179 |
-
helpful 0.8889 1.0000 0.9412 24
|
| 180 |
-
unclear 1.0000 0.7917 0.8837 24
|
| 181 |
-
outdated 0.9231 1.0000 0.9600 24
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
weighted avg 0.9535 0.9485 0.9468 97
|
| 186 |
```
|
| 187 |
|
| 188 |
-
|
| 189 |
-
- โจ **Perfect classification** of excellent comments (100% precision & recall)
|
| 190 |
-
- ๐ฏ **Zero false negatives** for helpful and outdated comments
|
| 191 |
-
- โ ๏ธ Slight challenge distinguishing unclear comments from other categories
|
| 192 |
-
- ๐ Strong overall performance with 94.85% accuracy
|
| 193 |
-
|
| 194 |
-
## โ ๏ธ Limitations
|
| 195 |
-
|
| 196 |
-
1. **Synthetic Training Data**: Model trained on synthetic examples; may require fine-tuning for specific domains (e.g., scientific computing, embedded systems)
|
| 197 |
-
2. **English Only**: Currently supports English code comments only
|
| 198 |
-
3. **No Code Context**: Evaluates comments in isolation without analyzing the actual code
|
| 199 |
-
4. **Subjectivity**: Comment quality is inherently subjective; model reflects patterns in training data
|
| 200 |
-
5. **Short Comments**: May struggle with very short comments (< 3 words)
|
| 201 |
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
-
- Supplementary tool in code review automation
|
| 206 |
-
- Documentation quality auditing
|
| 207 |
-
- Developer education and training
|
| 208 |
-
- IDE plugins for real-time feedback
|
| 209 |
|
| 210 |
-
|
| 211 |
-
-
|
| 212 |
-
-
|
| 213 |
-
-
|
| 214 |
-
- Analyzing code quality (only evaluates comments)
|
| 215 |
|
| 216 |
-
##
|
| 217 |
|
| 218 |
-
### Fine-tune on Your Domain
|
| 219 |
-
```python
|
| 220 |
-
from transformers import AutoModelForSequenceClassification, Trainer, TrainingArguments
|
| 221 |
-
|
| 222 |
-
# Load the pre-trained model
|
| 223 |
-
model = AutoModelForSequenceClassification.from_pretrained("Snaseem2026/code-comment-classifier")
|
| 224 |
-
|
| 225 |
-
# Fine-tune on your domain-specific data
|
| 226 |
-
training_args = TrainingArguments(
|
| 227 |
-
output_dir="./fine_tuned_model",
|
| 228 |
-
learning_rate=1e-5, # Lower learning rate for fine-tuning
|
| 229 |
-
num_train_epochs=2,
|
| 230 |
-
per_device_train_batch_size=8,
|
| 231 |
-
)
|
| 232 |
-
|
| 233 |
-
trainer = Trainer(
|
| 234 |
-
model=model,
|
| 235 |
-
args=training_args,
|
| 236 |
-
train_dataset=your_dataset,
|
| 237 |
-
)
|
| 238 |
-
trainer.train()
|
| 239 |
```
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
year = {2026},
|
| 260 |
-
publisher = {Hugging Face},
|
| 261 |
-
journal = {Hugging Face Model Hub},
|
| 262 |
-
howpublished = {\url{https://huggingface.co/Snaseem2026/code-comment-classifier}}
|
| 263 |
-
}
|
| 264 |
```
|
| 265 |
|
| 266 |
-
##
|
| 267 |
-
|
| 268 |
-
For questions, suggestions, or collaboration:
|
| 269 |
-
- ๐ค Hugging Face: [@Snaseem2026](https://huggingface.co/Snaseem2026)
|
| 270 |
-
- ๐ซ Issues: Report on the model's discussion tab
|
| 271 |
-
|
| 272 |
-
---
|
| 273 |
-
|
| 274 |
-
<div align="center">
|
| 275 |
-
|
| 276 |
-
**Made with โค๏ธ for the developer community**
|
| 277 |
-
|
| 278 |
-
[](https://opensource.org/licenses/MIT)
|
| 279 |
-
[](https://github.com/huggingface/transformers)
|
| 280 |
-
[](https://www.python.org/downloads/)
|
| 281 |
-
|
| 282 |
-
[๐ค Model Hub](https://huggingface.co/Snaseem2026/code-comment-classifier) โข [Report Issue](https://huggingface.co/Snaseem2026/code-comment-classifier/discussions)
|
| 283 |
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
|
| 286 |
-
##
|
| 287 |
-
|
| 288 |
-
- Trained on synthetic data; may require fine-tuning for specific domains
|
| 289 |
-
- English comments only
|
| 290 |
-
- Evaluates comments in isolation without code context
|
| 291 |
-
- Comment quality assessment is subjective
|
| 292 |
-
|
| 293 |
-
## Intended Use
|
| 294 |
|
| 295 |
-
This
|
| 296 |
|
| 297 |
-
##
|
| 298 |
|
| 299 |
-
|
|
|
|
| 300 |
|
| 301 |
-
##
|
| 302 |
|
| 303 |
-
|
| 304 |
-
@misc{code-comment-classifier-2026,
|
| 305 |
-
title={Code Comment Quality Classifier},
|
| 306 |
-
year={2026},
|
| 307 |
-
publisher={Hugging Face},
|
| 308 |
-
howpublished={\url{https://huggingface.co/your-username/code-comment-classifier}}
|
| 309 |
-
}
|
| 310 |
-
```
|
| 311 |
|
| 312 |
---
|
| 313 |
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Code Comment Quality Classifier ๐
|
| 2 |
|
| 3 |
+
A machine learning model that automatically classifies code comments into quality categories to help improve code documentation and review processes.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
## ๐ฏ What Does This Model Do?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
This model analyzes code comments and classifies them into four categories:
|
| 8 |
+
- **Excellent**: Clear, comprehensive, and highly informative comments
|
| 9 |
+
- **Helpful**: Good comments that add value but could be improved
|
| 10 |
+
- **Unclear**: Vague or confusing comments that don't add much value
|
| 11 |
+
- **Outdated**: Comments that may no longer reflect the current code
|
| 12 |
|
| 13 |
+
## ๐ Quick Start
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
### Installation
|
| 16 |
|
| 17 |
+
```bash
|
| 18 |
+
pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
```
|
| 20 |
|
| 21 |
+
### Using the Model
|
| 22 |
|
| 23 |
```python
|
| 24 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 25 |
import torch
|
| 26 |
|
| 27 |
+
# Load the model and tokenizer
|
| 28 |
+
model_name = "Snaseem2026/code-comment-classifier"
|
| 29 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 30 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Classify a comment
|
| 33 |
+
comment = "This function calculates the fibonacci sequence using dynamic programming"
|
| 34 |
+
inputs = tokenizer(comment, return_tensors="pt", truncation=True, max_length=512)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
with torch.no_grad():
|
| 37 |
+
outputs = model(**inputs)
|
| 38 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 39 |
+
predicted_class = torch.argmax(predictions, dim=-1).item()
|
| 40 |
|
| 41 |
+
labels = ["excellent", "helpful", "unclear", "outdated"]
|
| 42 |
+
print(f"Comment quality: {labels[predicted_class]}")
|
| 43 |
+
```
|
| 44 |
|
| 45 |
+
## ๐๏ธ Training the Model
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
To train the model on your own data:
|
| 48 |
|
| 49 |
+
```bash
|
| 50 |
+
python train.py --config config.yaml
|
| 51 |
```
|
|
|
|
| 52 |
|
| 53 |
+
To generate synthetic training data:
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
```bash
|
| 56 |
+
python scripts/generate_data.py
|
|
|
|
| 57 |
```
|
| 58 |
|
| 59 |
+
## ๐ Model Details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
- **Base Model**: DistilBERT (distilbert-base-uncased)
|
| 62 |
+
- **Task**: Multi-class text classification
|
| 63 |
+
- **Classes**: 4 (excellent, helpful, unclear, outdated)
|
| 64 |
+
- **Training Data**: Synthetic code comments with quality labels
|
| 65 |
+
- **License**: MIT
|
| 66 |
|
| 67 |
+
## ๐ Use Cases
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
- **Code Review Automation**: Automatically flag low-quality comments during PR reviews
|
| 70 |
+
- **Documentation Quality Checks**: Audit codebases for documentation quality
|
| 71 |
+
- **Developer Education**: Help developers learn what makes good code comments
|
| 72 |
+
- **IDE Integration**: Real-time feedback on comment quality while coding
|
|
|
|
| 73 |
|
| 74 |
+
## ๐ Project Structure
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
```
|
| 77 |
+
.
|
| 78 |
+
โโโ README.md
|
| 79 |
+
โโโ LICENSE
|
| 80 |
+
โโโ requirements.txt
|
| 81 |
+
โโโ config.yaml
|
| 82 |
+
โโโ train.py # Main training script
|
| 83 |
+
โโโ inference.py # Inference script
|
| 84 |
+
โโโ src/
|
| 85 |
+
โ โโโ __init__.py
|
| 86 |
+
โ โโโ data_loader.py # Data loading utilities
|
| 87 |
+
โ โโโ model.py # Model definition
|
| 88 |
+
โ โโโ utils.py # Helper functions
|
| 89 |
+
โโโ scripts/
|
| 90 |
+
โ โโโ generate_data.py # Generate synthetic training data
|
| 91 |
+
โ โโโ evaluate.py # Evaluation script
|
| 92 |
+
โ โโโ upload_to_hub.py # Upload model to Hugging Face Hub
|
| 93 |
+
โโโ data/
|
| 94 |
+
โ โโโ .gitkeep
|
| 95 |
+
โโโ MODEL_CARD.md # Hugging Face model card
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
```
|
| 97 |
|
| 98 |
+
## ๐ค Contributing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
This is an open-source project! Contributions are welcome. Please feel free to:
|
| 101 |
+
- Report bugs or issues
|
| 102 |
+
- Suggest new features
|
| 103 |
+
- Submit pull requests
|
| 104 |
+
- Improve documentation
|
| 105 |
|
| 106 |
+
## ๐ License
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
| 109 |
|
| 110 |
+
## ๐ Acknowledgments
|
| 111 |
|
| 112 |
+
- Built with [Hugging Face Transformers](https://huggingface.co/transformers/)
|
| 113 |
+
- Base model: [DistilBERT](https://huggingface.co/distilbert-base-uncased)
|
| 114 |
|
| 115 |
+
## ๐ฎ Contact
|
| 116 |
|
| 117 |
+
For questions or feedback, please open an issue on the GitHub repository or reach out on Hugging Face.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
---
|
| 120 |
|
| 121 |
+
**Note**: This model is designed for educational and productivity purposes. Always review automated suggestions with human judgment.
|