oliviermills commited on
Commit
43541b8
·
verified ·
1 Parent(s): 202c922

Training complete - F1: 0.8530

Browse files
Files changed (4) hide show
  1. README.md +149 -232
  2. config_setfit.json +2 -2
  3. model.safetensors +1 -1
  4. model_head.pkl +1 -1
README.md CHANGED
@@ -1,268 +1,185 @@
1
  ---
 
2
  license: cc-by-nc-4.0
3
- library_name: setfit
4
  tags:
5
  - setfit
6
  - sentence-transformers
7
  - text-classification
8
- - multi-label
9
- - water-conflict
 
 
 
 
 
 
 
 
10
  metrics:
11
- - f1
12
  - accuracy
13
- language:
14
- - en
15
- widget:
16
- - text: "Military attack workers at the Kajaki Dam in Afghanistan"
17
- - text: "Violent protests erupt over dam construction in Sudan"
18
- - text: "New water treatment plant opens in California"
19
- - text: "Armed groups cut off water supply to villages in Syria"
20
- - text: "Government announces new irrigation subsidies"
21
  ---
22
 
23
- # Water Conflict Multi-Label Classifier
24
 
25
- ## 🔬 Experimental Research
26
 
27
- > This experimental research draws on Pacific Institute's [Water Conflict Chronology](https://www.worldwater.org/water-conflict/), which tracks water-related conflicts spanning over 4,500 years of human history. The work is conducted independently and is not affiliated with Pacific Institute.
28
 
29
- This model is designed to assist researchers in classifying water-related conflict events at scale using tiny/small models that can classify 100s of headlines per second.
 
30
 
31
- The Pacific Institute maintains the world's most comprehensive open-source record of water-related conflicts, documenting over 2,700 events across 4,500 years of history. This is not a commercial product and is not intended for commercial use.
32
 
33
- ## 📋 Model Description
 
 
 
 
 
 
 
 
34
 
35
- This SetFit-based model classifies news headlines about water-related conflicts into three categories:
36
 
37
- - **Trigger**: Water resource as a conflict trigger
38
- - **Casualty**: Water infrastructure as a casualty/target
39
- - **Weapon**: Water used as a weapon/tool
40
 
41
- These categories align with the Pacific Institute's Water Conflict Chronology framework for understanding how water intersects with security and conflict.
42
 
43
- ## 🏗️ Model Details
44
 
45
- - **Base Model**: [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5)
46
- - **Architecture**: SetFit with One-vs-Rest multi-label strategy
47
- - **Training Approach**: Few-shot learning optimized (SetFit reaches peak performance with small samples)
48
- - **Training samples**: 1200 examples
49
- - **Test samples**: 519 (held-out, never seen during training)
50
- - **Training time**: ~2-5 minutes on A10G GPU
51
- - **Model size**: 33M Parameters, ~133MB
52
- - **Inference speed**: ~5-10ms per headline on CPU
53
 
54
- ## 💻 Usage
 
 
55
 
56
- ### Quick Start
57
 
58
  ```python
59
  from setfit import SetFitModel
60
 
61
- # Load the trained model from HF Hub
62
  model = SetFitModel.from_pretrained("baobabtech/water-conflict-classifier")
63
-
64
- # Predict on headlines
65
- headlines = [
66
- "Military attack workers at the Kajaki Dam in Afghanistan",
67
- "New water treatment plant opens in California"
68
- ]
69
-
70
- predictions = model.predict(headlines)
71
- print(predictions)
72
- # Output: [[1, 1, 0], [0, 0, 0]]
73
- # Format: [Trigger, Casualty, Weapon]
74
- ```
75
-
76
- ### Interpreting Results
77
-
78
- The model returns a list of binary predictions for each label:
79
-
80
- ```python
81
- label_names = ['Trigger', 'Casualty', 'Weapon']
82
-
83
- for headline, pred in zip(headlines, predictions):
84
- labels = [label_names[i] for i, val in enumerate(pred) if val == 1]
85
- print(f"Headline: {headline}")
86
- print(f"Labels: {', '.join(labels) if labels else 'None'}")
87
- print()
88
  ```
89
 
90
- ### Batch Processing
91
-
92
- ```python
93
- import pandas as pd
94
-
95
- # Load your data
96
- df = pd.read_csv("your_headlines.csv")
97
-
98
- # Predict in batches
99
- predictions = model.predict(df['headline'].tolist())
100
-
101
- # Add predictions to dataframe
102
- df['trigger'] = [p[0] for p in predictions]
103
- df['casualty'] = [p[1] for p in predictions]
104
- df['weapon'] = [p[2] for p in predictions]
105
- ```
106
-
107
- ### Example Outputs
108
-
109
- | Headline | Trigger | Casualty | Weapon |
110
- |----------|---------|----------|--------|
111
- | "Armed groups blow up water pipeline in Iraq" | | | ✓ |
112
- | "New water treatment plant opens in California" | ✗ | ✗ | ✗ |
113
- | "Protests erupt over dam construction in Ethiopia" | ✓ | ✗ | ✗ |
114
-
115
- ## 📈 Evaluation Results
116
-
117
- Evaluated on a held-out test set of 519 samples (30% of total data, stratified by label combinations).
118
-
119
- ### Overall Performance
120
-
121
- | Metric | Score |
122
- |--------|-------|
123
- | Exact Match Accuracy | 0.8092 |
124
- | Hamming Loss | 0.0899 |
125
- | F1 (micro) | 0.8523 |
126
- | F1 (macro) | 0.7983 |
127
- | F1 (samples) | 0.6993 |
128
-
129
- ### Per-Label Performance
130
-
131
- | Label | Precision | Recall | F1 | Support |
132
- |-------|-----------|--------|-----|---------|
133
- | Trigger | 0.9030 | 0.8563 | 0.8791 | 174 |
134
- | Casualty | 0.8807 | 0.9185 | 0.8992 | 233 |
135
- | Weapon | 0.5062 | 0.7885 | 0.6165 | 52 |
136
-
137
- ### Training Details
138
-
139
- - **Training samples**: 1200 examples
140
- - **Test samples**: 519 examples (held-out before sampling)
141
- - **Base model**: BAAI/bge-small-en-v1.5 (33M params)
142
- - **Batch size**: 64
143
- - **Epochs**: 2
144
- - **Iterations**: 20 (contrastive pair generation)
145
- - **Sampling strategy**: undersampling (balances positive/negative pairs)
146
- - **Training Dataset**: [baobabtech/water-conflict-training-data](https://huggingface.co/datasets/baobabtech/water-conflict-training-data) (version: d2.0)
147
-
148
-
149
- ### 📈 Experiment Tracking
150
-
151
- All training runs are automatically tracked in a public dataset for experiment comparison:
152
-
153
- - **Evals Dataset**: [baobabtech/water-conflict-classifier-evals](https://huggingface.co/datasets/baobabtech/water-conflict-classifier-evals)
154
- - **Tracked Metrics**: F1 scores, accuracy, per-label performance, and all hyperparameters
155
- - **Compare Experiments**: View how different configurations (sample size, epochs, batch size) affect performance
156
- - **Reproducibility**: Full training configs logged for each version
157
-
158
- You can explore past experiments and compare model performance across versions using the evals dataset.
159
-
160
-
161
- ## 📊 Data Sources
162
-
163
- ### Positive Examples (Water Conflict Headlines)
164
- Pacific Institute (2025). *Water Conflict Chronology*. Pacific Institute, Oakland, CA.
165
- https://www.worldwater.org/water-conflict/
166
-
167
- ### Negative Examples (Non-Water Conflict Headlines)
168
- Armed Conflict Location & Event Data Project (ACLED).
169
- https://acleddata.com/
170
-
171
- **Note:** Training negatives include synthetic "hard negatives" - peaceful water-related news (e.g., "New desalination plant opens", "Water conservation conference") to prevent false positives on non-conflict water topics.
172
-
173
- ## 🌍 About This Project
174
-
175
- This model is part of independent experimental research drawing on the Pacific Institute's Water Conflict Chronology. The Pacific Institute maintains the world's most comprehensive open-source record of water-related conflicts, documenting over 2,700 events across 4,500 years of history.
176
-
177
- **Project Links:**
178
- - Pacific Institute Water Conflict Chronology: https://www.worldwater.org/water-conflict/
179
- - Python Package (PyPI): https://pypi.org/project/water-conflict-classifier/
180
- - Source Code: https://github.com/baobabtech/waterconflict
181
- - Model Hub: https://huggingface.co/{model_repo}
182
-
183
-
184
- ## 🌱 Frugal AI: Training with Limited Data
185
-
186
- This classifier demonstrates an intentional approach to building AI systems with **limited data** using [SetFit](https://huggingface.co/docs/setfit/en/index) - a framework for few-shot learning with sentence transformers. Rather than defaulting to massive language models (GPT, Claude, or 100B+ parameter models) for simple classification tasks, we fine-tune small, efficient models (e.g., BAAI/bge-small-en-v1.5 with ~33M parameters) on a focused dataset.
187
-
188
- **Why this matters:** The industry has normalized using trillion-parameter models to classify headlines, answer simple questions, or categorize text - tasks that don't require world knowledge, reasoning, or generative capabilities. This is computationally wasteful and environmentally costly. A properly fine-tuned small model can achieve comparable or better accuracy while using a fraction of the compute resources.
189
-
190
- **Our approach:**
191
- - Train on ~600 examples (few-shot learning with SetFit)
192
- - Deploy small parameter models (e.g., ~33M params) vs. 100B-1T parameter alternatives
193
- - Achieve specialized task performance without the overhead of general-purpose LLMs
194
- - Reduce inference costs and latency by orders of magnitude
195
-
196
- This is not about avoiding large models altogether - they're invaluable for complex reasoning tasks. But for targeted classification problems with labeled data, fine-tuning remains the professional, responsible choice.
197
-
198
-
199
- ### 🏋🏽‍♀️ Training Your Own Model
200
-
201
- You can train your own version using the [published package](https://pypi.org/project/water-conflict-classifier/).
202
-
203
- **Package includes:**
204
- - Data preprocessing utilities
205
- - Training logic (SetFit multi-label)
206
- - Evaluation metrics
207
- - Model card generation
208
-
209
- **Source code:** https://github.com/baobabtech/waterconflict/tree/main/classifier
210
- **PyPI:** https://pypi.org/project/water-conflict-classifier/
211
-
212
- ```bash
213
- # Install package
214
- pip install water-conflict-classifier
215
-
216
- # Or install from source for development
217
- git clone https://github.com/baobabtech/waterconflict.git
218
- cd waterconflict/classifier
219
- pip install -e .
220
-
221
- # Train locally
222
- python train_setfit_headline_classifier.py
223
  ```
224
 
225
- For cloud training on HuggingFace Jobs infrastructure, see the scripts folder in the repository.
226
-
227
- ## 📜 License
228
-
229
- Copyright © 2025 Baobab Tech
230
-
231
- This work is licensed under the [Creative Commons Attribution-NonCommercial 4.0 International License](http://creativecommons.org/licenses/by-nc/4.0/).
232
 
233
- **You are free to:**
234
- - **Share** — copy and redistribute the material in any medium or format
235
- - **Adapt** — remix, transform, and build upon the material
236
 
237
- **Under the following terms:**
238
- - **Attribution** You must give appropriate credit to Baobab Tech, provide a link to the license, and indicate if changes were made
239
- - **NonCommercial** — You may not use the material for commercial purposes
240
 
 
 
241
 
242
- ## 📝 Citation
243
-
244
- If you use this model in your work, please cite:
245
-
246
- ```bibtex
247
- @misc{{waterconflict2025,
248
- title={{Water Conflict Multi-Label Classifier}},
249
- author={{Independent Experimental Research Drawing on Pacific Institute Water Conflict Chronology}},
250
- year={{2025}},
251
- howpublished={{\url{{https://huggingface.co/{model_repo}}}}},
252
- note={{Training data from Pacific Institute Water Conflict Chronology and ACLED}}
253
- }}
254
- ```
255
-
256
- Please also cite the Pacific Institute's Water Conflict Chronology:
257
-
258
- ```bibtex
259
- @misc{{pacificinstitute2025,
260
- title={{Water Conflict Chronology}},
261
- author={{Pacific Institute}},
262
- year={{2025}},
263
- address={{Oakland, CA}},
264
- url={{https://www.worldwater.org/water-conflict/}},
265
- note={{Accessed: [access date]}}
266
- }}
267
- ```
268
 
 
 
 
1
  ---
2
+ language: en
3
  license: cc-by-nc-4.0
 
4
  tags:
5
  - setfit
6
  - sentence-transformers
7
  - text-classification
8
+ - generated_from_setfit_trainer
9
+ widget:
10
+ - text: Israeli forces destroy water pump in Nablus, West Bank, cutting water supply
11
+ to over 20,000 Palestinians in multiple villages
12
+ - text: Chinese man killed for speaking out against displacement of communities by
13
+ the Three Gorges Dam
14
+ - text: Protests over water cuts turn violent in Tunisia
15
+ - text: National leader Dilma Ferreira Silva, working for policy reform to support
16
+ people affected by dams, is murdered in Brazil
17
+ - text: Water reservoir sustains minor damages from bombing in Colombia
18
  metrics:
 
19
  - accuracy
20
+ pipeline_tag: text-classification
21
+ library_name: setfit
22
+ inference: false
23
+ base_model: BAAI/bge-small-en-v1.5
 
 
 
 
24
  ---
25
 
26
+ # SetFit with BAAI/bge-small-en-v1.5
27
 
28
+ This is a [SetFit](https://github.com/huggingface/setfit) model that can be used for Text Classification. This SetFit model uses [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5) as the Sentence Transformer embedding model. A OneVsRestClassifier instance is used for classification.
29
 
30
+ The model has been trained using an efficient few-shot learning technique that involves:
31
 
32
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
33
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
34
 
35
+ ## Model Details
36
 
37
+ ### Model Description
38
+ - **Model Type:** SetFit
39
+ - **Sentence Transformer body:** [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5)
40
+ - **Classification head:** a OneVsRestClassifier instance
41
+ - **Maximum Sequence Length:** 512 tokens
42
+ - **Number of Classes:** 3 classes
43
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
44
+ - **Language:** en
45
+ - **License:** cc-by-nc-4.0
46
 
47
+ ### Model Sources
48
 
49
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
50
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
51
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
52
 
53
+ ## Uses
54
 
55
+ ### Direct Use for Inference
56
 
57
+ First install the SetFit library:
 
 
 
 
 
 
 
58
 
59
+ ```bash
60
+ pip install setfit
61
+ ```
62
 
63
+ Then you can load this model and run inference.
64
 
65
  ```python
66
  from setfit import SetFitModel
67
 
68
+ # Download from the 🤗 Hub
69
  model = SetFitModel.from_pretrained("baobabtech/water-conflict-classifier")
70
+ # Run inference
71
+ preds = model("Protests over water cuts turn violent in Tunisia")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  ```
73
 
74
+ <!--
75
+ ### Downstream Use
76
+
77
+ *List how someone could finetune this model on their own dataset.*
78
+ -->
79
+
80
+ <!--
81
+ ### Out-of-Scope Use
82
+
83
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
84
+ -->
85
+
86
+ <!--
87
+ ## Bias, Risks and Limitations
88
+
89
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
90
+ -->
91
+
92
+ <!--
93
+ ### Recommendations
94
+
95
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
96
+ -->
97
+
98
+ ## Training Details
99
+
100
+ ### Training Set Metrics
101
+ | Training set | Min | Median | Max |
102
+ |:-------------|:----|:--------|:----|
103
+ | Word count | 3 | 16.3692 | 154 |
104
+
105
+ ### Training Hyperparameters
106
+ - batch_size: (64, 64)
107
+ - num_epochs: (1, 1)
108
+ - max_steps: -1
109
+ - sampling_strategy: undersampling
110
+ - num_iterations: 20
111
+ - body_learning_rate: (2e-05, 2e-05)
112
+ - head_learning_rate: 0.01
113
+ - loss: CosineSimilarityLoss
114
+ - distance_metric: cosine_distance
115
+ - margin: 0.25
116
+ - end_to_end: False
117
+ - use_amp: False
118
+ - warmup_proportion: 0.1
119
+ - l2_weight: 0.01
120
+ - seed: 42
121
+ - eval_max_steps: -1
122
+ - load_best_model_at_end: True
123
+
124
+ ### Training Results
125
+ | Epoch | Step | Training Loss | Validation Loss |
126
+ |:------:|:----:|:-------------:|:---------------:|
127
+ | 0.0013 | 1 | 0.2353 | - |
128
+ | 0.0667 | 50 | 0.2291 | - |
129
+ | 0.1333 | 100 | 0.1807 | - |
130
+ | 0.2 | 150 | 0.1317 | - |
131
+ | 0.2667 | 200 | 0.1064 | - |
132
+ | 0.3333 | 250 | 0.0919 | - |
133
+ | 0.4 | 300 | 0.0808 | - |
134
+ | 0.4667 | 350 | 0.0745 | - |
135
+ | 0.5333 | 400 | 0.0665 | - |
136
+ | 0.6 | 450 | 0.0622 | - |
137
+ | 0.6667 | 500 | 0.0578 | - |
138
+ | 0.7333 | 550 | 0.0546 | - |
139
+ | 0.8 | 600 | 0.0523 | - |
140
+ | 0.8667 | 650 | 0.053 | - |
141
+ | 0.9333 | 700 | 0.0492 | - |
142
+ | 1.0 | 750 | 0.0505 | 0.0997 |
143
+
144
+ ### Framework Versions
145
+ - Python: 3.12.12
146
+ - SetFit: 1.1.3
147
+ - Sentence Transformers: 5.1.2
148
+ - Transformers: 4.57.3
149
+ - PyTorch: 2.9.1+cu128
150
+ - Datasets: 4.4.1
151
+ - Tokenizers: 0.22.1
152
+
153
+ ## Citation
154
+
155
+ ### BibTeX
156
+ ```bibtex
157
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
158
+ doi = {10.48550/ARXIV.2209.11055},
159
+ url = {https://arxiv.org/abs/2209.11055},
160
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
161
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
162
+ title = {Efficient Few-Shot Learning Without Prompts},
163
+ publisher = {arXiv},
164
+ year = {2022},
165
+ copyright = {Creative Commons Attribution 4.0 International}
166
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  ```
168
 
169
+ <!--
170
+ ## Glossary
 
 
 
 
 
171
 
172
+ *Clearly define terms in order to be accessible across audiences.*
173
+ -->
 
174
 
175
+ <!--
176
+ ## Model Card Authors
 
177
 
178
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
179
+ -->
180
 
181
+ <!--
182
+ ## Model Card Contact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
185
+ -->
config_setfit.json CHANGED
@@ -1,8 +1,8 @@
1
  {
2
- "normalize_embeddings": false,
3
  "labels": [
4
  "Trigger",
5
  "Casualty",
6
  "Weapon"
7
- ]
 
8
  }
 
1
  {
 
2
  "labels": [
3
  "Trigger",
4
  "Casualty",
5
  "Weapon"
6
+ ],
7
+ "normalize_embeddings": false
8
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9f675d6abd580aff11b20c655971d1f1d956f72d47aaf98928c1face94e95b56
3
  size 133462128
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2e8e508225135db2b8aa14e148509f45d49310d4ea4357573c79b0ec6ade4d2
3
  size 133462128
model_head.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0d98c8e5416b64be61f0c4623cef9e74e93eaf99a30f7772d5ff92e699bb8667
3
  size 11236
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dccc0e876439de20b04d9efb2f76f1441a1b548b5edc8a61d6d0174ca20aafb1
3
  size 11236