Files changed (1) hide show
  1. README.md +242 -113
README.md CHANGED
@@ -1,206 +1,335 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- This model takes the various social groups that might be mentioned in political speech, and assigns them to different meaningful groups. It allows the same text string to belong to multiple social groups, for example "girls" are mapped to both "women" and "children"
9
-
10
- See Dolinsky et al (2025) for more information on social group categories and Horne et al (2025) for details on training, relation to other models, and use cases.
11
-
12
- 📊 Evaluation Results: {'eval_loss': 0.023458, 'eval_accuracy': 0.994933, 'eval_f1': 0.894393, 'eval_precision': 0.0.897170, 'eval_recall': 0.891632, 'eval_runtime': 5.9184, 'eval_samples_per_second': 232.831, 'eval_steps_per_second': 29.231, 'epoch': 29.914368650217707}
13
-
14
-
15
- LEARNING_RATE = 1.9432557585419205e-05
16
- WEIGHT_DECAY = 0.11740203810285466
17
- WARMUP_RATIO = 0.018423412349675528
18
 
19
  ## Model Details
20
 
21
  ### Model Description
22
 
23
- <!-- Provide a longer summary of what this model is. -->
24
-
25
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
26
 
27
- - **Developed by:** [More Information Needed]
28
- - **Funded by [optional]:** [More Information Needed]
29
- - **Shared by [optional]:** [More Information Needed]
30
- - **Model type:** [More Information Needed]
31
- - **Language(s) (NLP):** [More Information Needed]
32
- - **License:** [More Information Needed]
33
- - **Finetuned from model [optional]:** [More Information Needed]
34
 
35
- ### Model Sources [optional]
36
 
37
- <!-- Provide the basic links for the model. -->
38
-
39
- - **Repository:** [More Information Needed]
40
- - **Paper [optional]:** [More Information Needed]
41
- - **Demo [optional]:** [More Information Needed]
42
 
43
  ## Uses
44
 
45
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
46
-
47
  ### Direct Use
48
 
49
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
50
-
51
- [More Information Needed]
52
 
53
- ### Downstream Use [optional]
 
 
 
 
 
 
 
 
 
54
 
55
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
56
 
57
- [More Information Needed]
 
 
 
 
58
 
59
  ### Out-of-Scope Use
60
 
61
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
62
-
63
- [More Information Needed]
 
 
 
 
64
 
65
  ## Bias, Risks, and Limitations
66
 
67
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
 
 
68
 
69
- [More Information Needed]
 
 
70
 
71
  ### Recommendations
72
 
73
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
74
-
75
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
76
 
77
  ## How to Get Started with the Model
78
 
79
- Use the code below to get started with the model.
80
 
81
- [More Information Needed]
 
82
 
83
- ## Training Details
 
 
 
84
 
85
- ### Training Data
 
 
 
 
 
 
 
86
 
87
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
88
 
89
- [More Information Needed]
 
90
 
91
- ### Training Procedure
 
 
 
 
92
 
93
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
94
 
95
- #### Preprocessing [optional]
 
 
96
 
97
- [More Information Needed]
 
 
 
98
 
 
 
99
 
100
- #### Training Hyperparameters
 
 
101
 
102
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
103
 
104
- #### Speeds, Sizes, Times [optional]
 
105
 
106
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
 
107
 
108
- [More Information Needed]
109
 
110
- ## Evaluation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- <!-- This section describes the evaluation protocols and provides the results. -->
113
 
114
  ### Testing Data, Factors & Metrics
115
 
116
  #### Testing Data
 
 
117
 
118
- <!-- This should link to a Dataset Card if possible. -->
 
 
 
 
119
 
120
- [More Information Needed]
 
 
 
 
 
121
 
122
- #### Factors
123
 
124
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
 
 
125
 
126
- [More Information Needed]
127
 
128
- #### Metrics
129
 
130
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
 
 
 
131
 
132
- [More Information Needed]
 
 
 
133
 
134
- ### Results
 
 
 
