Views
No views yet
distilbert-base-uncased using LoRA (Low-Rank Adaptation) for 5-class star rating prediction (1-5 stars) on Singapore digital bank reviews.| Metric | Score |
|---|---|
| Test Accuracy | 0.7619 |
| Precision (Macro) | 0.3064 |
| Recall (Macro) | 0.3597 |
| F1-Score (Macro) | 0.3307 |
| MAE (Mean Absolute Error) | 0.6000 stars |
1from peft import PeftModel, PeftConfig
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4# Load configuration
5config = PeftConfig.from_pretrained("ajiayi/bert-peft-singapore-digi-banks")
6
7# Load base model
8base_model = AutoModelForSequenceClassification.from_pretrained(
9 config.base_model_name_or_path,
10 num_labels=5
11)
12
13# Load PEFT adapter
14model = PeftModel.from_pretrained(base_model, "ajiayi/bert-peft-singapore-digi-banks")
15tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
16
17# Make predictions
18text = "Love this bank! Best interest rates in Singapore."
19inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
20outputs = model(**inputs)
21predicted_stars = outputs.logits.argmax(dim=1).item() + 1 # Convert 0-4 to 1-5
22print(f"Predicted rating: {predicted_stars} stars")distilbert-base-uncased (66M parameters)q_lin, v_lin (attention query and value layers)1from peft import PeftModel
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3import torch
4
5# Load model and tokenizer
6model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased", num_labels=5)
7model = PeftModel.from_pretrained(model, "ajiayi/bert-peft-singapore-digi-banks")
8tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
9
10# Predict
11def predict_rating(text):
12 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
13 model.eval()
14 with torch.no_grad():
15 outputs = model(**inputs)
16 prediction = outputs.logits.argmax(dim=1).item()
17 return prediction + 1 # Convert 0-indexed to 1-5 stars
18
19# Example
20review = "Great banking app! Very user-friendly interface."
21stars = predict_rating(review)
22print(f"Predicted: {stars} stars")1@misc{peft-singapore-banks,
2 author = {Your Name},
3 title = {PEFT DistilBERT for Singapore Bank Review Classification},
4 year = {2025},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/ajiayi/bert-peft-singapore-digi-banks}}
7}