mrzaizai2k commited on
Commit
5c11fac
·
verified ·
1 Parent(s): 026c0c8

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": 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,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: sentence-transformers/all-MiniLM-L6-v2
3
+ library_name: setfit
4
+ metrics:
5
+ - accuracy
6
+ pipeline_tag: text-classification
7
+ tags:
8
+ - setfit
9
+ - sentence-transformers
10
+ - text-classification
11
+ - generated_from_setfit_trainer
12
+ widget:
13
+ - text: Write a Python function that checks if a given number is prime.
14
+ - text: 'Phát biểu nào sau đây đúng đối với hai ma trận vuông A, B?
15
+
16
+ A. Nếu A chéo hóa được và B thu được từ A bằng các phép biến đổi sơ cấp trên dòng
17
+
18
+ (B tương đương dòng với A) thì B cũng chéo hóa được.
19
+
20
+ B. Nếu A và B chéo hóa được thì tích AB cũng chéo hóa được.
21
+
22
+ C. Nếu A có kích thước 3 × 3 là ma trận của phép chiếu trực giao các vectơ trong
23
+ R
24
+
25
+ 3
26
+
27
+ lên mặt phẳng x + y + z = 0 thì A chéo hóa được.
28
+
29
+ D. Ma trận A kích thước 3 × 3 có thể có giá trị riêng phức không thực với số bội
30
+ là 2.'
31
+ - text: Phần mềm kiểm thử là gì?
32
+ - text: What is software testing?
33
+ - text: 'Cho V là một không gian vecto của đa thức biến t có bậc cao nhất là 2 trên
34
+ R . Tích trong (inner product)
35
+
36
+ trên V được định nghĩa như sau ⟨f, g⟩=
37
+
38
+ R 1
39
+
40
+ 0
41
+
42
+ f(t)g(t)dt, ∀f, g ∈ V . Cho W = {1 − t
43
+
44
+ 2
45
+
46
+ , 1 + t
47
+
48
+ 2} và W⊥ là phần
49
+
50
+ bù trực giao của W trong V . Lấy h ∈ W⊥, khẳng định nào sau đây là luôn đúng về
51
+ h?
52
+
53
+ A. h(t) là hàm chẵn (h(t) = h(−t)) B. h(t) là hàm lẻ (h(t) = −h(−t))
54
+
55
+ C. h(0) = 0 D. h(t)=0 có nghiệm thực.
56
+
57
+ Giải thích vì sao'
58
+ inference: true
59
+ model-index:
60
+ - name: SetFit with sentence-transformers/all-MiniLM-L6-v2
61
+ results:
62
+ - task:
63
+ type: text-classification
64
+ name: Text Classification
65
+ dataset:
66
+ name: Unknown
67
+ type: unknown
68
+ split: test
69
+ metrics:
70
+ - type: accuracy
71
+ value: 0.8333333333333334
72
+ name: Accuracy
73
+ ---
74
+
75
+ # SetFit with sentence-transformers/all-MiniLM-L6-v2
76
+
77
+ This is a [SetFit](https://github.com/huggingface/setfit) model 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.
78
+
79
+ The model has been trained using an efficient few-shot learning technique that involves:
80
+
81
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
82
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
83
+
84
+ ## Model Details
85
+
86
+ ### Model Description
87
+ - **Model Type:** SetFit
88
+ - **Sentence Transformer body:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
89
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
90
+ - **Maximum Sequence Length:** 256 tokens
91
+ - **Number of Classes:** 2 classes
92
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
93
+ <!-- - **Language:** Unknown -->
94
+ <!-- - **License:** Unknown -->
95
+
96
+ ### Model Sources
97
+
98
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
99
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
100
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
101
+
102
+ ### Model Labels
103
+ | Label | Examples |
104
+ |:------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
105
+ | 0 | <ul><li>'what is the primarily goal of microservice architecture'</li><li>'Briefly describe the concept of photosynthesis.'</li><li>'The p success of karger min cut after k steps'</li></ul> |
106
+ | 1 | <ul><li>'What is White-box testing?\nCâu hỏi 7Trả lời\n\na.\nAll of the other answers.\n\nb.\nA testing technique in which internal structure, design and coding of software are tested.\n\nc.\nIts foundation is to execute every part of the code at least once.\n\nd.\nIn this technique, code is visible to testers.'</li><li>'Xác suất để trúng giải thưởng khi bạn mua một tờ vé số là 0.05%. Giả sử mỗi ngày bạn mua 1 tờ vé số, vậy\nchúng ta cần bao nhiêu ngày (trung bình) để có 98% cơ hội trúng?'</li><li>'Explain the difference between supervised and unsupervised learning algorithms. Provide an example of each. (min. 150 words)'</li></ul> |
107
+
108
+ ## Evaluation
109
+
110
+ ### Metrics
111
+ | Label | Accuracy |
112
+ |:--------|:---------|
113
+ | **all** | 0.8333 |
114
+
115
+ ## Uses
116
+
117
+ ### Direct Use for Inference
118
+
119
+ First install the SetFit library:
120
+
121
+ ```bash
122
+ pip install setfit
123
+ ```
124
+
125
+ Then you can load this model and run inference.
126
+
127
+ ```python
128
+ from setfit import SetFitModel
129
+
130
+ # Download from the 🤗 Hub
131
+ model = SetFitModel.from_pretrained("mrzaizai2k/model_routing_voice")
132
+ # Run inference
133
+ preds = model("Phần mềm kiểm thử là gì?")
134
+ ```
135
+
136
+ <!--
137
+ ### Downstream Use
138
+
139
+ *List how someone could finetune this model on their own dataset.*
140
+ -->
141
+
142
+ <!--
143
+ ### Out-of-Scope Use
144
+
145
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
146
+ -->
147
+
148
+ <!--
149
+ ## Bias, Risks and Limitations
150
+
151
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
152
+ -->
153
+
154
+ <!--
155
+ ### Recommendations
156
+
157
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
158
+ -->
159
+
160
+ ## Training Details
161
+
162
+ ### Training Set Metrics
163
+ | Training set | Min | Median | Max |
164
+ |:-------------|:----|:--------|:----|
165
+ | Word count | 4 | 16.4194 | 63 |
166
+
167
+ | Label | Training Sample Count |
168
+ |:------|:----------------------|
169
+ | 0 | 16 |
170
+ | 1 | 15 |
171
+
172
+ ### Training Hyperparameters
173
+ - batch_size: (4, 4)
174
+ - num_epochs: (4, 4)
175
+ - max_steps: -1
176
+ - sampling_strategy: oversampling
177
+ - body_learning_rate: (2e-05, 1e-05)
178
+ - head_learning_rate: 0.01
179
+ - loss: CosineSimilarityLoss
180
+ - distance_metric: cosine_distance
181
+ - margin: 0.25
182
+ - end_to_end: False
183
+ - use_amp: False
184
+ - warmup_proportion: 0.1
185
+ - seed: 42
186
+ - eval_max_steps: -1
187
+ - load_best_model_at_end: True
188
+
189
+ ### Training Results
190
+ | Epoch | Step | Training Loss | Validation Loss |
191
+ |:-------:|:-------:|:-------------:|:---------------:|
192
+ | 0.0078 | 1 | 0.4337 | - |
193
+ | 0.3906 | 50 | 0.2656 | - |
194
+ | 0.7812 | 100 | 0.2212 | - |
195
+ | 1.0 | 128 | - | 0.1281 |
196
+ | 1.1719 | 150 | 0.0343 | - |
197
+ | 1.5625 | 200 | 0.0022 | - |
198
+ | 1.9531 | 250 | 0.004 | - |
199
+ | 2.0 | 256 | - | 0.056 |
200
+ | 2.3438 | 300 | 0.0022 | - |
201
+ | 2.7344 | 350 | 0.0016 | - |
202
+ | 3.0 | 384 | - | 0.0519 |
203
+ | 3.125 | 400 | 0.0014 | - |
204
+ | 3.5156 | 450 | 0.0014 | - |
205
+ | 3.9062 | 500 | 0.002 | - |
206
+ | **4.0** | **512** | **-** | **0.0495** |
207
+
208
+ * The bold row denotes the saved checkpoint.
209
+ ### Framework Versions
210
+ - Python: 3.10.19
211
+ - SetFit: 1.0.3
212
+ - Sentence Transformers: 5.2.3
213
+ - Transformers: 4.41.2
214
+ - PyTorch: 2.10.0+cu128
215
+ - Datasets: 2.19.0
216
+ - Tokenizers: 0.19.1
217
+
218
+ ## Citation
219
+
220
+ ### BibTeX
221
+ ```bibtex
222
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
223
+ doi = {10.48550/ARXIV.2209.11055},
224
+ url = {https://arxiv.org/abs/2209.11055},
225
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
226
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
227
+ title = {Efficient Few-Shot Learning Without Prompts},
228
+ publisher = {arXiv},
229
+ year = {2022},
230
+ copyright = {Creative Commons Attribution 4.0 International}
231
+ }
232
+ ```
233
+
234
+ <!--
235
+ ## Glossary
236
+
237
+ *Clearly define terms in order to be accessible across audiences.*
238
+ -->
239
+
240
+ <!--
241
+ ## Model Card Authors
242
+
243
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
244
+ -->
245
+
246
+ <!--
247
+ ## Model Card Contact
248
+
249
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
250
+ -->
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "checkpoints/step_512",
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.41.2",
23
+ "type_vocab_size": 2,
24
+ "use_cache": true,
25
+ "vocab_size": 30522
26
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "5.2.3",
4
+ "transformers": "4.41.2",
5
+ "pytorch": "2.10.0+cu128"
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,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "labels": [
3
+ 0,
4
+ 1
5
+ ],
6
+ "normalize_embeddings": false
7
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5fba2f1b1dc47453ad43c04d1fbaf5439d0637b752a1398ebe03f299726fe801
3
+ size 90864192
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0e340ca8689a5e181272036b71f38a7bee6fd81b1975a53e7ef32f70aeca5e6
3
+ size 3935
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": 256,
3
+ "do_lower_case": false
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,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "max_length": 128,
50
+ "model_max_length": 256,
51
+ "never_split": null,
52
+ "pad_to_multiple_of": null,
53
+ "pad_token": "[PAD]",
54
+ "pad_token_type_id": 0,
55
+ "padding_side": "right",
56
+ "sep_token": "[SEP]",
57
+ "stride": 0,
58
+ "strip_accents": null,
59
+ "tokenize_chinese_chars": true,
60
+ "tokenizer_class": "BertTokenizer",
61
+ "truncation_side": "right",
62
+ "truncation_strategy": "longest_first",
63
+ "unk_token": "[UNK]"
64
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff