Views
No views yet
Moralities, emotions, and events are complex aspects of human cognition, which are often treated separately since capturing their combined effects is challenging, especially due to the lack of annotated data. Leveraging their interrelations hence becomes crucial for advancing the understanding of human moral behaviors. In this work, we propose ME²-BERT, the first holistic framework for fine-tuning a pre-trained language model like BERT to the task of moral foundation prediction. ME²-BERT integrates events and emotions for learning domain-invariant morality-relevant text representations. Our extensive experiments show that ME²-BERT outperforms existing state-of-the-art methods for moral foundation prediction, with an average percentage increase up to 35% in the out-of-domain scenario.
1from transformers import AutoTokenizer, AutoModel
2import torch
3
4model_name = "lorenzozan/ME2-BERT"
5tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
6model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
7
8text = ["Faithless is he that says farewell when the road darkens."]
9inputs = tokenizer(text, padding="max_length", truncation=True, return_tensors="pt")
10with torch.no_grad():
11 outputs = model(**inputs, return_dict=False)
12
13print(outputs) # tensor([[0.0185, 0.2401, 0.9166, 0.0498, 0.0453]])return_dict=True, it returns a dictionary containing key-value pairs, where each key represents a moral dimension and its corresponding value indicates the associated score.1
2text = [
3 'Faithless is he that says farewell when the road darkens.',
4 'The soul is healed by being with children.',
5 'I remembered how we had we had all come to Gatsby’s and guessed at his corruption… while he stood before us concealing an incorruptible dream…',
6 'All the variety, all the charm, all the beauty of life is made up of light and shadow, but justice must always remain clear and unbroken.',
7 'When tyranny becomes law, rebellion becomes duty.']
8
9max_seq_length = 200
10
11mf_mapping = {'CH':'CARE/HARM','FC':'FAIRNESS/CHEATING', 'LB':'LOYALTY/BETRAYAL', 'AS':'AUTHORITY/SUBVERSION', 'PD': 'PURITY/DEGRADATION'}
12
13tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
14model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
15
16encoded_input = tokenizer(
17 text,
18 max_length=max_seq_length,
19 padding="max_length",
20 truncation=True,
21 return_tensors="pt",
22)
23
24input_ids = encoded_input["input_ids"]
25attention_mask = encoded_input["attention_mask"]
26
27model.eval()
28with torch.no_grad():
29 output = model(input_ids=input_ids, attention_mask=attention_mask, return_dict=True)
30
31for i, tt in enumerate(text):
32 print(tt)
33 for mf, score in output[i].items():
34 print(f'{mf_mapping[mf]} : {score}')
35 print()Faithless is he that says farewell when the road darkens.
CARE/HARM : 0.05056
FAIRNESS/CHEATING : 0.01845
LOYALTY/BETRAYAL : 0.8676
AUTHORITY/SUBVERSION : 0.01655
PURITY/DEGRADATION : 0.06524
The soul is healed by being with children.
CARE/HARM : 0.83783
FAIRNESS/CHEATING : 0.02016
LOYALTY/BETRAYAL : 0.42663
AUTHORITY/SUBVERSION : 0.00525
PURITY/DEGRADATION : 0.61056
I remembered how we had we had all come to Gatsby’s and guessed at his corruption… while he stood before us concealing an incorruptible dream…
CARE/HARM : 0.00676
FAIRNESS/CHEATING : 0.04518
LOYALTY/BETRAYAL : 0.02287
AUTHORITY/SUBVERSION : 0.00545
PURITY/DEGRADATION : 0.64035
All the variety, all the charm, all the beauty of life is made up of light and shadow, but justice must always remain clear and unbroken.
CARE/HARM : 0.08769
FAIRNESS/CHEATING : 0.95034
LOYALTY/BETRAYAL : 0.05768
AUTHORITY/SUBVERSION : 0.00725
PURITY/DEGRADATION : 0.06396
When tyranny becomes law, rebellion becomes duty.
CARE/HARM : 0.1599
FAIRNESS/CHEATING : 0.91123
LOYALTY/BETRAYAL : 0.4824
AUTHORITY/SUBVERSION : 0.96638
PURITY/DEGRADATION : 0.02086@inproceedings{zangari-etal-2025-me2,
title = "{ME}2-{BERT}: Are Events and Emotions what you need for Moral Foundation Prediction?",
author = "Zangari, Lorenzo and
Greco, Candida M. and
Picca, Davide and
Tagarelli, Andrea",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2025.coling-main.638/",
pages = "9516--9532",
abstract = "Moralities, emotions, and events are complex aspects of human cognition, which are often treated separately since capturing their combined effects is challenging, especially due to the lack of annotated data. Leveraging their interrelations hence becomes crucial for advancing the understanding of human moral behaviors. In this work, we propose ME2-BERT, the first holistic framework for fine-tuning a pre-trained language model like BERT to the task of moral foundation prediction. ME2-BERT integrates events and emotions for learning domain-invariant morality-relevant text representations. Our extensive experiments show that ME2-BERT outperforms existing state-of-the-art methods for moral foundation prediction, with an average increase up to 35{\%} in the out-of-domain scenario."
}