Tobias Widmann
  • About
  • Publications
  • Work in Progress
  • Grants & Awards
  • Tools
  • Teaching
  • Media
  • Contact

Tools

Open-source research software

Measuring emotion and morality in political text

Four validated, freely available tools for computational social science — two dictionaries and two fine-tuned multilingual transformer models. Each one is documented in a research paper, ships with code to apply it, and can be tried right here on this page.

  • 4validated tools
  • 8discrete emotions
  • 5moral foundations, virtue & vice
  • 6dictionary languages; transformer base covers 100
  • ≈40kcrowd-coded sentences behind the models
3x8emotions pol_emo_mDeBERTa2 mMPD Moral-Emotional mDeBERTa

From word lists to multilingual transformers

1
DictionariesCurated word lists, expanded with inflections and word embeddingstransparent · fast · word-level
2
Word embeddings + neural netsSentence vectors from locally trained embeddings, one classifier per emotionsemantic similarity
3
Fine-tuned transformerELECTRA fine-tuned on ~10,000 crowd-coded German sentencescontext-aware
4
Multilingual transformersmDeBERTa-v3 models fine-tuned on crowd-coded sentences in up to six languages100-language base

Discrete emotions

Two tools measure appeals to the same eight discrete emotions — four negative, four positive — so that dictionary-based and transformer-based measurements can be compared directly.

  • Anger
  • Fear
  • Disgust
  • Sadness
  • Joy
  • Enthusiasm
  • Pride
  • Hope

3x8emotions ed8

Three tools to measure eight discrete emotions in German political text

  • Dictionary
  • Word embeddings + neural nets
  • ELECTRA transformer
  • German
  • R · Python
  • GitHub
  • Paper (Political Analysis)
  • Data & code

The ed8 dictionary contains 20,582 German terms assigned to anger, fear, disgust, sadness, joy, enthusiasm, pride and hope. It comes with two learned alternatives built on the same crowd-coded data: neural-network classifiers on locally trained word embeddings, and a fine-tuned ELECTRA transformer. Together they let researchers choose between transparency (dictionary), semantic generalisation (embeddings) and contextual accuracy (transformer). All three outperform widely used off-the-shelf dictionaries such as LIWC and the translated NRC EmoLex.

How the dictionary works

Textspeeches, posts, manifestos
Tokenise & cleanlower-case, drop punctuation, numbers, URLs and stopwords; join negations (“nicht …”)
Look upmatch each word against eight emotion word lists
Countmatches per emotion and document
Normalisedivide by document length → share of emotional terms

Try the ed8 dictionary

Type or paste German text — the dictionary is applied live in your browser

Loading…

Facts & validation

  • Dictionary size20,582 terms: 19,091 assigned manually, 1,491 added via word embeddings (incl. inflections)
  • Validation data≈10,000 crowd-coded sentences (5 coders each) from Bundestag speeches and party Facebook posts; ≈10,000 more for robustness
  • Transformer vs. dictionarythe fine-tuned ELECTRA model scores on average 18 F1 points higher than ed8
  • Off-the-shelf baselinesbest LIWC F1 = 0.40; translated NRC EmoLex as low as 0.09 (disgust)
  • Unit of analysisdocuments (dictionary) or sentences (embedding & transformer classifiers)
  • Apply withR (quanteda / keras) and Python (transformers); free for academic research
Cite: Widmann & Wich (2023), Political Analysis 31(4)
@article{widmann2023emotions,
  title = {Creating and Comparing Dictionary, Word Embedding, and Transformer-Based Models to Measure Discrete Emotions in German Political Text},
  author = {Widmann, Tobias and Wich, Maximilian},
  journal = {Political Analysis},
  year = {2023},
  volume = {31},
  number = {4},
  pages = {626--641},
  doi = {10.1017/pan.2022.15}
}

pol_emo_mDeBERTa2

Multilingual transformer classifier for eight discrete emotions in political communication

  • Transformer
  • mDeBERTa-v3-base
  • Multilingual
  • Python
  • MIT licence
  • GitHub
  • Download model
  • Paper (Political Analysis)

A successor to the ELECTRA model above: Microsoft’s multilingual mDeBERTa-v3-base — pre-trained on text from 100 languages — fine-tuned on the full set of 19,620 crowd-coded German sentences (80 / 20 train–test split). Because the base model is multilingual, the classifier transfers to other languages without any additional training: on more than 1,200 English, Spanish and French test sentences it reaches a macro F1 of 0.81. It returns one probability per emotion, so a sentence can carry several emotional appeals at once.