135
 
136
- [More Information Needed]
 
 
 
137
 
138
- #### Summary
 
 
 
139
 
 
 
 
 
140
 
 
 
 
 
141
 
142
- ## Model Examination [optional]
 
 
 
143
 
144
- <!-- Relevant interpretability work for the model goes here -->
145
 
146
- [More Information Needed]
 
 
 
 
147
 
148
  ## Environmental Impact
149
 
150
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
151
-
152
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
153
 
154
- - **Hardware Type:** [More Information Needed]
155
- - **Hours used:** [More Information Needed]
156
- - **Cloud Provider:** [More Information Needed]
157
- - **Compute Region:** [More Information Needed]
158
- - **Carbon Emitted:** [More Information Needed]
 
159
 
160
- ## Technical Specifications [optional]
161
 
162
  ### Model Architecture and Objective
163
-
164
- [More Information Needed]
 
 
 
 
 
165
 
166
  ### Compute Infrastructure
167
 
168
- [More Information Needed]
169
-
170
  #### Hardware
171
-
172
- [More Information Needed]
173
 
174
  #### Software
 
 
 
 
175
 
176
- [More Information Needed]
177
-
178
- ## Citation [optional]
179
 
180
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
181
 
182
  **BibTeX:**
 
 
 
 
 
 
 
 
183
 
184
- [More Information Needed]
185
-
186
- **APA:**
187
-
188
- [More Information Needed]
189
-
190
- ## Glossary [optional]
191
-
192
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
193
-
194
- [More Information Needed]
195
-
196
- ## More Information [optional]
197
-
198
- [More Information Needed]
199
-
200
- ## Model Card Authors [optional]
201
 
202
- [More Information Needed]
203
 
204
  ## Model Card Contact
205
 
206
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ tags:
4
+ - group-detection
5
+ - political-science
6
+ - multilingual
7
+ - multilabel-classification
8
+ - deberta
9
+ - group-appeals
10
+ language:
11
+ - en
12
+ - de
13
+ - nl
14
+ - da
15
+ - fr
16
+ - es
17
+ - it
18
+ - sv
19
+ base_model: microsoft/mdeberta-v3-base
20
  ---
21
 
22
+ # Model Card for mDeBERTa Group Detection
23
 
24
+ A multilingual group classification model fine-tuned for classifying social group tokens into meaningful social groups categories in political text.
 
 
 
 
 
 
 
 
 
25
 
26
  ## Model Details
27
 
28
  ### Model Description
29
 
30
+ This model is a fine-tuned mDeBERTa-v3-base that performs multilabel classification to classify social group tokens mentioned in political text into meaningful social groups categories. The model can classify a token into multiple group categories simultaneously to support intersectionality, and was trained on political manifesto data.
 
 
31
 
32
+ - **Developed by:** Will Horne, Alona O. Dolinsky and Lena Maria Huber
33
+ - **Model type:** Multilabel Sequence Classification
34
+ - **Language(s) (NLP):** English, German (multilingual)
35
+ - **Finetuned from model:** microsoft/mdeberta-v3-base
 
 
 
36
 
37
+ ### Model Sources
38
 
