synapti commited on
Commit
1b8e0dd
·
verified ·
1 Parent(s): eea7948

Update model card with metrics and usage examples

Browse files
Files changed (1) hide show
  1. README.md +160 -85
README.md CHANGED
@@ -1,90 +1,165 @@
1
  ---
 
 
 
2
  library_name: transformers
3
- license: apache-2.0
4
- base_model: answerdotai/ModernBERT-base
5
  tags:
6
- - generated_from_trainer
7
- model-index:
8
- - name: nci-technique-classifier-v2
9
- results: []
 
 
 
 
 
 
 
 
10
  ---
11
 
12
- <!-- This model card has been generated automatically according to the information the Trainer had access to. You
13
- should probably proofread and complete it, then remove this comment. -->
14
-
15
- # nci-technique-classifier-v2
16
-
17
- This model is a fine-tuned version of [answerdotai/ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) on an unknown dataset.
18
- It achieves the following results on the evaluation set:
19
- - Loss: 0.0233
20
- - Micro F1: 0.8017
21
- - Macro F1: 0.6272
22
- - Micro Precision: 0.8311
23
- - Micro Recall: 0.7743
24
-
25
- ## Model description
26
-
27
- More information needed
28
-
29
- ## Intended uses & limitations
30
-
31
- More information needed
32
-
33
- ## Training and evaluation data
34
-
35
- More information needed
36
-
37
- ## Training procedure
38
-
39
- ### Training hyperparameters
40
-
41
- The following hyperparameters were used during training:
42
- - learning_rate: 2e-05
43
- - train_batch_size: 16
44
- - eval_batch_size: 32
45
- - seed: 42
46
- - optimizer: Use OptimizerNames.ADAMW_TORCH_FUSED with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
47
- - lr_scheduler_type: linear
48
- - lr_scheduler_warmup_ratio: 0.1
49
- - num_epochs: 5
50
- - mixed_precision_training: Native AMP
51
-
52
- ### Training results
53
-
54
- | Training Loss | Epoch | Step | Validation Loss | Micro F1 | Macro F1 | Micro Precision | Micro Recall |
55
- |:-------------:|:------:|:----:|:---------------:|:--------:|:--------:|:---------------:|:------------:|
56
- | No log | 0.1634 | 200 | 0.0350 | 0.6311 | 0.1526 | 0.7644 | 0.5373 |
57
- | No log | 0.3268 | 400 | 0.0305 | 0.6658 | 0.1814 | 0.8020 | 0.5692 |
58
- | 0.0552 | 0.4902 | 600 | 0.0282 | 0.7023 | 0.2044 | 0.8244 | 0.6117 |
59
- | 0.0552 | 0.6536 | 800 | 0.0263 | 0.7268 | 0.2181 | 0.8509 | 0.6343 |
60
- | 0.0273 | 0.8170 | 1000 | 0.0256 | 0.7497 | 0.2610 | 0.8305 | 0.6832 |
61
- | 0.0273 | 0.9804 | 1200 | 0.0249 | 0.7462 | 0.2371 | 0.8740 | 0.6510 |
62
- | 0.0273 | 1.1438 | 1400 | 0.0245 | 0.7626 | 0.2862 | 0.8450 | 0.6949 |
63
- | 0.0231 | 1.3072 | 1600 | 0.0242 | 0.7583 | 0.2371 | 0.8582 | 0.6793 |
64
- | 0.0231 | 1.4706 | 1800 | 0.0238 | 0.7650 | 0.3155 | 0.8457 | 0.6984 |
65
- | 0.0226 | 1.6340 | 2000 | 0.0238 | 0.7624 | 0.3074 | 0.8542 | 0.6885 |
66
- | 0.0226 | 1.7974 | 2200 | 0.0230 | 0.7626 | 0.3634 | 0.8681 | 0.68 |
67
- | 0.0226 | 1.9608 | 2400 | 0.0223 | 0.7747 | 0.4246 | 0.8675 | 0.6998 |
68
- | 0.0214 | 2.1242 | 2600 | 0.0225 | 0.7731 | 0.4412 | 0.8752 | 0.6924 |
69
- | 0.0214 | 2.2876 | 2800 | 0.0221 | 0.7775 | 0.4101 | 0.8733 | 0.7005 |
70
- | 0.0189 | 2.4510 | 3000 | 0.0219 | 0.7819 | 0.4757 | 0.8414 | 0.7303 |
71
- | 0.0189 | 2.6144 | 3200 | 0.0224 | 0.7796 | 0.4224 | 0.8606 | 0.7126 |
72
- | 0.0189 | 2.7778 | 3400 | 0.0217 | 0.7922 | 0.5512 | 0.8389 | 0.7504 |
73
- | 0.0187 | 2.9412 | 3600 | 0.0217 | 0.7813 | 0.4680 | 0.8610 | 0.7150 |
74
- | 0.0187 | 3.1046 | 3800 | 0.0224 | 0.7912 | 0.5458 | 0.8341 | 0.7526 |
75
- | 0.0155 | 3.2680 | 4000 | 0.0231 | 0.7922 | 0.5455 | 0.8475 | 0.7437 |
76
- | 0.0155 | 3.4314 | 4200 | 0.0231 | 0.7996 | 0.5843 | 0.8295 | 0.7717 |
77
- | 0.0155 | 3.5948 | 4400 | 0.0223 | 0.8004 | 0.5706 | 0.8398 | 0.7646 |
78
- | 0.0148 | 3.7582 | 4600 | 0.0228 | 0.8096 | 0.6067 | 0.8527 | 0.7706 |
79
- | 0.0148 | 3.9216 | 4800 | 0.0229 | 0.8135 | 0.6228 | 0.8457 | 0.7837 |
80
- | 0.0126 | 4.0850 | 5000 | 0.0255 | 0.8095 | 0.6251 | 0.8379 | 0.7830 |
81
- | 0.0126 | 4.2484 | 5200 | 0.0267 | 0.8061 | 0.6223 | 0.8325 | 0.7812 |
82
- | 0.0126 | 4.4118 | 5400 | 0.0261 | 0.8081 | 0.6338 | 0.8372 | 0.7809 |
83
-
84
-
85
- ### Framework versions
86
-
87
- - Transformers 4.57.3
88
- - Pytorch 2.9.1+cu128
89
- - Datasets 4.4.1
90
- - Tokenizers 0.22.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ license: mit
5
  library_name: transformers
 
 
