Update model card with metrics and usage examples
Browse files
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 |
-
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
| 58 |
-
|
| 59 |
-
|
|
| 60 |
-
|
|
| 61 |
-
|
|
| 62 |
-
|
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
| 67 |
-
|
| 68 |
-
|
|
| 69 |
-
|
|
| 70 |
-
|
|
| 71 |
-
|
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|