lucienbaumgartner commited on
Commit
0956501
·
verified ·
1 Parent(s): 80685df

Add SetFit model

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false,
9
+ "include_prompt": true
10
+ }
README.md ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - setfit
4
+ - sentence-transformers
5
+ - text-classification
6
+ - generated_from_setfit_trainer
7
+ widget:
8
+ - text: if it is raining, as was stated, then it is irrelevant what someone thinks
9
+ abut whether or not it is raining. it is raining. therefore, the statement was
10
+ nonsensical.
11
+ - text: the first part of the sentence was a fact but the second half was sally's
12
+ opinion
13
+ - text: because on one hand it is but actually not a long term solution
14
+ - text: it contradicted itself
15
+ - text: cyberbully may seem cruel to everyone, but to tom, he does not feel cruel
16
+ to him.
17
+ metrics:
18
+ - accuracy
19
+ - precision
20
+ - recall
21
+ - f1
22
+ pipeline_tag: text-classification
23
+ library_name: setfit
24
+ inference: true
25
+ base_model: sentence-transformers/paraphrase-mpnet-base-v2
26
+ model-index:
27
+ - name: SetFit with sentence-transformers/paraphrase-mpnet-base-v2
28
+ results:
29
+ - task:
30
+ type: text-classification
31
+ name: Text Classification
32
+ dataset:
33
+ name: Unknown
34
+ type: unknown
35
+ split: test
36
+ metrics:
37
+ - type: accuracy
38
+ value: 0.868421052631579
39
+ name: Accuracy
40
+ - type: precision
41
+ value: 0.5642857142857144
42
+ name: Precision
43
+ - type: recall
44
+ value: 0.5629370629370629
45
+ name: Recall
46
+ - type: f1
47
+ value: 0.562610229276896
48
+ name: F1
49
+ ---
50
+
51
+ # SetFit with sentence-transformers/paraphrase-mpnet-base-v2
52
+
53
+ This is a [SetFit](https://github.com/huggingface/setfit) model that can be used for Text Classification. This SetFit model uses [sentence-transformers/paraphrase-mpnet-base-v2](https://huggingface.co/sentence-transformers/paraphrase-mpnet-base-v2) as the Sentence Transformer embedding model. A [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance is used for classification.
54
+
55
+ The model has been trained using an efficient few-shot learning technique that involves:
56
+
57
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
58
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
59
+
60
+ ## Model Details
61
+
62
+ ### Model Description
63
+ - **Model Type:** SetFit
64
+ - **Sentence Transformer body:** [sentence-transformers/paraphrase-mpnet-base-v2](https://huggingface.co/sentence-transformers/paraphrase-mpnet-base-v2)
65
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
66
+ - **Maximum Sequence Length:** 512 tokens
67
+ - **Number of Classes:** 3 classes
68
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
69
+ <!-- - **Language:** Unknown -->
70
+ <!-- - **License:** Unknown -->
71
+
72
+ ### Model Sources
73
+
74
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
75
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
76
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
77
+
78
+ ### Model Labels
79
+ | Label | Examples |
80
+ |:-----------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
81
+ | Linguistic (in)felicity | <ul><li>'because the second statement negates what was stated in the first part of the sentence'</li><li>'there is a logic conflict in the statement that renders it bizarre and nonsensical.'</li><li>'there was a contradiction of statements if read at face value, however, it could be read that being homeless is not right in which case the statement would make sense. it is unclear.'</li></ul> |
82
+ | Enrichment / reinterpretation | <ul><li>'the statement recognised the objective compassion but the opinion contradicted it'</li><li>"because while it is compassionate to help the homeless people don't always do it out of compassion."</li><li>'it could be the way how homeless are helped. there could be better ways to handle that'</li></ul> |
83
+ | Lack of understanding / clear misunderstanding | <ul><li>'it simply sounded stupid. i doubt it makes any sense'</li><li>'it statement didnt make any sense, for us to better understand, tom needs to further explain his reason for stating why its not cruel after first saying it is'</li><li>'it sounds very contradictory'</li></ul> |
84
+
85
+ ## Evaluation
86
+
87
+ ### Metrics
88
+ | Label | Accuracy | Precision | Recall | F1 |
89
+ |:--------|:---------|:----------|:-------|:-------|
90
+ | **all** | 0.8684 | 0.5643 | 0.5629 | 0.5626 |
91
+
92
+ ## Uses
93
+
94
+ ### Direct Use for Inference
95
+
96
+ First install the SetFit library:
97
+
98
+ ```bash
99
+ pip install setfit
100
+ ```
101
+
102
+ Then you can load this model and run inference.
103
+
104
+ ```python
105
+ from setfit import SetFitModel
106
+
107
+ # Download from the 🤗 Hub
108
+ model = SetFitModel.from_pretrained("setfit_model_id")
109
+ # Run inference
110
+ preds = model("it contradicted itself")
111
+ ```
112
+
113
+ <!--
114
+ ### Downstream Use
115
+
116
+ *List how someone could finetune this model on their own dataset.*
117
+ -->
118
+
119
+ <!--
120
+ ### Out-of-Scope Use
121
+
122
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
123
+ -->
124
+
125
+ <!--
126
+ ## Bias, Risks and Limitations
127
+
128
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
129
+ -->
130
+
131
+ <!--
132
+ ### Recommendations
133
+
134
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
135
+ -->
136
+
137
+ ## Training Details
138
+
139
+ ### Training Set Metrics
140
+ | Training set | Min | Median | Max |
141
+ |:-------------|:----|:--------|:----|
142
+ | Word count | 2 | 16.6447 | 92 |
143
+
144
+ | Label | Training Sample Count |
145
+ |:-----------------------------------------------|:----------------------|
146
+ | Enrichment / reinterpretation | 31 |
147
+ | Lack of understanding / clear misunderstanding | 10 |
148
+ | Linguistic (in)felicity | 111 |
149
+
150
+ ### Training Hyperparameters
151
+ - batch_size: (16, 16)
152
+ - num_epochs: (10, 10)
153
+ - max_steps: -1
154
+ - sampling_strategy: oversampling
155
+ - num_iterations: 20
156
+ - body_learning_rate: (2e-05, 2e-05)
157
+ - head_learning_rate: 2e-05
158
+ - loss: CosineSimilarityLoss
159
+ - distance_metric: cosine_distance
160
+ - margin: 0.25
161
+ - end_to_end: False
162
+ - use_amp: False
163
+ - warmup_proportion: 0.1
164
+ - l2_weight: 0.01
165
+ - seed: 3786
166
+ - eval_max_steps: -1
167
+ - load_best_model_at_end: False
168
+
169
+ ### Training Results
170
+ | Epoch | Step | Training Loss | Validation Loss |
171
+ |:------:|:----:|:-------------:|:---------------:|
172
+ | 0.0026 | 1 | 0.2539 | - |
173
+ | 0.1316 | 50 | 0.2248 | - |
174
+ | 0.2632 | 100 | 0.1681 | - |
175
+ | 0.3947 | 150 | 0.0854 | - |
176
+ | 0.5263 | 200 | 0.0128 | - |
177
+ | 0.6579 | 250 | 0.0074 | - |
178
+ | 0.7895 | 300 | 0.0017 | - |
179
+ | 0.9211 | 350 | 0.0021 | - |
180
+ | 1.0526 | 400 | 0.0024 | - |
181
+ | 1.1842 | 450 | 0.0004 | - |
182
+ | 1.3158 | 500 | 0.0011 | - |
183
+ | 1.4474 | 550 | 0.0016 | - |
184
+ | 1.5789 | 600 | 0.0003 | - |
185
+ | 1.7105 | 650 | 0.0002 | - |
186
+ | 1.8421 | 700 | 0.0002 | - |
187
+ | 1.9737 | 750 | 0.0002 | - |
188
+ | 2.1053 | 800 | 0.0002 | - |
189
+ | 2.2368 | 850 | 0.0002 | - |
190
+ | 2.3684 | 900 | 0.0002 | - |
191
+ | 2.5 | 950 | 0.0001 | - |
192
+ | 2.6316 | 1000 | 0.0001 | - |
193
+ | 2.7632 | 1050 | 0.0001 | - |
194
+ | 2.8947 | 1100 | 0.0001 | - |
195
+ | 3.0263 | 1150 | 0.0001 | - |
196
+ | 3.1579 | 1200 | 0.0001 | - |
197
+ | 3.2895 | 1250 | 0.0001 | - |
198
+ | 3.4211 | 1300 | 0.0001 | - |
199
+ | 3.5526 | 1350 | 0.0001 | - |
200
+ | 3.6842 | 1400 | 0.0001 | - |
201
+ | 3.8158 | 1450 | 0.0001 | - |
202
+ | 3.9474 | 1500 | 0.0001 | - |
203
+ | 4.0789 | 1550 | 0.0001 | - |
204
+ | 4.2105 | 1600 | 0.0001 | - |
205
+ | 4.3421 | 1650 | 0.0001 | - |
206
+ | 4.4737 | 1700 | 0.0001 | - |
207
+ | 4.6053 | 1750 | 0.0001 | - |
208
+ | 4.7368 | 1800 | 0.0001 | - |
209
+ | 4.8684 | 1850 | 0.0001 | - |
210
+ | 5.0 | 1900 | 0.0001 | - |
211
+ | 5.1316 | 1950 | 0.0001 | - |
212
+ | 5.2632 | 2000 | 0.0001 | - |
213
+ | 5.3947 | 2050 | 0.0001 | - |
214
+ | 5.5263 | 2100 | 0.0001 | - |
215
+ | 5.6579 | 2150 | 0.0001 | - |
216
+ | 5.7895 | 2200 | 0.0001 | - |
217
+ | 5.9211 | 2250 | 0.0001 | - |
218
+ | 6.0526 | 2300 | 0.0001 | - |
219
+ | 6.1842 | 2350 | 0.0001 | - |
220
+ | 6.3158 | 2400 | 0.0001 | - |
221
+ | 6.4474 | 2450 | 0.0001 | - |
222
+ | 6.5789 | 2500 | 0.0001 | - |
223
+ | 6.7105 | 2550 | 0.0001 | - |
224
+ | 6.8421 | 2600 | 0.0001 | - |
225
+ | 6.9737 | 2650 | 0.0001 | - |
226
+ | 7.1053 | 2700 | 0.0001 | - |
227
+ | 7.2368 | 2750 | 0.0001 | - |
228
+ | 7.3684 | 2800 | 0.0001 | - |
229
+ | 7.5 | 2850 | 0.0001 | - |
230
+ | 7.6316 | 2900 | 0.0001 | - |
231
+ | 7.7632 | 2950 | 0.0001 | - |
232
+ | 7.8947 | 3000 | 0.0001 | - |
233
+ | 8.0263 | 3050 | 0.0001 | - |
234
+ | 8.1579 | 3100 | 0.0001 | - |
235
+ | 8.2895 | 3150 | 0.0001 | - |
236
+ | 8.4211 | 3200 | 0.0001 | - |
237
+ | 8.5526 | 3250 | 0.0001 | - |
238
+ | 8.6842 | 3300 | 0.0001 | - |
239
+ | 8.8158 | 3350 | 0.0001 | - |
240
+ | 8.9474 | 3400 | 0.0012 | - |
241
+ | 9.0789 | 3450 | 0.0003 | - |
242
+ | 9.2105 | 3500 | 0.0001 | - |
243
+ | 9.3421 | 3550 | 0.0001 | - |
244
+ | 9.4737 | 3600 | 0.0001 | - |
245
+ | 9.6053 | 3650 | 0.0001 | - |
246
+ | 9.7368 | 3700 | 0.0001 | - |
247
+ | 9.8684 | 3750 | 0.0001 | - |
248
+ | 10.0 | 3800 | 0.0 | - |
249
+
250
+ ### Framework Versions
251
+ - Python: 3.11.9
252
+ - SetFit: 1.1.3
253
+ - Sentence Transformers: 5.1.0
254
+ - Transformers: 4.55.2
255
+ - PyTorch: 2.8.0
256
+ - Datasets: 4.0.0
257
+ - Tokenizers: 0.21.4
258
+
259
+ ## Citation
260
+
261
+ ### BibTeX
262
+ ```bibtex
263
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
264
+ doi = {10.48550/ARXIV.2209.11055},
265
+ url = {https://arxiv.org/abs/2209.11055},
266
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
267
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
268
+ title = {Efficient Few-Shot Learning Without Prompts},
269
+ publisher = {arXiv},
270
+ year = {2022},
271
+ copyright = {Creative Commons Attribution 4.0 International}
272
+ }
273
+ ```
274
+
275
+ <!--
276
+ ## Glossary
277
+
278
+ *Clearly define terms in order to be accessible across audiences.*
279
+ -->
280
+
281
+ <!--
282
+ ## Model Card Authors
283
+
284
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
285
+ -->
286
+
287
+ <!--
288
+ ## Model Card Contact
289
+
290
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
291
+ -->
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MPNetModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "eos_token_id": 2,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "layer_norm_eps": 1e-05,
14
+ "max_position_embeddings": 514,
15
+ "model_type": "mpnet",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 1,
19
+ "relative_attention_num_buckets": 32,
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.55.2",
22
+ "vocab_size": 30527
23
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "5.1.0",
4
+ "transformers": "4.55.2",
5
+ "pytorch": "2.8.0"
6
+ },
7
+ "model_type": "SentenceTransformer",
8
+ "prompts": {
9
+ "query": "",
10
+ "document": ""
11
+ },
12
+ "default_prompt_name": null,
13
+ "similarity_fn_name": "cosine"
14
+ }
config_setfit.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "normalize_embeddings": false,
3
+ "labels": [
4
+ "Enrichment / reinterpretation",
5
+ "Lack of understanding / clear misunderstanding",
6
+ "Linguistic (in)felicity"
7
+ ]
8
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7d2a8b35b49423a64794d34ebcae76e32988b9bfc40e2177581326adc8e156b
3
+ size 437967672
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7df08c779d36e50438be6ea8b87170caa74f8b5edabeef9f91de45123d75ec94
3
+ size 19855
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ }
14
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "[UNK]",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "104": {
28
+ "content": "[UNK]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "30526": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<s>",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "<s>",
47
+ "do_basic_tokenize": true,
48
+ "do_lower_case": true,
49
+ "eos_token": "</s>",
50
+ "extra_special_tokens": {},
51
+ "mask_token": "<mask>",
52
+ "model_max_length": 512,
53
+ "never_split": null,
54
+ "pad_token": "<pad>",
55
+ "sep_token": "</s>",
56
+ "strip_accents": null,
57
+ "tokenize_chinese_chars": true,
58
+ "tokenizer_class": "MPNetTokenizer",
59
+ "unk_token": "[UNK]"
60
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff