Views
No views yet
1
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3import torch
4
5tokenizer = AutoTokenizer.from_pretrained("tum-nlp/Deberta_Human_Value_Detector")
6trained_model = AutoModelForSequenceClassification.from_pretrained("tum-nlp/Deberta_Human_Value_Detector", trust_remote_code=True)
7
8example_text ='We should ban whaling because whales are a species at the risk of distinction'
9
10encoding = tokenizer.encode_plus(
11 example_text,
12 add_special_tokens=True,
13 max_length=512,
14 return_token_type_ids=False,
15 padding="max_length",
16 return_attention_mask=True,
17 return_tensors='pt',
18 )
19
20with torch.no_grad():
21 test_prediction = trained_model(encoding["input_ids"], encoding["attention_mask"])
22 test_prediction = test_prediction["output"].flatten().numpy()
231THRESHOLD = 0.25
2LABEL_COLUMNS = ['Self-direction: thought','Self-direction: action','Stimulation','Hedonism','Achievement','Power: dominance','Power: resources','Face','Security: personal',
3 'Security: societal','Tradition','Conformity: rules','Conformity: interpersonal','Humility','Benevolence: caring','Benevolence: dependability','Universalism: concern','Universalism: nature','Universalism: tolerance','Universalism: objectivity']
4print(f"Predictions:")
5for label, prediction in zip(LABEL_COLUMNS, test_prediction):
6 if prediction < THRESHOLD:
7 continue
8 print(f"{label}: {prediction}")@inproceedings{schroter-etal-2023-adam,
title = "{A}dam-Smith at {S}em{E}val-2023 Task 4: Discovering Human Values in Arguments with Ensembles of Transformer-based Models",
author = "Schroter, Daniel and
Dementieva, Daryna and
Groh, Georg",
editor = {Ojha, Atul Kr. and
Do{\u{g}}ru{\"o}z, A. Seza and
Da San Martino, Giovanni and
Tayyar Madabushi, Harish and
Kumar, Ritesh and
Sartori, Elisa},
booktitle = "Proceedings of the 17th International Workshop on Semantic Evaluation (SemEval-2023)",
month = jul,
year = "2023",
address = "Toronto, Canada",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.semeval-1.74",
doi = "10.18653/v1/2023.semeval-1.74",
pages = "532--541",
abstract = "This paper presents the best-performing approach alias {``}Adam Smith{''} for the SemEval-2023 Task 4: {``}Identification of Human Values behind Arguments{''}. The goal of the task was to create systems that automatically identify the values within textual arguments. We train transformer-based models until they reach their loss minimum or f1-score maximum. Ensembling the models by selecting one global decision threshold that maximizes the f1-score leads to the best-performing system in the competition. Ensembling based on stacking with logistic regressions shows the best performance on an additional dataset provided to evaluate the robustness ({``}Nahj al-Balagha{''}). Apart from outlining the submitted system, we demonstrate that the use of the large ensemble model is not necessary and that the system size can be significantly reduced.",
}