stanfordnlp/imdb
Viewer • Updated • 100k • 177k • 472
This model is a fine-tuned version of distilbert-base-uncased on the IMDb dataset for sentiment analysis, using LoRA (Low-Rank Adaptation) for efficient fine-tuning.
LABEL_0: NEGATIVELABEL_1: POSITIVEr=8 (rank)lora_alpha=16lora_dropout=0.05q_lin, v_linLABEL_1 (POSITIVE, score: 0.5600)LABEL_0 (NEGATIVE, score: 0.5388)pip install transformers peft torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline
from peft import PeftModel, PeftConfig
import torch
# Load model and tokenizer
model_name = "MyselfRee/distilbert-base-uncased-imdb-lora"
config = PeftConfig.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained("distilbert/distilbert-base-uncased", num_labels=2)
model = PeftModel.from_pretrained(model, model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Create pipeline
classifier = TextClassificationPipeline(
model=model,
tokenizer=tokenizer,
framework="pt",
task="sentiment-analysis",
device=0 if torch.cuda.is_available() else -1
)
# Test inference with label mapping
label_map = {"LABEL_0": "NEGATIVE", "LABEL_1": "POSITIVE"}
def map_labels(prediction):
prediction[0]["label"] = label_map[prediction[0]["label"]]
return prediction
print(map_labels(classifier("The movie is good"))) # Output: [{'label': 'POSITIVE', 'score': 0.5600}]
print(map_labels(classifier("The movie is bad"))) # Output: [{'label': 'NEGATIVE', 'score': 0.5388}]
peft library for LoRA weights.LABEL_0 (NEGATIVE) and LABEL_1 (POSITIVE)—use the map_labels function in the inference example to display proper labels.