ronalhung commited on
Commit
7fb9978
·
verified ·
1 Parent(s): de2143a

Add SetFit ABSA 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,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - setfit
4
+ - absa
5
+ - sentence-transformers
6
+ - text-classification
7
+ - generated_from_setfit_trainer
8
+ widget:
9
+ - text: food:The food was bland oily.
10
+ - text: 'soups:An oasis of refinement: Food, though somewhat uneven, often reaches
11
+ the pinnacles of new American fine cuisine - chef''s passion (and kitchen''s precise
12
+ execution) is most evident in the fish dishes and soups.'
13
+ - text: lobster sandwich:We had the lobster sandwich and it was FANTASTIC.
14
+ - text: sommlier:I understand the area and folks you need not come here for the romantic,
15
+ alluring ambiance or the five star service featuring a sommlier and a complicated
16
+ maze of captain and back waiters - you come for the authentic foods, the tastes,
17
+ the experiance.
18
+ - text: food:Not impressed with the food.
19
+ metrics:
20
+ - accuracy
21
+ pipeline_tag: text-classification
22
+ library_name: setfit
23
+ inference: false
24
+ base_model: sentence-transformers/all-MiniLM-L6-v2
25
+ model-index:
26
+ - name: SetFit Aspect Model with sentence-transformers/all-MiniLM-L6-v2
27
+ results:
28
+ - task:
29
+ type: text-classification
30
+ name: Text Classification
31
+ dataset:
32
+ name: Unknown
33
+ type: unknown
34
+ split: test
35
+ metrics:
36
+ - type: accuracy
37
+ value: 0.8377192982456141
38
+ name: Accuracy
39
+ ---
40
+
41
+ # SetFit Aspect Model with sentence-transformers/all-MiniLM-L6-v2
42
+
43
+ This is a [SetFit](https://github.com/huggingface/setfit) model that can be used for Aspect Based Sentiment Analysis (ABSA). 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. In particular, this model is in charge of filtering aspect span candidates.
44
+
45
+ The model has been trained using an efficient few-shot learning technique that involves:
46
+
47
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
48
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
49
+
50
+ This model was trained within the context of a larger system for ABSA, which looks like so:
51
+
52
+ 1. Use a spaCy model to select possible aspect span candidates.
53
+ 2. **Use this SetFit model to filter these possible aspect span candidates.**
54
+ 3. Use a SetFit model to classify the filtered aspect span candidates.
55
+
56
+ ## Model Details
57
+
58
+ ### Model Description
59
+ - **Model Type:** SetFit
60
+ - **Sentence Transformer body:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
61
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
62
+ - **spaCy Model:** en_core_web_sm
63
+ - **SetFitABSA Aspect Model:** [ronalhung/setfit-absa-restaurants-polarity](https://huggingface.co/ronalhung/setfit-absa-restaurants-polarity)
64
+ - **SetFitABSA Polarity Model:** [setfit-absa-polarity](https://huggingface.co/setfit-absa-polarity)
65
+ - **Maximum Sequence Length:** 256 tokens
66
+ - **Number of Classes:** 2 classes
67
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
68
+ <!-- - **Language:** Unknown -->
69
+ <!-- - **License:** Unknown -->
70
+
71
+ ### Model Sources
72
+
73
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
74
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
75
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
76
+
77
+ ### Model Labels
78
+ | Label | Examples |
79
+ |:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
80
+ | aspect | <ul><li>'staff:But the staff was so horrible to us.'</li><li>"food:To be completely fair, the only redeeming factor was the food, which was above average, but couldn't make up for all the other deficiencies of Teodora."</li><li>"food:The food is uniformly exceptional, with a very capable kitchen which will proudly whip up whatever you feel like eating, whether it's on the menu or not."</li></ul> |
81
+ | no aspect | <ul><li>"factor:To be completely fair, the only redeeming factor was the food, which was above average, but couldn't make up for all the other deficiencies of Teodora."</li><li>"deficiencies:To be completely fair, the only redeeming factor was the food, which was above average, but couldn't make up for all the other deficiencies of Teodora."</li><li>"Teodora:To be completely fair, the only redeeming factor was the food, which was above average, but couldn't make up for all the other deficiencies of Teodora."</li></ul> |
82
+
83
+ ## Evaluation
84
+
85
+ ### Metrics
86
+ | Label | Accuracy |
87
+ |:--------|:---------|
88
+ | **all** | 0.8377 |
89
+
90
+ ## Uses
91
+
92
+ ### Direct Use for Inference
93
+
94
+ First install the SetFit library:
95
+
96
+ ```bash
97
+ pip install setfit
98
+ ```
99
+
100
+ Then you can load this model and run inference.
101
+
102
+ ```python
103
+ from setfit import AbsaModel
104
+
105
+ # Download from the 🤗 Hub
106
+ model = AbsaModel.from_pretrained(
107
+ "ronalhung/setfit-absa-restaurants-polarity",
108
+ "setfit-absa-polarity",
109
+ )
110
+ # Run inference
111
+ preds = model("The food was great, but the venue is just way too busy.")
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 | 4 | 18.0 | 37 |
144
+
145
+ | Label | Training Sample Count |
146
+ |:----------|:----------------------|
147
+ | no aspect | 73 |
148
+ | aspect | 128 |
149
+
150
+ ### Training Hyperparameters
151
+ - batch_size: (128, 128)
152
+ - num_epochs: (5, 5)
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: True
162
+ - warmup_proportion: 0.1
163
+ - l2_weight: 0.01
164
+ - seed: 42
165
+ - eval_max_steps: -1
166
+ - load_best_model_at_end: True
167
+
168
+ ### Training Results
169
+ | Epoch | Step | Training Loss | Validation Loss |
170
+ |:------:|:----:|:-------------:|:---------------:|
171
+ | 0.0058 | 1 | 0.2702 | - |
172
+ | 0.2907 | 50 | 0.2764 | 0.2555 |
173
+ | 0.5814 | 100 | 0.1827 | 0.2240 |
174
+ | 0.8721 | 150 | 0.0239 | 0.2296 |
175
+ | 1.1628 | 200 | 0.0027 | 0.2436 |
176
+ | 1.4535 | 250 | 0.0015 | 0.2421 |
177
+ | 1.7442 | 300 | 0.001 | 0.2411 |
178
+ | 2.0349 | 350 | 0.0007 | 0.2431 |
179
+ | 2.3256 | 400 | 0.0005 | 0.2391 |
180
+ | 2.6163 | 450 | 0.0004 | 0.2470 |
181
+ | 2.9070 | 500 | 0.0004 | 0.2381 |
182
+ | 3.1977 | 550 | 0.0003 | 0.2465 |
183
+ | 3.4884 | 600 | 0.0003 | 0.2452 |
184
+ | 3.7791 | 650 | 0.0003 | 0.2478 |
185
+ | 4.0698 | 700 | 0.0003 | 0.2416 |
186
+ | 4.3605 | 750 | 0.0003 | 0.2453 |
187
+ | 4.6512 | 800 | 0.0002 | 0.2433 |
188
+ | 4.9419 | 850 | 0.0003 | 0.2447 |
189
+
190
+ ### Framework Versions
191
+ - Python: 3.11.12
192
+ - SetFit: 1.1.2
193
+ - Sentence Transformers: 3.4.1
194
+ - spaCy: 3.8.5
195
+ - Transformers: 4.51.1
196
+ - PyTorch: 2.6.0+cu124
197
+ - Datasets: 3.5.0
198
+ - Tokenizers: 0.21.1
199
+
200
+ ## Citation
201
+
202
+ ### BibTeX
203
+ ```bibtex
204
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
205
+ doi = {10.48550/ARXIV.2209.11055},
206
+ url = {https://arxiv.org/abs/2209.11055},
207
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
208
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
209
+ title = {Efficient Few-Shot Learning Without Prompts},
210
+ publisher = {arXiv},
211
+ year = {2022},
212
+ copyright = {Creative Commons Attribution 4.0 International}
213
+ }
214
+ ```
215
+
216
+ <!--
217
+ ## Glossary
218
+
219
+ *Clearly define terms in order to be accessible across audiences.*
220
+ -->
221
+
222
+ <!--
223
+ ## Model Card Authors
224
+
225
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
226
+ -->
227
+
228
+ <!--
229
+ ## Model Card Contact
230
+
231
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
232
+ -->
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 384,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 1536,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 6,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.51.1",
22
+ "type_vocab_size": 2,
23
+ "use_cache": true,
24
+ "vocab_size": 30522
25
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "3.4.1",
4
+ "transformers": "4.51.1",
5
+ "pytorch": "2.6.0+cu124"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null,
9
+ "similarity_fn_name": "cosine"
10
+ }
config_setfit.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "spacy_model": "en_core_web_sm",
3
+ "normalize_embeddings": false,
4
+ "labels": [
5
+ "no aspect",
6
+ "aspect"
7
+ ],
8
+ "span_context": 0
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:17490e38d9e2926c3362476b470910c1e2187761472f5c384bf061e009308454
3
+ size 90864192
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ebbda54c87e2fc24dad2b6036b5b0d12101285f1d5a2b3a2006b17eca921c5c
3
+ size 3919
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,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": false,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "max_length": 128,
51
+ "model_max_length": 256,
52
+ "never_split": null,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "[PAD]",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "[SEP]",
58
+ "stride": 0,
59
+ "strip_accents": null,
60
+ "tokenize_chinese_chars": true,
61
+ "tokenizer_class": "BertTokenizer",
62
+ "truncation_side": "right",
63
+ "truncation_strategy": "longest_first",
64
+ "unk_token": "[UNK]"
65
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff