stanfordnlp/imdb
Viewer • Updated • 100k • 271k • 380
How to use hrnrxb/roberta-bilstm-attention-sentiment with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="hrnrxb/roberta-bilstm-attention-sentiment") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("hrnrxb/roberta-bilstm-attention-sentiment", dtype="auto")This model combines roberta-base embeddings with a BiLSTM layer and attention mechanism to classify the sentiment of movie reviews, even when the language includes sarcasm, irony, or mixed emotional signals.
This model takes the output of RoBERTa, processes it through a BiLSTM, applies attention to focus on important parts of the sentence, and classifies sentiment as Positive (1) or Negative (0).
Standard BERT-based sentiment classifiers often fail on subtle language such as:
This model aims to address that by combining contextual language modeling (RoBERTa) with sequence learning (BiLSTM) and attention-based interpretability.
| Input | Prediction |
|---|---|
| "If I had a dollar for every cliché..." | 🔴 Negative |
| "It’s fine. Just fine. Totally fine." | 🔴 Negative |
| "The acting was great, but the plot..." | 🔴 Negative |
| "Brilliant visuals and solid pacing." | 🟢 Positive |
from transformers import RobertaTokenizer
from my_model import RobertaBiLSTMAttention # the custom model
import torch
tokenizer = RobertaTokenizer.from_pretrained("roberta-base")
model = RobertaBiLSTMAttention()
model.load_state_dict(torch.load("pytorch_model.bin"))
model.eval()
text = "It’s fine. Just fine. Totally… fine."
tokens = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True, max_length=128)
logits = model(tokens["input_ids"], tokens["attention_mask"])
pred = torch.argmax(logits, dim=1).item()
print("Sentiment:", "Positive" if pred == 1 else "Negative")