moshew commited on
Commit
cfb5c46
1 Parent(s): bb49b15

Add SetFit model

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
3
+ "pooling_mode_cls_token": true,
4
+ "pooling_mode_mean_tokens": false,
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,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: setfit
3
+ tags:
4
+ - setfit
5
+ - sentence-transformers
6
+ - text-classification
7
+ - generated_from_setfit_trainer
8
+ metrics:
9
+ - accuracy
10
+ widget:
11
+ - text: Ruukki Group calculates that it has lost EUR 4mn in the failed project .
12
+ - text: The Tecnomen Convergent Charging solution includes functionality for prepaid
13
+ and post-paid billing , charging and rating of voice calls , video calls , raw
14
+ data traffic and any type of content services in both mobile and fixed networks
15
+ .
16
+ - text: The combined value of the planned investments is about EUR 30mn .
17
+ - text: The Diameter Protocol is developed according to the standards IETF RFC 3588
18
+ and IETF RFC 3539 .
19
+ - text: Below are unaudited consolidated results for Aspocomp Group under IFRS reporting
20
+ standards .
21
+ pipeline_tag: text-classification
22
+ inference: true
23
+ base_model: BAAI/bge-small-en-v1.5
24
+ model-index:
25
+ - name: SetFit with BAAI/bge-small-en-v1.5
26
+ results:
27
+ - task:
28
+ type: text-classification
29
+ name: Text Classification
30
+ dataset:
31
+ name: Unknown
32
+ type: unknown
33
+ split: test
34
+ metrics:
35
+ - type: accuracy
36
+ value: 0.9426048565121413
37
+ name: Accuracy
38
+ ---
39
+
40
+ # SetFit with BAAI/bge-small-en-v1.5
41
+
42
+ 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 [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance is used for classification.
43
+
44
+ The model has been trained using an efficient few-shot learning technique that involves:
45
+
46
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
47
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
48
+
49
+ ## Model Details
50
+
51
+ ### Model Description
52
+ - **Model Type:** SetFit
53
+ - **Sentence Transformer body:** [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5)
54
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
55
+ - **Maximum Sequence Length:** 512 tokens
56
+ - **Number of Classes:** 3 classes
57
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
58
+ <!-- - **Language:** Unknown -->
59
+ <!-- - **License:** Unknown -->
60
+
61
+ ### Model Sources
62
+
63
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
64
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
65
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
66
+
67
+ ### Model Labels
68
+ | Label | Examples |
69
+ |:---------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
70
+ | positive | <ul><li>'HELSINKI ( AFX ) - Nokian Tyres reported a fourth quarter pretax profit of 61.5 mln eur , up from 48.6 mln on the back of strong sales .'</li><li>'Equity ratio was 60.9 % compared to 54.2 % In the third quarter of 2007 , net sales of the Frozen Foods Business totaled EUR 11.0 , up by about 5 % from the third quarter of 2006 .'</li><li>"`` After a long , unprofitable period the Food Division posted a profitable result , which speaks of a healthier cost structure and a new approach in business operations , '' Rihko said ."</li></ul> |
71
+ | neutral | <ul><li>'Their names have not yet been released .'</li><li>'The contract includes design , construction , delivery of equipment , installation and commissioning .'</li><li>"Tieto 's service is also used to send , process and receive materials related to absentee voting ."</li></ul> |
72
+ | negative | <ul><li>'The company confirmed its estimate for lower revenue for the whole 2009 than the year-ago EUR93 .9 m as given in the interim report on 5 August 2009 .'</li><li>'Acando AB ( ACANB SS ) fell 8.9 percent to 13.35 kronor , the lowest close since Dec. 11 .'</li><li>'Okmetic expects its net sales for the first half of 2009 to be less than in 2008 .'</li></ul> |
73
+
74
+ ## Evaluation
75
+
76
+ ### Metrics
77
+ | Label | Accuracy |
78
+ |:--------|:---------|
79
+ | **all** | 0.9426 |
80
+
81
+ ## Uses
82
+
83
+ ### Direct Use for Inference
84
+
85
+ First install the SetFit library:
86
+
87
+ ```bash
88
+ pip install setfit
89
+ ```
90
+
91
+ Then you can load this model and run inference.
92
+
93
+ ```python
94
+ from setfit import SetFitModel
95
+
96
+ # Download from the 🤗 Hub
97
+ model = SetFitModel.from_pretrained("moshew/bge-small-en-v1.5-SetFit-FSA")
98
+ # Run inference
99
+ preds = model("The combined value of the planned investments is about EUR 30mn .")
100
+ ```
101
+
102
+ <!--
103
+ ### Downstream Use
104
+
105
+ *List how someone could finetune this model on their own dataset.*
106
+ -->
107
+
108
+ <!--
109
+ ### Out-of-Scope Use
110
+
111
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
112
+ -->
113
+
114
+ <!--
115
+ ## Bias, Risks and Limitations
116
+
117
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
118
+ -->
119
+
120
+ <!--
121
+ ### Recommendations
122
+
123
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
124
+ -->
125
+
126
+ ## Training Details
127
+
128
+ ### Training Set Metrics
129
+ | Training set | Min | Median | Max |
130
+ |:-------------|:----|:--------|:----|
131
+ | Word count | 2 | 22.4020 | 60 |
132
+
133
+ | Label | Training Sample Count |
134
+ |:---------|:----------------------|
135
+ | negative | 266 |
136
+ | neutral | 1142 |
137
+ | positive | 403 |
138
+
139
+ ### Training Hyperparameters
140
+ - batch_size: (16, 16)
141
+ - num_epochs: (1, 1)
142
+ - max_steps: -1
143
+ - sampling_strategy: oversampling
144
+ - num_iterations: 10
145
+ - body_learning_rate: (2e-05, 1e-05)
146
+ - head_learning_rate: 0.01
147
+ - loss: CosineSimilarityLoss
148
+ - distance_metric: cosine_distance
149
+ - margin: 0.25
150
+ - end_to_end: False
151
+ - use_amp: False
152
+ - warmup_proportion: 0.1
153
+ - seed: 42
154
+ - eval_max_steps: -1
155
+ - load_best_model_at_end: False
156
+
157
+ ### Training Results
158
+ | Epoch | Step | Training Loss | Validation Loss |
159
+ |:------:|:----:|:-------------:|:---------------:|
160
+ | 0.0004 | 1 | 0.2832 | - |
161
+ | 0.0221 | 50 | 0.209 | - |
162
+ | 0.0442 | 100 | 0.1899 | - |
163
+ | 0.0663 | 150 | 0.1399 | - |
164
+ | 0.0883 | 200 | 0.1274 | - |
165
+ | 0.1104 | 250 | 0.0586 | - |
166
+ | 0.1325 | 300 | 0.0756 | - |
167
+ | 0.1546 | 350 | 0.0777 | - |
168
+ | 0.1767 | 400 | 0.0684 | - |
169
+ | 0.1988 | 450 | 0.0311 | - |
170
+ | 0.2208 | 500 | 0.0102 | - |
171
+ | 0.2429 | 550 | 0.052 | - |
172
+ | 0.2650 | 600 | 0.0149 | - |
173
+ | 0.2871 | 650 | 0.1042 | - |
174
+ | 0.3092 | 700 | 0.061 | - |
175
+ | 0.3313 | 750 | 0.0083 | - |
176
+ | 0.3534 | 800 | 0.0036 | - |
177
+ | 0.3754 | 850 | 0.002 | - |
178
+ | 0.3975 | 900 | 0.0598 | - |
179
+ | 0.4196 | 950 | 0.0036 | - |
180
+ | 0.4417 | 1000 | 0.0027 | - |
181
+ | 0.4638 | 1050 | 0.0617 | - |
182
+ | 0.4859 | 1100 | 0.0015 | - |
183
+ | 0.5080 | 1150 | 0.0022 | - |
184
+ | 0.5300 | 1200 | 0.0016 | - |
185
+ | 0.5521 | 1250 | 0.0009 | - |
186
+ | 0.5742 | 1300 | 0.0013 | - |
187
+ | 0.5963 | 1350 | 0.0009 | - |
188
+ | 0.6184 | 1400 | 0.0015 | - |
189
+ | 0.6405 | 1450 | 0.0018 | - |
190
+ | 0.6625 | 1500 | 0.0015 | - |
191
+ | 0.6846 | 1550 | 0.0018 | - |
192
+ | 0.7067 | 1600 | 0.0016 | - |
193
+ | 0.7288 | 1650 | 0.0022 | - |
194
+ | 0.7509 | 1700 | 0.0013 | - |
195
+ | 0.7730 | 1750 | 0.0108 | - |
196
+ | 0.7951 | 1800 | 0.0016 | - |
197
+ | 0.8171 | 1850 | 0.0021 | - |
198
+ | 0.8392 | 1900 | 0.002 | - |
199
+ | 0.8613 | 1950 | 0.0015 | - |
200
+ | 0.8834 | 2000 | 0.0016 | - |
201
+ | 0.9055 | 2050 | 0.0028 | - |
202
+ | 0.9276 | 2100 | 0.0013 | - |
203
+ | 0.9496 | 2150 | 0.0019 | - |
204
+ | 0.9717 | 2200 | 0.0075 | - |
205
+ | 0.9938 | 2250 | 0.0015 | - |
206
+
207
+ ### Framework Versions
208
+ - Python: 3.10.12
209
+ - SetFit: 1.0.3
210
+ - Sentence Transformers: 2.5.1
211
+ - Transformers: 4.38.1
212
+ - PyTorch: 2.1.0+cu121
213
+ - Datasets: 2.18.0
214
+ - Tokenizers: 0.15.2
215
+
216
+ ## Citation
217
+
218
+ ### BibTeX
219
+ ```bibtex
220
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
221
+ doi = {10.48550/ARXIV.2209.11055},
222
+ url = {https://arxiv.org/abs/2209.11055},
223
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
224
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
225
+ title = {Efficient Few-Shot Learning Without Prompts},
226
+ publisher = {arXiv},
227
+ year = {2022},
228
+ copyright = {Creative Commons Attribution 4.0 International}
229
+ }
230
+ ```
231
+
232
+ <!--
233
+ ## Glossary
234
+
235
+ *Clearly define terms in order to be accessible across audiences.*
236
+ -->
237
+
238
+ <!--
239
+ ## Model Card Authors
240
+
241
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
242
+ -->
243
+
244
+ <!--
245
+ ## Model Card Contact
246
+
247
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
248
+ -->
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "BAAI/bge-small-en-v1.5",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 384,
11
+ "id2label": {
12
+ "0": "LABEL_0"
13
+ },
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 1536,
16
+ "label2id": {
17
+ "LABEL_0": 0
18
+ },
19
+ "layer_norm_eps": 1e-12,
20
+ "max_position_embeddings": 512,
21
+ "model_type": "bert",
22
+ "num_attention_heads": 12,
23
+ "num_hidden_layers": 12,
24
+ "pad_token_id": 0,
25
+ "position_embedding_type": "absolute",
26
+ "torch_dtype": "float32",
27
+ "transformers_version": "4.38.1",
28
+ "type_vocab_size": 2,
29
+ "use_cache": true,
30
+ "vocab_size": 30522
31
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.28.1",
5
+ "pytorch": "1.13.0+cu117"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null
9
+ }
config_setfit.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "labels": [
3
+ "negative",
4
+ "neutral",
5
+ "positive"
6
+ ],
7
+ "normalize_embeddings": false
8
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:11dab720450d4492ff84ed3baa65fa60b66e8bb0a83348fcc02244a798bf2dda
3
+ size 133462128
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8595235eb279767ad54f331847212692ff3d3553ed44fbe7c3f001bd2eb53bb
3
+ size 10159
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
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": true
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 512,
50
+ "never_split": null,
51
+ "pad_token": "[PAD]",
52
+ "sep_token": "[SEP]",
53
+ "strip_accents": null,
54
+ "tokenize_chinese_chars": true,
55
+ "tokenizer_class": "BertTokenizer",
56
+ "unk_token": "[UNK]"
57
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff