wikd commited on
Commit
9a5f2d9
1 Parent(s): d2ea11f

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,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: setfit
3
+ tags:
4
+ - setfit
5
+ - sentence-transformers
6
+ - text-classification
7
+ - generated_from_setfit_trainer
8
+ base_model: distilbert/distilbert-base-uncased-finetuned-sst-2-english
9
+ datasets:
10
+ - wikd/customer_data
11
+ metrics:
12
+ - accuracy
13
+ widget:
14
+ - text: I'm very satisfied with my purchase
15
+ - text: The delivery was very quick!
16
+ - text: The product is out of stock
17
+ - text: The return process was easy
18
+ - text: I changed my mind and want to cancel my order
19
+ pipeline_tag: text-classification
20
+ inference: true
21
+ model-index:
22
+ - name: SetFit with distilbert/distilbert-base-uncased-finetuned-sst-2-english
23
+ results:
24
+ - task:
25
+ type: text-classification
26
+ name: Text Classification
27
+ dataset:
28
+ name: wikd/customer_data
29
+ type: wikd/customer_data
30
+ split: test
31
+ metrics:
32
+ - type: accuracy
33
+ value: 1.0
34
+ name: Accuracy
35
+ ---
36
+
37
+ # SetFit with distilbert/distilbert-base-uncased-finetuned-sst-2-english
38
+
39
+ This is a [SetFit](https://github.com/huggingface/setfit) model trained on the [wikd/customer_data](https://huggingface.co/datasets/wikd/customer_data) dataset that can be used for Text Classification. This SetFit model uses [distilbert/distilbert-base-uncased-finetuned-sst-2-english](https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english) 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.
40
+
41
+ The model has been trained using an efficient few-shot learning technique that involves:
42
+
43
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
44
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
45
+
46
+ ## Model Details
47
+
48
+ ### Model Description
49
+ - **Model Type:** SetFit
50
+ - **Sentence Transformer body:** [distilbert/distilbert-base-uncased-finetuned-sst-2-english](https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english)
51
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
52
+ - **Maximum Sequence Length:** 512 tokens
53
+ - **Number of Classes:** 2 classes
54
+ - **Training Dataset:** [wikd/customer_data](https://huggingface.co/datasets/wikd/customer_data)
55
+ <!-- - **Language:** Unknown -->
56
+ <!-- - **License:** Unknown -->
57
+
58
+ ### Model Sources
59
+
60
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
61
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
62
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
63
+
64
+ ### Model Labels
65
+ | Label | Examples |
66
+ |:------|:----------------------------------------------------------------------------------------------------------------------------------------------------------|
67
+ | 0 | <ul><li>'I received the wrong item'</li><li>'The product arrived damaged'</li><li>"I placed an order but haven't received a confirmation email"</li></ul> |
68
+ | 1 | <ul><li>'I got a discount code!'</li><li>'I would recommend this company to a friend'</li><li>"I'm very satisfied with my purchase"</li></ul> |
69
+
70
+ ## Evaluation
71
+
72
+ ### Metrics
73
+ | Label | Accuracy |
74
+ |:--------|:---------|
75
+ | **all** | 1.0 |
76
+
77
+ ## Uses
78
+
79
+ ### Direct Use for Inference
80
+
81
+ First install the SetFit library:
82
+
83
+ ```bash
84
+ pip install setfit
85
+ ```
86
+
87
+ Then you can load this model and run inference.
88
+
89
+ ```python
90
+ from setfit import SetFitModel
91
+
92
+ # Download from the 🤗 Hub
93
+ model = SetFitModel.from_pretrained("setfit_model_id")
94
+ # Run inference
95
+ preds = model("The product is out of stock")
96
+ ```
97
+
98
+ <!--
99
+ ### Downstream Use
100
+
101
+ *List how someone could finetune this model on their own dataset.*
102
+ -->
103
+
104
+ <!--
105
+ ### Out-of-Scope Use
106
+
107
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
108
+ -->
109
+
110
+ <!--
111
+ ## Bias, Risks and Limitations
112
+
113
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
114
+ -->
115
+
116
+ <!--
117
+ ### Recommendations
118
+
119
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
120
+ -->
121
+
122
+ ## Training Details
123
+
124
+ ### Training Set Metrics
125
+ | Training set | Min | Median | Max |
126
+ |:-------------|:----|:-------|:----|
127
+ | Word count | 4 | 6.9375 | 10 |
128
+
129
+ | Label | Training Sample Count |
130
+ |:------|:----------------------|
131
+ | 0 | 10 |
132
+ | 1 | 6 |
133
+
134
+ ### Training Hyperparameters
135
+ - batch_size: (16, 16)
136
+ - num_epochs: (1, 1)
137
+ - max_steps: -1
138
+ - sampling_strategy: oversampling
139
+ - num_iterations: 20
140
+ - body_learning_rate: (2e-05, 2e-05)
141
+ - head_learning_rate: 2e-05
142
+ - loss: CosineSimilarityLoss
143
+ - distance_metric: cosine_distance
144
+ - margin: 0.25
145
+ - end_to_end: False
146
+ - use_amp: False
147
+ - warmup_proportion: 0.1
148
+ - seed: 42
149
+ - eval_max_steps: -1
150
+ - load_best_model_at_end: False
151
+
152
+ ### Training Results
153
+ | Epoch | Step | Training Loss | Validation Loss |
154
+ |:-----:|:----:|:-------------:|:---------------:|
155
+ | 0.025 | 1 | 0.0549 | - |
156
+
157
+ ### Framework Versions
158
+ - Python: 3.11.8
159
+ - SetFit: 1.0.3
160
+ - Sentence Transformers: 2.5.1
161
+ - Transformers: 4.38.2
162
+ - PyTorch: 2.2.1
163
+ - Datasets: 2.18.0
164
+ - Tokenizers: 0.15.2
165
+
166
+ ## Citation
167
+
168
+ ### BibTeX
169
+ ```bibtex
170
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
171
+ doi = {10.48550/ARXIV.2209.11055},
172
+ url = {https://arxiv.org/abs/2209.11055},
173
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
174
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
175
+ title = {Efficient Few-Shot Learning Without Prompts},
176
+ publisher = {arXiv},
177
+ year = {2022},
178
+ copyright = {Creative Commons Attribution 4.0 International}
179
+ }
180
+ ```
181
+
182
+ <!--
183
+ ## Glossary
184
+
185
+ *Clearly define terms in order to be accessible across audiences.*
186
+ -->
187
+
188
+ <!--
189
+ ## Model Card Authors
190
+
191
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
192
+ -->
193
+
194
+ <!--
195
+ ## Model Card Contact
196
+
197
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
198
+ -->
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation": "gelu",
3
+ "architectures": [
4
+ "DistilBertForSequenceClassification"
5
+ ],
6
+ "attention_dropout": 0.1,
7
+ "dim": 768,
8
+ "dropout": 0.1,
9
+ "finetuning_task": "sst-2",
10
+ "hidden_dim": 3072,
11
+ "id2label": {
12
+ "0": "NEGATIVE",
13
+ "1": "POSITIVE"
14
+ },
15
+ "initializer_range": 0.02,
16
+ "label2id": {
17
+ "NEGATIVE": 0,
18
+ "POSITIVE": 1
19
+ },
20
+ "max_position_embeddings": 512,
21
+ "model_type": "distilbert",
22
+ "n_heads": 12,
23
+ "n_layers": 6,
24
+ "output_past": true,
25
+ "pad_token_id": 0,
26
+ "qa_dropout": 0.1,
27
+ "seq_classif_dropout": 0.2,
28
+ "sinusoidal_pos_embds": false,
29
+ "tie_weights_": true,
30
+ "vocab_size": 30522
31
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.5.1",
4
+ "transformers": "4.38.2",
5
+ "pytorch": "2.2.1"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null
9
+ }
config_setfit.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "normalize_embeddings": false,
3
+ "labels": null
4
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f371e87d5d8ba17bd19ce9e245b362cf1074fe0b544a79ad164520a0d27fea7f
3
+ size 265462608
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0d861bdc121e04180575e968b947df9a4244d3e69030d5a39e058505013e1d5
3
+ size 7013
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,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,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": "DistilBertTokenizer",
56
+ "unk_token": "[UNK]"
57
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff