CoolFace
Modelpublic

Harsh-Gupta/Sentiment-Analysis-BERT-sst2

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
Model Card

๐Ÿค– LoRA-BERT for Sentiment Analysis (SST-2)

This is a lightweight, parameter-efficient BERT model fine-tuned with LoRA (Low-Rank Adaptation) for binary sentiment classification on the SST-2 dataset.


๐Ÿ’ก Model Highlights

  • โ€”โœ… Fine-tuned using LoRA (r=8, ฮฑ=16) on top of bert-base-uncased
  • โ€”โœ… Trained on SST2
  • โ€”โœ… Achieves ~91.17% validation accuracy
  • โ€”โœ… Lightweight: only LoRA adapter weights are updated

๐Ÿ“Š Results

EpochTraining LossValidation LossAccuracy
10.30300.246789.91%
20.19720.242490.94%
30.20830.239591.17%
40.19360.246490.94%
50.19140.249190.83%

Early stopping could be applied from Epoch 3 based on validation metrics.


๐Ÿ› ๏ธ Usage

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from peft import PeftModel, PeftConfig

model_id = "Harsh-Gupta/bert-lora-sentiment"

# Load PEFT config + model
config = PeftConfig.from_pretrained(model_id)
base_model = AutoModelForSequenceClassification.from_pretrained(config.base_model_name_or_path)
model = PeftModel.from_pretrained(base_model, model_id)

# Tokenizer
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)

# Predict
text = "This movie was absolutely amazing!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
    outputs = model(**inputs)
    probs = outputs.logits.softmax(dim=-1)
    pred = probs.argmax().item()

LoRA Configuration

python
LoraConfig(
    r=32,
    lora_alpha=4,
    target_modules=["query", "value"],
    lora_dropout=0.1,
    bias="none",
    task_type="SEQ_CLS"
)

๐Ÿ” Intended Use

  • โ€”Sentiment classification for binary text (positive/negative)
  • โ€”Can be adapted to other domains: movie reviews, product reviews, tweets

๐Ÿง  Author

  • โ€”Harsh Gupta
  • โ€”MCA, Jawaharlal Nehru University (JNU)
  • โ€”GitHub: 2003Harsh