Views
No views yet
roberta-large that predicts valence and arousal of a text (2-output regression), trained on EmoBank.best_roberta_large.pth — PyTorch state_dict for RobertaForSequenceClassification (num_labels=2, outputs [valence, arousal])1import torch
2from huggingface_hub import hf_hub_download
3from transformers import RobertaTokenizer, RobertaForSequenceClassification
4
5model = RobertaForSequenceClassification.from_pretrained("roberta-large", num_labels=2)
6model_path = hf_hub_download(repo_id="RuiSumida/LUFY", filename="best_roberta_large.pth")
7model.load_state_dict(torch.load(model_path, map_location="cpu"))
8model.eval()
9
10tokenizer = RobertaTokenizer.from_pretrained("roberta-large")
11enc = tokenizer("I can't believe we won the finals!", max_length=128,
12 padding="max_length", truncation=True, return_tensors="pt")
13with torch.no_grad():
14 valence, arousal = model(**enc).logits.squeeze()