kenhktsui commited on
Commit
74d4d74
·
verified ·
1 Parent(s): 95ab668

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,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: sentence-transformers/paraphrase-mpnet-base-v2
3
+ datasets:
4
+ - fancyzhx/ag_news
5
+ library_name: setfit
6
+ metrics:
7
+ - accuracy
8
+ pipeline_tag: text-classification
9
+ tags:
10
+ - setfit
11
+ - sentence-transformers
12
+ - text-classification
13
+ - generated_from_setfit_trainer
14
+ widget:
15
+ - text: Google gets a bounce, ends its first day up 18 percent Shares of Google leaped
16
+ \$15.34, or 18 percent, to \$100.34 on the Nasdaq exchange yesterday in an opening
17
+ day of trading that harkened back to the wild run-ups of the dot-com era.
18
+ - text: Jobs Data Hold Promise of Stronger Growth (AP) AP - Employers stepped up hiring
19
+ in August, expanding payrolls by 144,000 and lowering the unemployment rate marginally
20
+ to 5.4 percent. While the figures didn't amount to a national job fair, analysts
21
+ said, they did hold out the promise of stronger growth following the summer lull.
22
+ - text: Canadians in Southeast Asia at risk from terrorist groups, report cautions
23
+ (Canadian Press) Canadian Press - OTTAWA (CP) - Islamic extremists with links
24
+ to Osama bin Laden's al-Qaida network pose a threat to Canadians living in Southeast
25
+ Asia, warns a newly obtained intelligence report.
26
+ - text: 'Cricket telecast: Opportunity for lost bidders EVEN as Zee Telefilms chalks
27
+ out its strategy for the cricket rights, legal experts are of the opinion that
28
+ the Bombay High Court #39;s suggestion for a fresh round of bidding could open
29
+ options for the other broadcasters who had lost out in the first round.'
30
+ - text: UN Security Council to Witness Sudan Peace Pledge NAIROBI (Reuters) - The
31
+ Sudanese government and its southern rebel opponents have agreed to sign a pledge
32
+ in the Kenyan capital on Friday to formally end a brutal 21-year-old civil war,
33
+ with U.N. Security Council ambassadors as witnesses.
34
+ inference: true
35
+ model-index:
36
+ - name: SetFit with sentence-transformers/paraphrase-mpnet-base-v2
37
+ results:
38
+ - task:
39
+ type: text-classification
40
+ name: Text Classification
41
+ dataset:
42
+ name: fancyzhx/ag_news
43
+ type: fancyzhx/ag_news
44
+ split: test
45
+ metrics:
46
+ - type: accuracy
47
+ value: 0.7647368421052632
48
+ name: Accuracy
49
+ ---
50
+
51
+ # SetFit with sentence-transformers/paraphrase-mpnet-base-v2
52
+
53
+ This is a [SetFit](https://github.com/huggingface/setfit) model trained on the [fancyzhx/ag_news](https://huggingface.co/datasets/fancyzhx/ag_news) dataset 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:** 4 classes
68
+ - **Training Dataset:** [fancyzhx/ag_news](https://huggingface.co/datasets/fancyzhx/ag_news)
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
+ | Sci/Tech | <ul><li>'MIT Selects Its First Female President (Reuters) Reuters - The Massachusetts Institute of\\Technology on Thursday named Susan Hockfield as its first\\female president, a breakthrough for the world-renowned school\\that has churned out more than 50 Nobel prizewinners but which\\ranks below the national average for its percentage of female\\students.'</li><li>"New PC Is Created Just for Teenagers (AP) AP - This isn't your typical, humdrum, slate-colored computer. Not only is the PC known as the hip-e almost all white, but its screen and keyboard are framed in fuzzy pink fur. Or a leopard skin design. Or a graffiti-themed pattern."</li><li>'Cdn X Prize team postpones launch KINDERSLEY, Sask. (CP) -- A Canadian team of engineers competing in an international race to put civilians into space has postponed its first stab at the \\$10-million prize.'</li></ul> |
82
+ | Business | <ul><li>'Cold sends oil price above \\$44 Oil futures prices have jumped 5 percent higher, climbing above \\$44 a barrel in the United States Wednesday after US government data showed a slight decline in crude and heating oil supplies as colder weather in the Northeast drove up '</li><li>"2 Cable Giants Set To Bid for Adelphia Comcast Corp. and Time Warner Inc. are planning a joint bid for Adelphia Communications Corp. as part of a deal that could lead to a broad realignment of interests in the cable industry and increase Comcast's already dominant presence in the mid-Atlantic region."</li><li>'Piper Rudnick to Merge With Big British Firm Piper Rudnick Gray Cary LLP, a law firm with major operations in Washington, agreed over the weekend to merge with British firm DLA LLP, creating one of the largest combinations ever of law firms from different countries.'</li></ul> |
83
+ | World | <ul><li>'50 Hurt During Opposition Strike in Bangladesh Capital In Bangladesh, at least 50 people have been injured in clashes with authorities during a general strike called by the main opposition party.'</li><li>"No Time Frame for Yuan Move -China WASHINGTON (Reuters) - There is no time frame for a shift away from Beijing's tight currency peg and the United States is mistaken if it thinks it will reap big benefits from a move, a top Chinese central bank official said on Sunday."</li><li>'American Forces Bomb Site in Fallujah (AP) AP - American forces bombed a site in the insurgent stronghold of Fallujah early Tuesday where several militants loyal to terror mastermind Abu Musab al-Zarqawi were believed to be holed up, the U.S. military said.'</li></ul> |
84
+ | Sports | <ul><li>'Blue Jays activate Halladay from DL Bronx, NY (Sports Network) - The Toronto Blue Jays activated pitcher Roy Halladay from the 15-day disabled list and he is expected to start Tuesday #39;s game against the New York Yankees.'</li><li>'Trinidad climbs off canvas to keep title options open Felix Trinidad returned to the ring after more than two years to score a thrilling eighth-round stoppage of Ricardo Mayorga at New York #39;s Madison Square Garden in a non- title bout being described as one of the fights of the year.'</li><li>'Broncos #39; rout frustrates Saints owner NEW ORLEANS -- Another blowout loss left New Orleans owner Tom Benson furious and wondering whether his team belonged in the NFL. Reuben Droughns rushed for 166 yards and a touchdown, Jake Plummer threw for '</li></ul> |
85
+
86
+ ## Evaluation
87
+
88
+ ### Metrics
89
+ | Label | Accuracy |
90
+ |:--------|:---------|
91
+ | **all** | 0.7647 |
92
+
93
+ ## Uses
94
+
95
+ ### Direct Use for Inference
96
+
97
+ First install the SetFit library:
98
+
99
+ ```bash
100
+ pip install setfit
101
+ ```
102
+
103
+ Then you can load this model and run inference.
104
+
105
+ ```python
106
+ from setfit import SetFitModel
107
+
108
+ # Download from the 🤗 Hub
109
+ model = SetFitModel.from_pretrained("setfit_model_id")
110
+ # Run inference
111
+ preds = model("Google gets a bounce, ends its first day up 18 percent Shares of Google leaped \$15.34, or 18 percent, to \$100.34 on the Nasdaq exchange yesterday in an opening day of trading that harkened back to the wild run-ups of the dot-com era.")
112
+ ```
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 | 14 | 39.5694 | 62 |
144
+
145
+ | Label | Training Sample Count |
146
+ |:---------|:----------------------|
147
+ | World | 28 |
148
+ | Sports | 16 |
149
+ | Business | 18 |
150
+ | Sci/Tech | 10 |
151
+
152
+ ### Training Hyperparameters
153
+ - batch_size: (16, 16)
154
+ - num_epochs: (5, 5)
155
+ - max_steps: -1
156
+ - sampling_strategy: oversampling
157
+ - body_learning_rate: (2e-05, 1e-05)
158
+ - head_learning_rate: 0.01
159
+ - loss: CosineSimilarityLoss
160
+ - distance_metric: cosine_distance
161
+ - margin: 0.25
162
+ - end_to_end: False
163
+ - use_amp: False
164
+ - warmup_proportion: 0.1
165
+ - seed: 42
166
+ - eval_max_steps: -1
167
+ - load_best_model_at_end: True
168
+
169
+ ### Training Results
170
+ | Epoch | Step | Training Loss | Validation Loss |
171
+ |:-------:|:-------:|:-------------:|:---------------:|
172
+ | 0.0043 | 1 | 0.4093 | - |
173
+ | 0.2146 | 50 | 0.2095 | - |
174
+ | 0.4292 | 100 | 0.0329 | - |
175
+ | 0.6438 | 150 | 0.0008 | - |
176
+ | 0.8584 | 200 | 0.0002 | - |
177
+ | **1.0** | **233** | **-** | **0.1542** |
178
+ | 1.0730 | 250 | 0.0002 | - |
179
+ | 1.2876 | 300 | 0.0001 | - |
180
+ | 1.5021 | 350 | 0.0002 | - |
181
+ | 1.7167 | 400 | 0.0001 | - |
182
+ | 1.9313 | 450 | 0.0001 | - |
183
+ | 2.0 | 466 | - | 0.1631 |
184
+ | 2.1459 | 500 | 0.0001 | - |
185
+ | 2.3605 | 550 | 0.0001 | - |
186
+ | 2.5751 | 600 | 0.0001 | - |
187
+ | 2.7897 | 650 | 0.0001 | - |
188
+ | 3.0 | 699 | - | 0.1648 |
189
+ | 3.0043 | 700 | 0.0001 | - |
190
+ | 3.2189 | 750 | 0.0001 | - |
191
+ | 3.4335 | 800 | 0.0001 | - |
192
+ | 3.6481 | 850 | 0.0001 | - |
193
+ | 3.8627 | 900 | 0.0001 | - |
194
+ | 4.0 | 932 | - | 0.1663 |
195
+ | 4.0773 | 950 | 0.0001 | - |
196
+ | 4.2918 | 1000 | 0.0 | - |
197
+ | 4.5064 | 1050 | 0.0 | - |
198
+ | 4.7210 | 1100 | 0.0001 | - |
199
+ | 4.9356 | 1150 | 0.0001 | - |
200
+ | 5.0 | 1165 | - | 0.1648 |
201
+
202
+ * The bold row denotes the saved checkpoint.
203
+ ### Framework Versions
204
+ - Python: 3.9.19
205
+ - SetFit: 1.1.0.dev0
206
+ - Sentence Transformers: 3.0.1
207
+ - Transformers: 4.39.0
208
+ - PyTorch: 2.4.0
209
+ - Datasets: 2.20.0
210
+ - Tokenizers: 0.15.2
211
+
212
+ ## Citation
213
+
214
+ ### BibTeX
215
+ ```bibtex
216
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
217
+ doi = {10.48550/ARXIV.2209.11055},
218
+ url = {https://arxiv.org/abs/2209.11055},
219
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
220
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
221
+ title = {Efficient Few-Shot Learning Without Prompts},
222
+ publisher = {arXiv},
223
+ year = {2022},
224
+ copyright = {Creative Commons Attribution 4.0 International}
225
+ }
226
+ ```
227
+
228
+ <!--
229
+ ## Glossary
230
+
231
+ *Clearly define terms in order to be accessible across audiences.*
232
+ -->
233
+
234
+ <!--
235
+ ## Model Card Authors
236
+
237
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
238
+ -->
239
+
240
+ <!--
241
+ ## Model Card Contact
242
+
243
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
244
+ -->
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "setfit/step_233",
3
+ "architectures": [
4
+ "MPNetModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-05,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "mpnet",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 1,
20
+ "relative_attention_num_buckets": 32,
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.39.0",
23
+ "vocab_size": 30527
24
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "3.0.1",
4
+ "transformers": "4.39.0",
5
+ "pytorch": "2.4.0"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null,
9
+ "similarity_fn_name": null
10
+ }
config_setfit.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "normalize_embeddings": false,
3
+ "labels": [
4
+ "World",
5
+ "Sports",
6
+ "Business",
7
+ "Sci/Tech"
8
+ ]
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2430088fe54e808a97a104b33774b3d03c6a0ecb589d7b72f46301ed2896d18
3
+ size 437967672
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a4540c84a16d4f96a0cec8e7b2dad311e61d1c5a53d9b3951c3c55a37f00c9c
3
+ size 25479
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,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": true,
46
+ "cls_token": "<s>",
47
+ "do_basic_tokenize": true,
48
+ "do_lower_case": true,
49
+ "eos_token": "</s>",
50
+ "mask_token": "<mask>",
51
+ "max_length": 512,
52
+ "model_max_length": 512,
53
+ "never_split": null,
54
+ "pad_to_multiple_of": null,
55
+ "pad_token": "<pad>",
56
+ "pad_token_type_id": 0,
57
+ "padding_side": "right",
58
+ "sep_token": "</s>",
59
+ "stride": 0,
60
+ "strip_accents": null,
61
+ "tokenize_chinese_chars": true,
62
+ "tokenizer_class": "MPNetTokenizer",
63
+ "truncation_side": "right",
64
+ "truncation_strategy": "longest_first",
65
+ "unk_token": "[UNK]"
66
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff