The model outputs continuous scores for each dimension; Arousal and Dominance
scores are correlated with Bradley-Terry scores derived from pairwise annotations.
The example below assumes you have cloned this repository and downloaded the model files from the Hugging Face repo into the current working directory.
1from huggingface_hub import snapshot_download
2from pathlib import Path
3import importlib.util
4
5repo_id = "edsi-umd/Reward-EmoPair"
6local_dir = snapshot_download(repo_id=repo_id, repo_type="model")
7
8# Dynamically load the RewardModel class from the downloaded repository
9reward_model_path = Path(local_dir) / "RewardModel.py"
10spec = importlib.util.spec_from_file_location("reward_model", str(reward_model_path))
11reward_mod = importlib.util.module_from_spec(spec)
12spec.loader.exec_module(reward_mod)
13RewardModel = reward_mod.RewardModel
14
15model = RewardModel(model_name="roberta-large", max_length=256)
16checkpoint = Path(local_dir) / "pytorch_model.pth"
17model.load(str(checkpoint))
18model.eval()
19
20scores = model.score_text("I can't believe how amazing this feels!")
21print(scores) # {'valence': ..., 'arousal': ..., 'dominance': ...}
If you prefer to keep the class definition in a separate file, the same snippet works as long as the repository checkout is on sys.path and the checkpoint file is available next to your current working directory.
If you use this model, please cite the EmoPair paper and dataset using the most recent citation on the GitHub repository,
https://github.com/EDSI-UMD-College-Park/EMOPAIR.