Edit model card

Model description

An xlm-roberta-large model fine-tuned on ~1,7 million annotated statements contained in the Manifesto Corpus (version 2024a). The model can be used to categorize any type of text into 56 different political topics according to the Manifesto Project's coding scheme (Handbook 4). It works for all languages the xlm-roberta model is pretrained on (overview), just note that it will perform best for the 38 languages contained in the Manifesto Corpus:

armenian bosnian bulgarian catalan croatian
czech danish dutch english estonian
finnish french galician georgian german
greek hebrew hungarian icelandic italian
japanese korean latvian lithuanian macedonian
montenegrin norwegian polish portuguese romanian
russian serbian slovak slovenian spanish
swedish turkish ukrainian

The context model variant additionally incorporates the surrounding sentences of a statement to improve the classification results for ambiguous sentences. (See Training Procedure for details)

Important

We slightly modified the Classification Head of the XLMRobertaModelForSequenceClassification model (removed the tanh activation and the intermediate linear layer) as that improved the model performance for this task considerably. To correctly load the full model, include the trust_remote_code=True argument when using the from_pretrained method.

How to use

import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

model = AutoModelForSequenceClassification.from_pretrained("manifesto-project/manifestoberta-xlm-roberta-56policy-topics-context-2024-1-1", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("xlm-roberta-large")

sentence = "These principles are under threat."
context = "Human rights and international humanitarian law are fundamental pillars of a secure global system. These principles are under threat. Some of the world's most powerful states choose to sell arms to human-rights abusing states."
# For sentences without additional context, just use the sentence itself as the context.
# Example: context = "These principles are under threat."


inputs = tokenizer(sentence,
                   context,
                   return_tensors="pt",
                   max_length=300,  #we limited the input to 300 tokens during finetuning
                   padding="max_length",
                   truncation=True
                   )

logits = model(**inputs).logits

probabilities = torch.softmax(logits, dim=1).tolist()[0]
probabilities = {model.config.id2label[index]: round(probability * 100, 2) for index, probability in enumerate(probabilities)}
probabilities = dict(sorted(probabilities.items(), key=lambda item: item[1], reverse=True))
print(probabilities)
# {'201 - Freedom and Human Rights': 86.58, '107 - Internationalism: Positive': 8.12, '106 - Peace': 1.67...

predicted_class = model.config.id2label[logits.argmax().item()]
print(predicted_class)
# 201 - Freedom and Human Rights

Training Procedure

Training of the model took place on all quasi-sentences of the Manifesto Corpus (version 2024a), minus 10% that were kept out of training for the final test and evaluation results. This results in a training dataset of 1,691,707 quasi-sentences. As our context-including model input poses the threat of data-leakage problems between train and test data, we refrained from randomly splitting quasi-sentences into train and test data. Instead, we randomly split the dataset on the manifesto level, so that 1828 manifestos and all their quasi-sentences were assigned to the train set and 203 to the test set.

As training parameters, we used the following settings: learning rate: 1e-5, weight decay: 0.01, epochs: 1, batch size: 4, gradient accumulation steps: 4 (effective batch size: 16).

Context

To adapt the model to the task of classifying statements in manifestos we made some modifications to the traditional training setup. Given that human annotators in the Manifesto Project are encouraged to use surrounding sentences to interpret ambiguous statements , we combined statements with their context for our model's input. Specifically, we used a sentence-pair input, where the single to-be-classified statement gets followed by the separator token followed by the whole bigger context of length 200 tokens, in which the statement to-be-classified is embedded. Here is an example:

"<s> We must right the wrongs in our democracy, </s> </s> To turn this crisis into a crucible, from which we will forge a stronger, brighter, and more equitable future. We must right the wrongs in our democracy, redress the systemic injustices that have long plagued our society,throw open the doors of opportunity for all Americans and reinvent our institutions at home and our leadership abroad. </s>".

The second part, which contains the context, is greedily filled until it contains 200 tokens. Our tests showed that including the context helped to improve the performance of the classification model considerably (~7% accuracy). We tried other approaches like using two XLM-RoBERTa models as a duo, where one receives the sentence and one the context, and a shared-layer model, where both inputs are fed separately trough the same model. Both variants performed similarly to our sentence pair approach, but lead to higher complexity and computing costs, which is why we ultimately opted for the sentence pair way to include the surrounding context.

Model Performance

The model was evaluated on a test set of 200,920 annotated manifesto statements.

Overall

Accuracy Top2_Acc Top3_Acc Precision Recall F1_Macro MCC Cross-Entropy
Sentence Model 0.57 0.73 0.81 0.48 0.43 0.45 0.55 1.47
Context Model 0.64 0.81 0.88 0.55 0.52 0.53 0.63 1.15

Citation

Please cite the model as follows:

Burst, Tobias / Lehmann, Pola / Franzmann, Simon / Al-Gaddooa, Denise / Ivanusch, Christoph / Regel, Sven / Riethmüller, Felicia / Weßels, Bernhard / Zehnter, Lisa (2024): manifestoberta. Version 56topics.context.2024.1.1. Berlin: Wissenschaftszentrum Berlin für Sozialforschung (WZB) / Göttingen: Institut für Demokratieforschung (IfDem). https://doi.org/10.25522/manifesto.manifestoberta.56topics.context.2024.1.1

@misc{Burst:2024,
  Address = {Berlin / Göttingen},
  Author = {Burst, Tobias AND Lehmann, Pola AND Franzmann, Simon AND Al-Gaddooa, Denise AND Ivanusch, Christoph AND Regel, Sven AND Riethmüller, Felicia AND Weßels, Bernhard AND Zehnter, Lisa},
  Publisher = {Wissenschaftszentrum Berlin für Sozialforschung / Göttinger Institut für Demokratieforschung},
  Title = {manifestoberta. Version 56topics.context.2024.1.1},
  doi = {10.25522/manifesto.manifestoberta.56topics.context.2024.1.1},
  url = {https://doi.org/10.25522/manifesto.manifestoberta.56topics.context.2024.1.1},     
  Year = {2024},
Downloads last month
209
Safetensors
Model size
560M params
Tensor type
I64
·
F32
·
Inference API
Unable to determine this model's library. Check the docs .