39
+ - **Repository:** rwillh11/mdeberta_groups_2.0
40
+ - **Base Model:** [microsoft/mdeberta-v3-base](https://huggingface.co/microsoft/mdeberta-v3-base)
 
 
 
41
 
42
  ## Uses
43
 
 
 
44
  ### Direct Use
45
 
46
+ The model is designed for researchers analyzing political discourse to automatically classify **social group tokens or phrases** into meaningful social group categories. It takes individual group mentions (e.g., "workers", "students", "citizens") as input and outputs predictions for 44 different group categories:
 
 
47
 
48
+ - Adults, Caregivers, Children, Citizens, Civil servants, Consumers
49
+ - Crime victims, Criminals, Education professionals, Elderly people
50
+ - Employees and workers, Employers and business owners, Ethnic and national communities
51
+ - Families, Farmers, Health professionals, Homeless people, Homeowners and landowners
52
+ - Investors and stakeholders, Landlords, Law enforcement personnel, LGBTQI
53
+ - Lower class, Manual and service workers, Men, Middle class, Migrants and refugees
54
+ - Military personnel, Patients, People with disabilities, Politicians, Religious communities
55
+ - Road users, Rural communities, Sociocultural professionals, Students, Taxpayers
56
+ - Tenants, Unemployed, Upper class, White collar workers, Women, Young people
57
+ - and a residual category of "Other"
58
 
59
+ ### Downstream Use
60
 
61
+ This model can be integrated into larger political text analysis pipelines for:
62
+ - **Step 2 of group analysis**: After extracting group mentions from text, classify them into meaningful categories
63
+ - Political manifestos analysis and group categorization
64
+ - Comparative political research across countries and languages
65
+ - Social group representation studies with consistent categorization
66
 
67
  ### Out-of-Scope Use
68
 
69
+ This model should not be used for:
70
+ - **Detecting group mentions within full text** (this model classifies pre-identified group tokens)
71
+ - General entity recognition or named entity recognition tasks
72
+ - Processing full sentences or paragraphs directly
73
+ - Real-time social media monitoring without human oversight
74
+ - Making decisions about individuals or groups
75
+ - Content moderation without additional validation
76
 
77
  ## Bias, Risks, and Limitations
78
 
79
+ ### Technical Limitations
80
+ - Trained specifically on political manifesto text; performance may vary on other text types
81
+ - Limited to 44 predefined group categories
82
+ - Multilabel predictions may have dependencies between group categories
83
 
84
+ ### Bias Considerations
85
+ - Training data consists of political manifestos from specific countries and time periods
86
+ - May reflect biases present in political discourse of training data
87
 
88
  ### Recommendations
89
 
90
+ Users should be aware that this model:
91
+ - Is designed for research purposes in political science
92
+ - Should be validated on specific domains before deployment
93
+ - May require human oversight for sensitive applications
94
+ - Performance may vary across different types of groups and political contexts
95
 
96
  ## How to Get Started with the Model
97
 
98
+ ### Recommended Usage (Pipeline)
99
 
100
+ ```python
101
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
102
 
103
+ # Load model and tokenizer
104
+ model_repo = "rwillh11/mdeberta_groups_2.0"
105
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/mdeberta-v3-base")
106
+ model = AutoModelForSequenceClassification.from_pretrained(model_repo)
107
 
108
+ # Create pipeline for multilabel classification
109
+ classifier = pipeline(
110
+ "text-classification",
111
+ model=model,
112
+ tokenizer=tokenizer,
113
+ return_all_scores=True,
114
+ device=0 # Use GPU if available
115
+ )
116
 
117
+ # Example usage - classify group tokens/phrases
118
+ group_tokens = ["students", "workers", "teachers", "citizens", "elderly people"]
119
 
120
+ # Get predictions
121
+ predictions = classifier(group_tokens)
122
 
123
+ # Process results with 0.5 threshold
124
+ for token, prediction in zip(group_tokens, predictions):
125
+ predicted_labels = [label_score['label'] for label_score in prediction if label_score['score'] > 0.5]
126
+ print(f"'{token}' → {predicted_labels}")
127
+ ```
128
 
129
+ ### Manual Implementation
130
 
131
+ ```python
132
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
133
+ import torch
134
 
135
+ # Load model and tokenizer
136
+ model_name = "rwillh11/mdeberta_groups_2.0"
137
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/mdeberta-v3-base")
138
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
139
 
140
+ # Example group tokens
141
+ group_tokens = ["workers", "citizens", "students"]
142
 
143
+ for token in group_tokens:
144
+ # Tokenize
145
+ inputs = tokenizer(token, return_tensors="pt", truncation=True, max_length=128)
146
 
147
+ # Get predictions
148
+ with torch.no_grad():
149
+ outputs = model(**inputs)
150
+ predictions = torch.sigmoid(outputs.logits)
151
 
152
+ # Apply threshold (0.5) to get binary predictions
153
+ binary_predictions = (predictions > 0.5).cpu().numpy()
154
 
155
+ # Get predicted label indices
156
+ predicted_indices = [i for i, pred in enumerate(binary_predictions[0]) if pred]
157
+ print(f"'{token}' predicted categories: {predicted_indices}")
158
+ ```
159
 
160
+ ## Training Details
161
 
162
+ ### Training Data
163
+
164
+ The model was trained on political manifesto data containing:
165
+ - **Languages:** English and German
166
+ - **Text Type:** Political manifesto sentences and group mentions
167
+ - **Labels:** Multiple social group categories (multilabel classification)
168
+ - **Source:** `final_group_train.csv`
169
+ - **Training Size:** 2,454 examples (80% split)
170
+ - **Validation Size:** 614 examples (20% split)
171
+ - **Data processing:** MultiLabelBinarizer for one-hot encoding of group labels
172
+
173
+ ### Training Procedure
174
+
175
+ #### Preprocessing
176
+ - Texts tokenized using mDeBERTa tokenizer with max length 128
177
+ - Multilabel binarization using scikit-learn's MultiLabelBinarizer
178
+ - Each text can have multiple group labels simultaneously
179
+
180
+ #### Training Hyperparameters (Optimal from Optuna)
181
+ - **Training regime:** Mixed precision training with gradient accumulation
182
+ - **Optimizer:** AdamW
183
+ - **Learning rate:** 1.9432557585419205e-05 (optimized via Optuna)
184
+ - **Weight decay:** 0.11740203810285466 (optimized via Optuna)
185
+ - **Warmup ratio:** 0.018423412349675528 (optimized via Optuna)
186
+ - **Epochs:** 30
187
+ - **Batch size:** 8 (train and eval)
188
+ - **Gradient accumulation steps:** 2
189
+ - **Trials:** 7 Optuna trials for hyperparameter optimization
190
+ - **Metric for selection:** F1 Score
191
+ - **Seed:** 42 (partial deterministic training - only Transformers seed set)
192
+ - **Pruning:** MedianPruner with 5 warmup steps
193
+
194
+ #### Training Infrastructure
195
+ - **Hardware:** CUDA-enabled GPU (Google Colab)
196
+ - **Framework:** Transformers, PyTorch
197
+ - **Hyperparameter optimization:** Optuna with MedianPruner
198
+ - **Early stopping:** MedianPruner with 5 warmup steps
199
 
200
+ ## Evaluation
201
 
202
  ### Testing Data, Factors & Metrics
203
 
204
  #### Testing Data
205
+ - 20% holdout from original dataset
206
+ - Multilingual political manifesto sentences with group annotations
207
 
208
+ #### Factors
209
+ The model was evaluated across:
210
+ - **Languages:** English and German text
211
+ - **Group categories:** 44 different social group types
212
+ - **Multilabel performance:** Ability to predict multiple groups per text
213
 
214
+ #### Metrics
215
+ Primary metrics used for evaluation:
216
+ - **F1 Score:** Primary optimization metric for multilabel classification
217
+ - **Accuracy:** Overall prediction accuracy
218
+ - **Precision:** Precision across all labels
219
+ - **Recall:** Recall across all labels
220
 
221
+ ### Results
222
 
223
+ **Best Model Performance (Trial 4, Epoch 27):**
224
+ - **Accuracy:** 0.9942
225
+ - **F1 Score:** 0.8537
226
+ - **Precision:** 0.8633
227
+ - **Recall:** 0.8443
228
 
229
+ The model demonstrates strong performance in multilabel group detection with consistent results across hyperparameter trials and excellent convergence during training.
230
 
231
+ Additional validation on held-out sets return the following micro-averaged metrics excluding the residual category "other":
232
 
233
+ **English**
234
+ - **Precision:** 0.894
235
+ - **Recall:** 0.868
236
+ - **F1 Micro:** 0.881
237
 
238
+ **German (using texts translated from English)**
239
+ - **Precision:** 0.853
240
+ - **Recall:** 0.823
241
+ - **F1 Micro:** 0.838
242
 
243
+ **Dutch (using texts translated from English)**
244
+ - **Precision:** 0.833
245
+ - **Recall:** 0.789
246
+ - **F1 Micro:** 0.817
247
 
248
+ **Danish (using texts translated from English)**
249
+ - **Precision:** 0.845
250
+ - **Recall:** 0.789
251
+ - **F1 Micro:** 0.816
252
 
253
+ **Spanish (using texts translated from English)**
254
+ - **Precision:** 0.838
255
+ - **Recall:** 0.792
256
+ - **F1 Micro:** 0.815
257
 
258
+ **French (using texts translated from English)**
259
+ - **Precision:** 0.841
260
+ - **Recall:** 0.802
261
+ - **F1 Micro:** 0.821
262
 
263
+ **Italian (using texts translated from English)**
264
+ - **Precision:** 0.837
265
+ - **Recall:** 0.788
266
+ - **F1 Micro:** 0.811
267
 
268
+ **Swedish (using texts translated from English)**
269
+ - **Precision:** 0.837
270
+ - **Recall:** 0.774
271
+ - **F1 Micro:** 0.804
272
 
273
+ ## Model Examination
274
 
275
+ The model uses a standard multilabel classification approach:
276
+ - Sigmoid activation for independent probability prediction per group
277
+ - Binary cross-entropy loss for multilabel training
278
+ - Threshold of 0.5 for binary predictions
279
+ - Supports detection of multiple groups simultaneously in a single text
280
 
281
  ## Environmental Impact
282
 
283
+ Training involved hyperparameter optimization with 7 trials, each training for 30 epochs.
 
 
284
 
285
+ - **Hardware Type:** CUDA-enabled GPU (Google Colab)
286
+ - **Hours used:** Approximately 37-38 hours per trial (6 complete trials ≈ 4.5 hours each, ~27 total hours)
287
+ - **Cloud Provider:** Google Colab
288
+ - **Compute Region:** Variable
289
+ - **Carbon Emitted:** Not precisely measured
290
+ - **Training Date:** February 24, 2025
291
 
292
+ ## Technical Specifications
293
 
294
  ### Model Architecture and Objective
295
+ - **Base Architecture:** mDeBERTa-v3-base (278M parameters)
296
+ - **Task:** Multilabel sequence classification for group detection
297
+ - **Input:** Political text (max length 128 tokens)
298
+ - **Output:** Multi-dimensional binary vector for group presence
299
+ - **Objective:** Binary cross-entropy loss with F1 score optimization
300
+ - **Activation:** Sigmoid for independent probability prediction per group
301
+ - **Threshold:** 0.5 for binary predictions
302
 
303
  ### Compute Infrastructure
304
 
 
 
305
  #### Hardware
306
+ - GPU-accelerated training (CUDA)
307
+ - Mixed precision training support
308
 
309
  #### Software
310
+ - Transformers library
311
+ - PyTorch framework
312
+ - Optuna for hyperparameter optimization
313
+ - scikit-learn for metrics and multilabel encoding
314
 
315
+ ## Citation
 
 
316
 
317
+ If you use this model in your research, please cite:
318
 
319
  **BibTeX:**
320
+ ```bibtex
321
+ @misc{mdeberta_groups_detection,
322
+ title={mDeBERTa Group Detection Model for Political Text Analysis},
323
+ author={Will Horne and Alona O. Dolinsky and Lena Maria Huber},
324
+ year={2024},
325
+ note={Multilingual model for detecting social groups in political discourse}
326
+ }
327
+ ```
328
 
329
+ ## Model Card Authors
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
331
+ Research team studying group appeals in political discourse.
332
 
333
  ## Model Card Contact
334
 
335
+ For questions about this model, please contact the research team through appropriate academic channels.