Views
No views yet
authdetect is a classification model for detecting authoritarian discourse in political speeches, leveraging a novel approach to studying latent political concepts through language modeling. Rather than relying on predefined rules or rigid definitions of authoritarian discourse, the model operates on the premise that authoritarian leaders naturally exhibit such discourse in their speech patterns. Essentially, the model assumes that "authoritarians talk like authoritarians," allowing it to discern instances of authoritarian rhetoric from speech segments. Structured as a regression problem with weak supervision logic, the model classifies text segments based on their association with either authoritarian or democratic discourse. By training on speeches from both authoritarian and democratic leaders, it learns to distinguish between these two distinct forms of political rhetoric.roberta-base model using 77 years of speech data from the UN General Assembly. Training design combines the transcripts of political speeches in English with a weak supervision setup under which the training data are annotated with the V-Dem polyarchy index (i.e., polyarchic status) as the reference labels. The model is trained for predicting the index value of a speech, linking the presented narratives with the virtual quality of democracy of the speaker’s country (rather than with the speaker himself). The corpus quality ensures robust temporal (1946–2022) and spatial (197 countries) representation, resulting in a well-balanced training dataset. Although the training data are domain-specific (the UN General Assembly), the model trained on the UNGD corpus appears to be robust across various sub-domains, demonstrating its capacity to scale well across regions and contexts. Rather than using whole speeches as input data for training, I utilize a sliding window of sentence trigrams splitting the raw transcripts into uniform snippets of text mapping the political language of world leaders. As the goal is to model the varying context of presented ideas in the analyzed speeches rather than the context of the UN General Assembly debates, the main focus is on the particularities of the language of reference groups (authoritarian/democratic leaders). The final dataset counts 1 062 286 sentence trigrams annotated with EDI scores inherited from the parent documents (μ = 0.430, 95% CI [0.429, 0.430]).trankit library no longer works due to broken dependencies that cannot be resolved within the same Colab session. As a workaround, the trankit library has been replaced with the stanza toolkit (how_to_use_authdetect_w_stanza.ipynb) in the paper's Zenodo repository (https://doi.org/10.5281/zenodo.13920399).Stanza performs the same functions as trankit and does not have the same dependency compatibility issues. This is the recommended pipeline for Google Colab and serves as a functional alternative to trankit, if needed.1# install required libraries if needed
2pip install simpletransformers
3pip install trankit==1.1.1
4
5# load all libraries
6import simpletransformers.classification as cl
7import trankit
8import pandas as pd
9
10# sample text (excerpt from the UNGD 2024 speech delivered by Song Kim, Permanent Representative of the Democratic People’s Republic of Korea at the UN.)
11sample_text = "Joining here are the member states of NATO, which is an outside force beyond the region and an exclusive military bloc. They are strengthening military cooperation with the U.S. and ROK, abusing the signboard of UN command, which should have been dismantled decades ago, in accordance with the UNGA resolution. They are storing up military confrontation still further by deploying warships and aircrafts in the hotspot region of the Korean Peninsula. Such being the case, they blame us for threatening them. and the peace and stability of the region and beyond with nuclear weapons. Then who had developed and used nuclear weapons against humanity for the first time in history? Who has introduced nuclear weapons into the Korean Peninsula in the last century and posed a nuclear threat to the DPRK over the century? Who on earth is talking unhesitatingly about the end of regime of a sovereign state and maintaining first use of nuclear weapons against the DPRK as its national policy? It is not that the DPRK's position of nuclear weapons makes the U.S. hostile towards us."
12
13# load the trankit pipeline with the English model; this pipe uses a deep learning model for sentence tokenization (much more precise than rule-based models)
14p = trankit.Pipeline(lang='english', embedding='xlm-roberta-base', gpu=True, cache_dir='./cache')
15
16# split the text into sentences
17sentences_raw = pd.DataFrame.from_dict(p.ssplit(sample_text))
18
19# normalized dataframe
20sentences_norm = pd.json_normalize(sentences_raw['sentences'].tolist())
21
22# helper function for creating sentence trigrams
23def create_ngram(text):
24 no_steps = len(text) - 2
25 indexes = [list(range(x, x + 3)) for x in range(no_steps)]
26 return [' '.join(text[i] for i in index) for index in indexes]
27
28# Create sentence trigrams
29sentence_trigram = create_ngram(sentences_norm['text'].tolist())
30
31# create a DataFrame with sentence trigrams
32sentence_df = pd.DataFrame({'sent_trigram': sentence_trigram})
33
34# load the pretrained authdetect model from the Huggingface Hub
35model = cl.ClassificationModel("roberta", "mmochtak/authdetect")
36
37# apply the model on the prepared sentence trigrams
38prediction = model.predict(to_predict = sentence_df["sent_trigram"].tolist())
39
40# add scores to the existing dataframe
41sentence_df = sentence_df.assign(predict = prediction[1])
42
43print(sentence_df)
44@article{mochtak_chasing_2024,
title = {Chasing the authoritarian spectre: {Detecting} authoritarian discourse with large language models},
issn = {1475-6765},
shorttitle = {Chasing the authoritarian spectre},
url = {https://onlinelibrary.wiley.com/doi/abs/10.1111/1475-6765.12740},
doi = {10.1111/1475-6765.12740},
journal = {European Journal of Political Research},
author = {Mochtak, Michal},
keywords = {authoritarian discourse, deep learning, detecting authoritarianism, model, political discourse},
}