Views
No views yet
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.| 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 |
1from transformers import RobertaTokenizer
2from my_model import RobertaBiLSTMAttention # the custom model
3import torch
4
5tokenizer = RobertaTokenizer.from_pretrained("roberta-base")
6model = RobertaBiLSTMAttention()
7model.load_state_dict(torch.load("pytorch_model.bin"))
8model.eval()
9
10text = "It’s fine. Just fine. Totally… fine."
11tokens = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True, max_length=128)
12logits = model(tokens["input_ids"], tokens["attention_mask"])
13pred = torch.argmax(logits, dim=1).item()
14print("Sentiment:", "Positive" if pred == 1 else "Negative")