How the model works

Sentenceany language
Subword tokensSentencePiece splits words into pieces shared across languages
mDeBERTa encoder12 transformer layers read every token in context
Sentence vectorthe [CLS] representation summarises the sentence
8 probabilitiesa sigmoid output per emotion; label = 1 if ≥ 0.65

See the model’s predictions

Pick an example sentence

Illustrative sentences written in the style of political communication; the probabilities are the model’s actual output, computed with the released weights. (The model is ~1 GB, so it cannot run inside a web page.)

    Model input

    Facts & validation

    • Base modelmicrosoft/mdeberta-v3-base, pre-trained on CC100 (100 languages)
    • Fine-tuning data19,620 crowd-coded sentences from German political communication, 80 / 20 train–test split
    • Output8 sigmoid probabilities (multi-label); threshold 0.65 in the reference code
    • Cross-lingual test>1,200 generated English, Spanish and French sentences: macro F1 0.81
    • Apply withPython (PyTorch + transformers); notebook and example data included
    • LicenceMIT — please cite the paper
    Emotion
    F1 · German test set
    F1 · EN / ES / FR test
    Anger
    0.78
    0.84
    Fear
    0.69
    0.83
    Disgust
    0.73
    0.66
    Sadness
    0.74
    0.88
    Joy
    0.83
    0.91
    Enthusiasm
    0.69
    0.66
    Pride
    0.71
    0.89
    Hope
    0.62
    0.77
    Macro average
    0.72
    0.81
    Cite: Widmann & Wich (2023), Political Analysis 31(4)
    @article{widmann2023emotions,
      title = {Creating and Comparing Dictionary, Word Embedding, and Transformer-Based Models to Measure Discrete Emotions in German Political Text},
      author = {Widmann, Tobias and Wich, Maximilian},
      journal = {Political Analysis},
      year = {2023},
      volume = {31},
      number = {4},
      pages = {626--641},
      doi = {10.1017/pan.2022.15}
    }

    Moral language

    Two tools capture appeals to right and wrong: a multilingual dictionary organised by moral foundations, and a transformer model that detects moral and emotional appeals and their valence.

    • Care / Harm
    • Fairness / Cheating
    • Loyalty / Betrayal
    • Authority / Subversion
    • Sanctity / Degradation
    • General moral terms

    mMPD

    Multilingual Moral Political Dictionary — moral language in six languages

    • Dictionary
    • Danish
    • Dutch
    • English
    • German
    • Spanish
    • Swedish
    • R
    • MIT licence
    • GitHub
    • Paper (BJPS)
    • Data & code

    Developed with Kristina Bakkær Simonsen, the mMPD extends Jung’s (2020) English-language moral political dictionary into a family of six parallel dictionaries. Professional native-speaker linguists translated the English entries into Danish, Dutch, German and Swedish, adding grammatical variants and moral synonyms, and a Spanish dictionary completes the set; each language file lists between roughly 1,600 (English) and 6,200 (German) inflected forms. Terms are organised by the five moral foundations — each split into virtue and vice — plus general moral vocabulary, and aggregated into positive, negative and overall morality scores. The dictionary was built to compare the moralisation of immigration across eight Western democracies and up to six decades of parliamentary speech.

    How it works

    Textin any of the six languages
    Tokenise & cleanlower-case; drop punctuation, numbers and URLs
    Look upmatch against the language’s moral word lists (14 categories)
    Countper foundation, virtue vs. vice, and overall
    Normalisedivide by document length → moral share, comparable across languages

    Try the dictionary

    Choose a language, then edit the text

    Loading…

    Facts & validation

    • LanguagesDanish, Dutch, English, German, Spanish, Swedish
    • Categoriescare/harm, fairness/cheating, loyalty/betrayal, authority/subversion, sanctity/degradation, general; aggregated to positive, negative, morality
    • ConstructionJung’s (2020) English moral dictionary, de-stemmed and extended, translated by professional linguists with inflections and synonyms
    • Validationalmost 13,000 crowd-coded sentences; clearly outperforms the original English Moral Foundations Dictionary
    • Applied toimmigration speeches in eight parliaments (AT, CA, DE, DK, NL, SE, UK, US) over up to six decades
    • Apply withR (quanteda); YAML dictionary files, MIT licence — please cite the paper
    Cite: Simonsen & Widmann (2025), British Journal of Political Science 55
    @article{simonsen2025moralize,
      title = {When Do Political Parties Moralize? A Cross-National Study of the Use of Moral Language in Political Communication on Immigration},
      author = {Simonsen, Kristina Bakk{\ae}r and Widmann, Tobias},
      journal = {British Journal of Political Science},
      year = {2025},
      volume = {55},
      doi = {10.1017/S0007123425000122}
    }

    Political-Moral-Emotional mDeBERTa

    Multilingual transformer classifier for moral and emotional appeals and their valence

    • Transformer
    • mDeBERTa-v3-base
    • Fine-tuned in 6 languages
    • Python
    • MIT licence
    • GitHub
    • Download model
    • Paper (preprint)

    A multilingual mDeBERTa-v3 model fine-tuned, together with Kristina Bakkær Simonsen, on more than 20,000 sentences of political communication in Danish, Dutch, English, German, Spanish and Swedish, each crowd-coded on Prolific. For every sentence it returns four probabilities: whether it contains a moral appeal, an emotional appeal, and whether that appeal is positive or negative. Because the base model was pre-trained on 100 languages, it can also be applied beyond the six fine-tuning languages. It underpins our study of moral appeals in ten Western democracies over six decades.

    How the model works

    Sentenceany language
    Subword tokensSentencePiece pieces shared across languages
    mDeBERTa encoder12 transformer layers read every token in context
    Sentence vectorthe [CLS] representation summarises the sentence
    4 probabilitiesmorality, emotionality, positive, negative; label = 1 if ≥ 0.5

    See the model’s predictions

    Pick an example sentence

    Illustrative sentences written in the style of political communication; the probabilities are the model’s actual output, computed with the released weights.

      Model input

      Facts & validation

      • Base modelmicrosoft/mdeberta-v3-base, pre-trained on CC100 (100 languages)
      • Fine-tuning data>20,000 crowd-coded sentences (Prolific) in six languages, 80 / 20 train–test split
      • Output4 sigmoid probabilities: morality, emotionality, positive, negative; threshold 0.5
      • Apply withPython (PyTorch + transformers); notebook and example data included
      • LicenceMIT — please cite the paper
      F1 on held-out test data
      English
      n = 985
      Spanish
      n = 499
      Dutch
      n = 500
      German
      n = 496
      Swedish
      n = 796
      Danish
      n = 795
      Morality
      0.79
      0.75
      0.72
      0.70
      0.67
      0.64
      Emotionality
      0.76
      0.74
      0.66
      0.69
      0.65
      0.63
      Positive
      0.81
      0.77
      0.74
      0.78
      0.71
      0.69
      Negative
      0.79
      0.79
      0.72
      0.75
      0.69
      0.71
      Cite: Simonsen & Widmann (2023), The Politics of Right and Wrong
      @article{simonsen2023rightwrong,
        title = {The Politics of Right and Wrong: Moral Appeals in Political Communication over Six Decades in Ten Western Democracies},
        author = {Simonsen, Kristina Bakk{\ae}r and Widmann, Tobias},
        journal = {OSF Preprints},
        year = {2023},
        doi = {10.31219/osf.io/m6qkg}
      }

      Which tool for which job?

      Tool
      Measures
      Method
      Languages
      Best suited for
      3x8emotions / ed8
      8 discrete emotions
      Dictionary (+ embedding and ELECTRA classifiers)
      German
      Transparent, fast, corpus-scale measurement with word-level explanations
      pol_emo_mDeBERTa2
      8 discrete emotions
      Fine-tuned multilingual transformer
      Trained on German; validated on EN, ES, FR; base covers 100
      Context-sensitive sentence classification across languages
      mMPD
      Moral language by foundation, virtue / vice
      Dictionary
      DA, DE, EN, ES, NL, SV
      Comparable moral-language measures across countries and decades
      Moral-Emotional mDeBERTa
      Moral and emotional appeals, positive / negative
      Fine-tuned multilingual transformer
      Fine-tuned in 6 languages; base covers 100
      Sentence-level detection of (moral-)emotional appeals

      All tools are free for academic research; please cite the corresponding paper when you use them. The demos on this page run in your browser: the dictionary demos are light-weight re-implementations of the quanteda pipelines shipped with each tool (results can differ marginally from the R code, e.g. in tokenisation edge cases), and the transformer examples show the models’ actual predictions computed offline with the released weights. Questions or ideas for collaboration: widmann@ps.au.dk.