Instructions to use MohamedSayed112/sst2-distilbert-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use MohamedSayed112/sst2-distilbert-LoRA with PEFT:
from peft import PeftModel from transformers import AutoModelForSequenceClassification base_model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased") model = PeftModel.from_pretrained(base_model, "MohamedSayed112/sst2-distilbert-LoRA") - Notebooks
- Google Colab
- Kaggle
- DistilBERT SST-2 LoRA Adapter
- Model Description
- Model Details
- Training Configuration
- Evaluation Results
- Quick Usage
- Related Experiment (Full Fine-Tuning Comparison)
- Intended Use & Limitations
- Limitations: Contains adapter weights only (requires loading the base model first); trained strictly on English movie review snippets (max_length=128) and may underperform on sarcasm or domain-specific text.
- Model Description
DistilBERT SST-2 LoRA Adapter
Model Description
This repository contains a LoRA (Low-Rank Adaptation) adapter fine-tuned on distilbert/distilbert-base-uncased for binary sentiment classification (0: Negative, 1: Positive), trained on the SST-2 subset of the GLUE benchmark (nyu-mll/glue).
Note: This repository contains the LoRA adapter weights and configuration only, not the complete base model.
Model Details
- Base Model:
distilbert/distilbert-base-uncased - Architecture: DistilBERT
- Task: Binary Sentiment Classification (
num_labels=2) - Dataset:
nyu-mll/glue(sst2) - Training Split:
train - Evaluation Split:
validation - Fine-Tuning Method: LoRA (
PEFT) - Total Parameters:
67,842,052 - Trainable Parameters:
887,042(1.3075%of total parameters)
Training Configuration
| Parameter | Value |
|---|---|
| Fine-Tuning Method | LoRA |
Rank (r) |
16 |
| LoRA Alpha | 16 |
| LoRA Dropout | 0.1 |
| Target Modules | q_lin, v_lin |
| Modules to Save | classifier |
| Epochs | 3 |
| Batch Size | 16 |
| Learning Rate | 2e-4 |
| Weight Decay | 0.01 |
| Max Sequence Length | 128 |
| Random Seed | 42 |
Evaluation Results
Evaluated on the validation split of SST-2:
| Metric | Score |
|---|---|
| Accuracy | 0.9002 |
| Precision (Positive Class) | 0.8906 |
| Recall (Positive Class) | 0.9167 |
| Macro F1 | 0.9001 |
Confusion Matrix
| Predicted Negative | Predicted Positive | |
|---|---|---|
| Actual Negative | 378 | 50 |
| Actual Positive | 37 | 407 |
Note: Reported metrics are evaluated on the validation split, as SST-2 test labels are withheld on the GLUE benchmark.
Quick Usage
Option 1: Using PeftModel
from peft import PeftModel
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
base_model_id = "distilbert/distilbert-base-uncased"
adapter_id = "MohamedSayed112/sst2-distilbert-LoRA"
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForSequenceClassification.from_pretrained(
base_model_id,
num_labels=2,
)
model = PeftModel.from_pretrained(base_model, adapter_id)
model.eval()
text = "The movie was surprisingly engaging and well-paced."
inputs = tokenizer(
text, return_tensors="pt", truncation=True, max_length=128
)
with torch.inference_mode():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1)
pred = torch.argmax(probs, dim=-1).item()
print(
f"Predicted class: {pred} | Confidence: {probs[0][pred].item():.4f}"
)
Related Experiment (Full Fine-Tuning Comparison)
For the full fine-tuning baseline on the same task and dataset (Accuracy: 0.9197) 'MohamedSayed112/sst2-distilbert-full-ft'
Intended Use & Limitations
Intended Use: English short-text sentiment analysis, educational NLP benchmarks, and parameter-efficient fine-tuning comparisons.
Limitations: Contains adapter weights only (requires loading the base model first); trained strictly on English movie review snippets (max_length=128) and may underperform on sarcasm or domain-specific text.
- Downloads last month
- 53
Model tree for MohamedSayed112/sst2-distilbert-LoRA
Base model
distilbert/distilbert-base-uncased