Unifying the Extremes: Developing a Unified Model for Detecting and Predicting Extremist Traits and Radicalization
- This project uses a Conda environment for managing dependencies. To create and activate the environment:
# Clone the repository
git clone https://github.com/humanlab/extremism.git
cd extremism
# Create the Conda environment
conda env create -f environment.yml
# Activate the environment
conda activate extremism- Please install PyTorch
| Scale | Source | Construct(s) Assessed | # of Items | bibkey |
|---|---|---|---|---|
| Extremism Scale | Ozer and Bertelsen (2018) | General Extremist Attitudes | 14 | ozer-2018-capturing |
| Social Dominance Orientation | Ho et al. (2015) | Preferences for Social Hierarchy | 8 | ho2015nature |
| Radicalism Intention | Moskalenko & McCauley (2009) | Propensity for Radical Action | 4 | moskalenko2009measuring |
| Violent Intention | Obaidi et al. (2018a, 2018b) | Likelihood of Violent Behavior | 7 | obaidi2018living, obaidi2018mistreatment |
| Nationalism Scale | Weiss (2003) | National Identity and Superiority | 4 | weiss2003cross |
| Right-Wing Authoritarianism | Zakrisson (2005) | Obedience to Authority and Tradition | 15 | zakrisson2005construction |
| Self-Categorization Scale | Ellemers et al. (1999) | Group Identity and Affiliation | 3 | ellemers1999self |
| Dirty Dozen | Jonason & Webster (2010) | "Dark" Personality Traits | 12 | jonason2010dirty |
| General Extremist | Jungkunz et al. (2024) | Broad Extremist Tendencies | 5 | jungkunz2024measuring |
| Left-Wing Radical | Jungkunz et al. (2024) | Radical Left Ideological Views | 6 | jungkunz2024measuring |
| Right-Wing Radical | Jungkunz et al. (2024) | Radical Right Ideological Views | 7 | jungkunz2024measuring |
| Ethnic Intolerance | Weiss (2003) | Xenophobic Attitudes | 4 | weiss2003cross |
- Request access to the datasets: [data request link]
- Place the CSV files in:
data/final_dataset/ - Use the
--dataflag with one of the dataset names below:
python item_scoring.py --data sample| Dataset Name | Description |
|---|---|
sample |
5 random posts from Reddit (for demo) |
stormfront |
White supremacist forum posts |
poli |
Political discussion posts |
incel |
Involuntary celibate forum posts |
control |
Baseline/control forum posts |
isis |
Jihadist forum posts |
incel_history |
User histories before joining incel |
random |
Large set of random online posts |
To use your own dataset, just pass the file path and the name of the text column using --custom-dataset and --text-column:
python item_scoring.py \
--custom-dataset path/to/your_file.csv \
--text-column name_of_text_columnYou can choose one or more scales used in our paper (stored in data/scales/) by name with the --scale flag. Multiple scales can be passed to run together in one job. You can also use your own custom scale by passing in a .txt file path. Each scale file should list the scale items, one per line.
python item_scoring.py --scale jungkunz_gex --scale RWA --scale /path/to/my_scale.txtTo replicate the Extremism Eleven Factors, use all the scales using all as the flag: --scale all. This will extract all the extremism scale similarity scores and save to a single file.
python item_scoring.py --scale allOutput will be saved automatically in data/irt_data/ unless you specify --output.
- To save somewhere else, use the
--outputoption to specify the desired file path. - If the file already exists and you want to overwrite it, the script requires you to use
-w.
This module provides functionality for applying factor analysis models to extract factor scores from item-scored similarity data.
The extract_factor_scores.py script is designed to:
- Load a pre-trained 11-factor extremism model
- Apply the factor model to item-scored similarity data
- Generate factor scores for psychological constructs related to extremism
- Save the resulting factor scores for downstream analysis
Fucntion apply_factor_model(fa, df):
- Purpose: Loads a pre-trained factor analysis model from a pickle file and applies it to transform input data into factor scores
- Parameters:
factor_model_path: ath to the model file. Defaults to"model/extremist_11_factor_model.pkl"df: pandas DataFrame containing the similarity scores to transform
- Returns: numpy array of factor scores
Function train_and_save_factor_model(df, n_factors, negative_code_cols, model_path):
- Purpose: Trains a new factor analysis model and saves it to disk
- Parameters:
df: pandas DataFrame with training datan_factors(int, optional): Number of factors to extract. Defaults to 11negative_code_cols(list, optional): Columns that need reverse codingmodel_path(str, optional): Where to save the new model. Defaults to"model/new_factor_model.pkl"
- Returns: Fitted FactorAnalyzer object
- Note: Applies reverse coding to specified columns before training
To get the scores for downstream analysis:
- Item Scoring: Run
item_scoring.pyto generate similarity scores - Factor Extraction: Run
extract_factor_scores.pyto convert similarities to factor scores - Analysis: Use the factor scores for downstream psychological analysis
If you use our code, please cite our work. Note: Allison Lahnala and Vasudha Varadarajan contributed equally to this work (co-first authors).
@article{Lahnala_Varadarajan_Flek_Schwartz_Boyd_2025,
title={Unifying the Extremes: Developing a Unified Model for Detecting and Predicting Extremist Traits and Radicalization},
volume={19},
url={https://ojs.aaai.org/index.php/ICWSM/article/view/35860},
DOI={10.1609/icwsm.v19i1.35860},
note={Allison Lahnala and Vasudha Varadarajan contributed equally to this work.},
number={1},
journal={Proceedings of the International AAAI Conference on Web and Social Media},
author={Lahnala, Allison and Varadarajan, Vasudha and Flek, Lucie and Schwartz, H. Andrew and Boyd, Ryan L},
year={2025},
month={Jun.},
pages={1051--1067}
}Please also cite the papers that introduced the scales used in this work.
@article{ozer-2018-capturing,
author = {Ozer, Simon and Bertelsen, Preben},
title = {Capturing violent radicalization: Developing and validating scales measuring central aspects of radicalization},
journal = {Scandinavian Journal of Psychology},
volume = {59},
number = {6},
pages = {653-660},
year = {2018}
}
@article{ho2015nature,
title={The nature of social dominance orientation: Theorizing and measuring preferences for intergroup inequality using the new SDO₇ scale.},
author={Ho, Arnold K and Sidanius, Jim and Kteily, Nour and Sheehy-Skeffington, Jennifer and Pratto, Felicia and Henkel, Kristin E and Foels, Rob and Stewart, Andrew L},
journal={Journal of personality and social psychology},
volume={109},
number={6},
pages={1003},
year={2015},
publisher={American Psychological Association}
}
@article{moskalenko2009measuring,
title={Measuring political mobilization: The distinction between activism and radicalism},
author={Moskalenko, Sophia and McCauley, Clark},
journal={Terrorism and political violence},
volume={21},
number={2},
pages={239--260},
year={2009},
publisher={Taylor \& Francis}
}
@article{obaidi2018living,
title={Living under threat: Mutual threat perception drives anti-Muslim and anti-Western hostility in the age of terrorism},
author={Obaidi, Milan and Kunst, Jonas R and Kteily, Nour and Thomsen, Lotte and Sidanius, James},
journal={European Journal of Social Psychology},
volume={48},
number={5},
pages={567--584},
year={2018},
publisher={Wiley Online Library}
}
@article{obaidi2018living,
title={Living under threat: Mutual threat perception drives anti-Muslim and anti-Western hostility in the age of terrorism},
author={Obaidi, Milan and Kunst, Jonas R and Kteily, Nour and Thomsen, Lotte and Sidanius, James},
journal={European Journal of Social Psychology},
volume={48},
number={5},
pages={567--584},
year={2018},
publisher={Wiley Online Library}
}
@article{weiss2003cross,
title={A cross-national comparison of nationalism in Austria, the Czech and Slovac Republics, Hungary, and Poland},
author={Weiss, Hilde},
journal={Political Psychology},
volume={24},
number={2},
pages={377--401},
year={2003},
publisher={Wiley Online Library}
}
@article{zakrisson2005construction,
title={Construction of a short version of the Right-Wing Authoritarianism (RWA) scale},
author={Zakrisson, Ingrid},
journal={Personality and individual differences},
volume={39},
number={5},
pages={863--872},
year={2005},
publisher={Elsevier}
}
@article{ellemers1999self,
title={Self-categorisation, commitment to the group and group self-esteem as related but distinct aspects of social identity},
author={Ellemers, Naomi and Kortekaas, Paulien and Ouwerkerk, Jaap W},
journal={European journal of social psychology},
volume={29},
number={2-3},
pages={371--389},
year={1999},
publisher={Wiley Online Library}
}
@article{jonason2010dirty,
title={The dirty dozen: a concise measure of the dark triad.},
author={Jonason, Peter K and Webster, Gregory D},
journal={Psychological assessment},
volume={22},
number={2},
pages={420},
year={2010},
publisher={American Psychological Association}
}
@article{jungkunz2024measuring,
title={Measuring political radicalism and extremism in surveys: Three new scales},
author={Jungkunz, Sebastian and Helbling, Marc and Osenbr{\"u}gge, Nina},
journal={Plos one},
volume={19},
number={5},
pages={e0300661},
year={2024}
}