6
  tags:
7
+ - propaganda-detection
8
+ - multi-label-classification
9
+ - modernbert
10
+ - nci-protocol
11
+ base_model: answerdotai/ModernBERT-base
12
+ datasets:
13
+ - synapti/nci-propaganda-production
14
+ metrics:
15
+ - f1
16
+ - precision
17
+ - recall
18
+ pipeline_tag: text-classification
19
  ---
20
 
21
+ # NCI Technique Classifier v2
22
+
23
+ Multi-label propaganda technique classifier for the NCI (News Content Intelligence) Protocol.
24
+
25
+ ## Model Description
26
+
27
+ This model classifies text into 18 propaganda techniques as part of a two-stage pipeline:
28
+ - **Stage 1**: Binary detection (`synapti/nci-binary-detector-v2`) determines if propaganda exists
29
+ - **Stage 2**: This model identifies which specific techniques are used
30
+
31
+ ### Techniques Detected
32
+
33
+ | ID | Technique | Description |
34
+ |----|-----------|-------------|
35
+ | 0 | Loaded_Language | Using words with strong emotional implications |
36
+ | 1 | Appeal_to_fear-prejudice | Seeking to build support by instilling fear |
37
+ | 2 | Exaggeration,Minimisation | Overstating or understating aspects of issues |
38
+ | 3 | Repetition | Repeating the same message multiple times |
39
+ | 4 | Flag-Waving | Appeals to patriotism or group identity |
40
+ | 5 | Name_Calling,Labeling | Giving a subject a name with negative connotations |
41
+ | 6 | Reductio_ad_hitlerum | Comparing to Hitler or Nazis to discredit |
42
+ | 7 | Black-and-White_Fallacy | Presenting only two options when more exist |
43
+ | 8 | Causal_Oversimplification | Assuming a single cause for complex issues |
44
+ | 9 | Whataboutism,Straw_Men,Red_Herring | Deflection and misrepresentation tactics |
45
+ | 10 | Straw_Man | Misrepresenting someone's argument |
46
+ | 11 | Red_Herring | Introducing irrelevant information |
47
+ | 12 | Doubt | Questioning credibility of sources |
48
+ | 13 | Appeal_to_Authority | Citing authorities to support claims |
49
+ | 14 | Thought-terminating_Cliches | Using clichés to end discussion |
50
+ | 15 | Bandwagon | Appeal to popularity |
51
+ | 16 | Slogans | Brief, striking phrases |
52
+ | 17 | Obfuscation,Intentional_Vagueness,Confusion | Being deliberately unclear |
53
+
54
+ ## Training
55
+
56
+ - **Base Model**: `answerdotai/ModernBERT-base`
57
+ - **Dataset**: `synapti/nci-propaganda-production` (19,581 train, 1,727 val, 1,729 test)
58
+ - **Loss**: Focal Loss (gamma=2.0) with class weights for imbalanced techniques
59
+ - **Epochs**: 5
60
+ - **Batch Size**: 16
61
+ - **Learning Rate**: 2e-5
62
+ - **Hardware**: NVIDIA A10G GPU
63
+
64
+ ## Performance
65
+
66
+ | Metric | Score |
67
+ |--------|-------|
68
+ | Micro F1 | 80.2% |
69
+ | Macro F1 | 63.9% |
70
+ | Micro Precision | 83.4% |
71
+ | Micro Recall | 77.4% |
72
+
73
+ ### Per-Technique Performance (selected)
74
+
75
+ | Technique | F1 Score |
76
+ |-----------|----------|
77
+ | Loaded_Language | 97.0% |
78
+ | Appeal_to_fear-prejudice | 89.7% |
79
+ | Name_Calling,Labeling | 84.3% |
80
+ | Flag-Waving | 82.1% |
81
+
82
+ ## Usage
83
+
84
+ ### With Transformers
85
+
86
+ ```python
87
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
88
+ import torch
89
+
90
+ model = AutoModelForSequenceClassification.from_pretrained("synapti/nci-technique-classifier-v2")
91
+ tokenizer = AutoTokenizer.from_pretrained("synapti/nci-technique-classifier-v2")
92
+
93
+ text = "The radical left is DESTROYING our great nation!"
94
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
95
+
96
+ with torch.no_grad():
97
+ outputs = model(**inputs)
98
+ probs = torch.sigmoid(outputs.logits)[0]
99
+
100
+ # Get techniques above threshold
101
+ threshold = 0.5
102
+ techniques = list(model.config.id2label.values())
103
+ detected = [(techniques[i], probs[i].item()) for i in range(len(techniques)) if probs[i] > threshold]
104
+ print(detected)
105
+ ```
106
+
107
+ ### With NCI Protocol
108
+
109
+ ```python
110
+ from nci.transformers.two_stage_pipeline import TwoStagePipeline
111
+
112
+ pipeline = TwoStagePipeline.from_pretrained(
113
+ binary_model="synapti/nci-binary-detector-v2",
114
+ technique_model="synapti/nci-technique-classifier-v2",
115
+ )
116
+
117
+ result = pipeline.analyze("The radical left is DESTROYING our great nation!")
118
+ print(f"Has propaganda: {result.has_propaganda}")
119
+ print(f"Techniques: {[t.name for t in result.techniques if t.above_threshold]}")
120
+ ```
121
+
122
+ ### ONNX Inference
123
+
124
+ ONNX model available in `onnx/model.onnx` for faster inference (~1.25x speedup).
125
+
126
+ ```python
127
+ import onnxruntime as ort
128
+ import numpy as np
129
+ from transformers import AutoTokenizer
130
+
131
+ tokenizer = AutoTokenizer.from_pretrained("synapti/nci-technique-classifier-v2")
132
+ session = ort.InferenceSession("onnx/model.onnx")
133
+
134
+ text = "WAKE UP AMERICA!"
135
+ inputs = tokenizer(text, return_tensors="np", truncation=True, max_length=512)
136
+
137
+ outputs = session.run(None, {
138
+ "input_ids": inputs["input_ids"],
139
+ "attention_mask": inputs["attention_mask"]
140
+ })
141
+ probs = 1 / (1 + np.exp(-outputs[0])) # sigmoid
142
+ ```
143
+
144
+ ## Limitations
145
+
146
+ - Trained primarily on English news articles
147
+ - May not generalize well to social media or other domains
148
+ - Threshold of 0.5 may need adjustment for specific use cases
149
+ - Multi-label classification means multiple techniques can be detected per text
150
+
151
+ ## Citation
152
+
153
+ ```bibtex
154
+ @misc{nci-technique-classifier-v2,
155
+ author = {Synapti},
156
+ title = {NCI Technique Classifier v2},
157
+ year = {2024},
158
+ publisher = {Hugging Face},
159
+ url = {https://huggingface.co/synapti/nci-technique-classifier-v2}
160
+ }
161
+ ```
162
+
163
+ ## License
164
+
165
+ MIT License