This repository contains the code for the MoralBERT paper accepted at ACM GoodIT 2024 (click here for the paper). The work involves training BERT models to predict moral values from social media text. Baseline models, including a lexicon-based model and a machine learning model, are also provided.
If you want to apply moral automatic annotation in your text without having to write any code, head over to MoralBERTApp.
This folder contains Python Jupyter Notebook files for training MoralBERT and predicting moral values in text. The models are fine-tuned on annotated social media datasets and are designed to understand and predict the representation of moral values based on the Moral Foundations Theory (MFT). The code demonstrates the prediction of 10 moral foundations, each handled individually by a single classification model. You can also include Liberty/Oppression (when the data is available and annotated accordingly) using the same script.
The pre-trained weights of our models are now available on Hugging Face, enabling rapid utilisation of the MoralBERT models to compute moral scores for any text and store the results in a DataFrame. To apply these models, please refer to the MoralBert/Predict_mft_scores_from_the_MoralBERT_weights.ipynb
script. The weights for the liberty/oppression dimension are not yet released, as we are still working on refining this aspect of the model.
This folder hosts Python Jupyter Notebook files for baseline models built with the MoralStrength Lexicon (see the paper and the GitHub page) and a Word2Vec with Random Forest Model using scikit-learn machine learning library.
This folder hosts Python Jupyter Notebook file for utilising GPT-4 zero shot classification model for predicting moral foundations.
To fine-tune the models with the same data, please download the datasets as follows:
- Moral Foundations Twitter Corpus: Download the corpus here
- Moral Foundations Reddit Corpus: Download the corpus here
- Facebook Vaccination Posts: Please contact the authors of this paper: Contact Authors