tomaarsen HF staff commited on
Commit
cb692ec
1 Parent(s): 7fc5c75

Add SetFit model

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
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
+ }
README.md ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ library_name: setfit
6
+ tags:
7
+ - setfit
8
+ - sentence-transformers
9
+ - text-classification
10
+ - generated_from_setfit_trainer
11
+ datasets:
12
+ - sst2
13
+ metrics:
14
+ - precision
15
+ - recall
16
+ - f1
17
+ widget:
18
+ - text: 'this is a story of two misfits who do n''t stand a chance alone , but together
19
+ they are magnificent . '
20
+ - text: 'it does n''t believe in itself , it has no sense of humor ... it ''s just
21
+ plain bored . '
22
+ - text: 'the band ''s courage in the face of official repression is inspiring , especially
23
+ for aging hippies ( this one included ) . '
24
+ - text: 'a fast , funny , highly enjoyable movie . '
25
+ - text: 'the movie achieves as great an impact by keeping these thoughts hidden as
26
+ ... ( quills ) did by showing them . '
27
+ pipeline_tag: text-classification
28
+ co2_eq_emissions:
29
+ emissions: 2.768308759172054
30
+ source: codecarbon
31
+ training_type: fine-tuning
32
+ on_cloud: false
33
+ cpu_model: 13th Gen Intel(R) Core(TM) i7-13700K
34
+ ram_total_size: 31.777088165283203
35
+ hours_used: 0.072
36
+ hardware_used: 1 x NVIDIA GeForce RTX 3090
37
+ base_model: sentence-transformers/all-MiniLM-L6-v2
38
+ model-index:
39
+ - name: SetFit with sentence-transformers/all-MiniLM-L6-v2 on sst2
40
+ results:
41
+ - task:
42
+ type: text-classification
43
+ name: Text Classification
44
+ dataset:
45
+ name: sst2
46
+ type: sst2
47
+ split: test
48
+ metrics:
49
+ - type: accuracy
50
+ value: 0.7512953367875648
51
+ name: Accuracy
52
+ ---
53
+
54
+ # SetFit with sentence-transformers/all-MiniLM-L6-v2 on sst2
55
+
56
+ This is a [SetFit](https://github.com/huggingface/setfit) model trained on the [sst2](https://huggingface.co/datasets/sst2) dataset that can be used for Text Classification. This SetFit model uses [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-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.
57
+
58
+ The model has been trained using an efficient few-shot learning technique that involves:
59
+
60
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
61
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
62
+
63
+ ## Model Details
64
+
65
+ ### Model Description
66
+ - **Model Type:** SetFit
67
+ - **Sentence Transformer body:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
68
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance.
69
+ - **Maximum Sequence Length:** 256 tokens
70
+ - **Number of Classes:** 2 classes
71
+ - **Training Dataset:** [sst2](https://huggingface.co/datasets/sst2)
72
+ - **Language:** en
73
+ - **License:** apache-2.0
74
+
75
+ ### Model Sources
76
+
77
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
78
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
79
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
80
+
81
+ ### Model Labels
82
+ | Label | Examples |
83
+ |:---------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
84
+ | negative | <ul><li>'a tough pill to swallow and '</li><li>'indignation '</li><li>'that the typical hollywood disregard for historical truth and realism is at work here '</li></ul> |
85
+ | positive | <ul><li>"a moving experience for people who have n't read the book "</li><li>'in the best possible senses of both those words '</li><li>'to serve the work especially well '</li></ul> |
86
+
87
+ ## Evaluation
88
+
89
+ ### Metrics
90
+ | Label | Accuracy |
91
+ |:--------|:---------|
92
+ | **all** | 0.7513 |
93
+
94
+ ## Uses
95
+
96
+ ### Direct Use for Inference
97
+
98
+ First install the SetFit library:
99
+
100
+ ```bash
101
+ pip install setfit
102
+ ```
103
+
104
+ Then you can load this model and run inference.
105
+
106
+ ```python
107
+ from setfit import SetFitModel
108
+
109
+ # Download from 🤗 Hub
110
+ model = SetFitModel.from_pretrained("tomaarsen/setfit-all-MiniLM-L6-v2-sst2-8-shot")
111
+ # Run inference
112
+ preds = model("a fast , funny , highly enjoyable movie . ")
113
+ ```
114
+ <!--
115
+ ### Downstream Use
116
+
117
+ *List how someone could finetune this model on their own dataset.*
118
+ -->
119
+
120
+ <!--
121
+ ### Out-of-Scope Use
122
+
123
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
124
+ -->
125
+
126
+ <!--
127
+ ## Bias, Risks and Limitations
128
+
129
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
130
+ -->
131
+
132
+ <!--
133
+ ### Recommendations
134
+
135
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
136
+ -->
137
+
138
+ ## Training Details
139
+
140
+ ### Training Set Metrics
141
+ | Training set | Min | Median | Max |
142
+ |:-------------|:----|:--------|:----|
143
+ | Word count | 2 | 10.2812 | 36 |
144
+
145
+ | Label | Training Sample Count |
146
+ |:---------|:----------------------|
147
+ | negative | 32 |
148
+ | positive | 32 |
149
+
150
+ ### Training Hyperparameters
151
+ - batch_size: (16, 16)
152
+ - num_epochs: (3, 3)
153
+ - max_steps: -1
154
+ - sampling_strategy: oversampling
155
+ - body_learning_rate: (2e-05, 1e-05)
156
+ - head_learning_rate: 0.01
157
+ - loss: CosineSimilarityLoss
158
+ - distance_metric: cosine_distance
159
+ - margin: 0.25
160
+ - end_to_end: False
161
+ - use_amp: False
162
+ - warmup_proportion: 0.1
163
+ - seed: 42
164
+ - load_best_model_at_end: True
165
+
166
+ ### Training Results
167
+ | Epoch | Step | Training Loss | Validation Loss |
168
+ |:----------:|:------:|:-------------:|:---------------:|
169
+ | 0.0076 | 1 | 0.3787 | - |
170
+ | 0.0758 | 10 | 0.2855 | - |
171
+ | 0.1515 | 20 | 0.3458 | 0.29 |
172
+ | 0.2273 | 30 | 0.2496 | - |
173
+ | 0.3030 | 40 | 0.2398 | 0.2482 |
174
+ | 0.3788 | 50 | 0.2068 | - |
175
+ | 0.4545 | 60 | 0.2471 | 0.244 |
176
+ | 0.5303 | 70 | 0.2053 | - |
177
+ | **0.6061** | **80** | **0.1802** | **0.2361** |
178
+ | 0.6818 | 90 | 0.0767 | - |
179
+ | 0.7576 | 100 | 0.0279 | 0.2365 |
180
+ | 0.8333 | 110 | 0.0192 | - |
181
+ | 0.9091 | 120 | 0.0095 | 0.2527 |
182
+ | 0.9848 | 130 | 0.0076 | - |
183
+ | 1.0606 | 140 | 0.0082 | 0.2651 |
184
+ | 1.1364 | 150 | 0.0068 | - |
185
+ | 1.2121 | 160 | 0.0052 | 0.2722 |
186
+ | 1.2879 | 170 | 0.0029 | - |
187
+ | 1.3636 | 180 | 0.0042 | 0.273 |
188
+ | 1.4394 | 190 | 0.0026 | - |
189
+ | 1.5152 | 200 | 0.0036 | 0.2761 |
190
+ | 1.5909 | 210 | 0.0044 | - |
191
+ | 1.6667 | 220 | 0.0027 | 0.2796 |
192
+ | 1.7424 | 230 | 0.0025 | - |
193
+ | 1.8182 | 240 | 0.0025 | 0.2817 |
194
+ | 1.8939 | 250 | 0.003 | - |
195
+ | 1.9697 | 260 | 0.0026 | 0.2817 |
196
+ | 2.0455 | 270 | 0.0035 | - |
197
+ | 2.1212 | 280 | 0.002 | 0.2816 |
198
+ | 2.1970 | 290 | 0.0023 | - |
199
+ | 2.2727 | 300 | 0.0016 | 0.2821 |
200
+ | 2.3485 | 310 | 0.0023 | - |
201
+ | 2.4242 | 320 | 0.0015 | 0.2838 |
202
+ | 2.5 | 330 | 0.0014 | - |
203
+ | 2.5758 | 340 | 0.002 | 0.2842 |
204
+ | 2.6515 | 350 | 0.002 | - |
205
+ | 2.7273 | 360 | 0.0013 | 0.2847 |
206
+ | 2.8030 | 370 | 0.0009 | - |
207
+ | 2.8788 | 380 | 0.0018 | 0.2857 |
208
+ | 2.9545 | 390 | 0.0016 | - |
209
+
210
+ * The bold row denotes the saved checkpoint.
211
+ ### Environmental Impact
212
+ Carbon emissions were measured using [CodeCarbon](https://github.com/mlco2/codecarbon).
213
+ - **Carbon Emitted**: 0.003 kg of CO2
214
+ - **Hours Used**: 0.072 hours
215
+
216
+ ### Training Hardware
217
+ - **On Cloud**: No
218
+ - **GPU Model**: 1 x NVIDIA GeForce RTX 3090
219
+ - **CPU Model**: 13th Gen Intel(R) Core(TM) i7-13700K
220
+ - **RAM Size**: 31.78 GB
221
+
222
+ ### Framework Versions
223
+ - Python: 3.9.16
224
+ - SetFit: 1.0.0.dev0
225
+ - Sentence Transformers: 2.2.2
226
+ - Transformers: 4.29.0
227
+ - PyTorch: 1.13.1+cu117
228
+ - Datasets: 2.15.0
229
+ - Tokenizers: 0.13.3
230
+
231
+ ## Citation
232
+
233
+ ### BibTeX
234
+ ```bibtex
235
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
236
+ doi = {10.48550/ARXIV.2209.11055},
237
+ url = {https://arxiv.org/abs/2209.11055},
238
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
239
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
240
+ title = {Efficient Few-Shot Learning Without Prompts},
241
+ publisher = {arXiv},
242
+ year = {2022},
243
+ copyright = {Creative Commons Attribution 4.0 International}
244
+ }
245
+ ```
246
+
247
+ <!--
248
+ ## Glossary
249
+
250
+ *Clearly define terms in order to be accessible across audiences.*
251
+ -->
252
+
253
+ <!--
254
+ ## Model Card Authors
255
+
256
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
257
+ -->
258
+
259
+ <!--
260
+ ## Model Card Contact
261
+
262
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
263
+ -->
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "checkpoints\\step_80\\",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 384,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 1536,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 6,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.29.0",
23
+ "type_vocab_size": 2,
24
+ "use_cache": true,
25
+ "vocab_size": 30522
26
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.6.1",
5
+ "pytorch": "1.8.1"
6
+ }
7
+ }
config_setfit.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "labels": [
3
+ "negative",
4
+ "positive"
5
+ ],
6
+ "normalize_embeddings": false
7
+ }
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9e9469425745e2df00e05a906930ecf15100782a6d9a7225809dcb85b568cc2
3
+ size 3887
modules.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.models.Normalize"
19
+ }
20
+ ]
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28307aa11df3ffd2adec2a1e787390c05ef12f7841f998f08923adf587c1ee49
3
+ size 90891565
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 256,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": true,
6
+ "mask_token": "[MASK]",
7
+ "model_max_length": 512,
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "strip_accents": null,
12
+ "tokenize_chinese_chars": true,
13
+ "tokenizer_class": "BertTokenizer",
14
+ "unk_token": "[UNK]"
15
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff