Corpus-specific models

Models trained on one corpus: on the shared labels, on all labels of the corpus, or on its emotion dimensions.

One model per corpus and perspective. You can pick between two kinds: with shared labels or with all labels in the respective corpus. Some corpora also have a model for emotion dimensions (valence and arousal, appraisals or emotion components).

Reset filters

ModelTypeArchitectureLanguageLabelsValidation macro-F1License

Each repository on Hugging Face has the weights (in half precision), a README and card.json with the labels, thresholds and training data. Please cite the papers of the corpora a model was trained on.

How to use these models

The models are Transformers for multi-label classification. If your texts differ from the training data and you have a few hundred labelled texts, we recommend tuning the thresholds on them. With fewer than about 100 texts, stick to our thresholds.

Show code
import json, torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForSequenceClassification, AutoTokenizer

repo = "bamnlp/emotionhub-xlmr-base-general"   # or any model below
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).float().eval()
card = json.load(open(hf_hub_download(repo, "card.json")))  # labels and tuned thresholds

texts = ["I finally got the letter of acceptance!", "They lied to us, again."]
batch = tokenizer(texts, padding=True, truncation=True, max_length=256, return_tensors="pt")
with torch.no_grad():
    probs = torch.sigmoid(model(**batch).logits)
for text, p in zip(texts, probs):
    emotions = [l for l, x in zip(card["labels"], p) if x >= card["thresholds"][l]]
    print(text, emotions or [card["labels"][int(p.argmax())]])  # at least the most probable one

How to use the models with emotion dimensions

The models for valence and arousal, appraisals or emotion components have additional small output layers for the ratings, stored in heads.pt. They sit on the hidden state of the first token; all outputs are between 0 and 1.

Show code
import json, torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForSequenceClassification, AutoTokenizer

repo = "bamnlp/emotionhub-deberta-v3-base-dims-emoprogress-writer"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).float().eval()
card = json.load(open(hf_hub_download(repo, "card.json")))
state = torch.load(hf_hub_download(repo, "heads.pt"), map_location="cpu")

# one small output layer per kind of rating, on the first token's last hidden state
size = model.config.hidden_size
heads = {}
for task, dims in card["aux_dims"].items():
    head = torch.nn.Sequential(torch.nn.Dropout(0.1), torch.nn.Linear(size, size), torch.nn.Tanh(),
                               torch.nn.Dropout(0.1), torch.nn.Linear(size, len(dims)))
    prefix = "heads." + task.replace(":", "__") + ".net."
    head.load_state_dict({k[len(prefix):]: v for k, v in state.items() if k.startswith(prefix)})
    heads[task] = head.eval()

texts = ["My dream was about falling, and I woke up scared."]
batch = tokenizer(texts, padding=True, truncation=True, max_length=256, return_tensors="pt")
with torch.no_grad():
    out = model(**batch, output_hidden_states=True)
    first = out.hidden_states[-1][:, 0]
    for task, head in heads.items():
        for text, values in zip(texts, torch.sigmoid(head(first))):
            print(task, {d: round(v, 2) for d, v in zip(card["aux_dims"][task], values.tolist())})  # all in 0..1