ronalhung commited on
Commit
edc7785
·
verified ·
1 Parent(s): b8880a8

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,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - setfit
4
+ - absa
5
+ - sentence-transformers
6
+ - text-classification
7
+ - generated_from_setfit_trainer
8
+ widget:
9
+ - text: bench:Get your food to go, find a bench, and kick back with a plate of dumplings.
10
+ - text: comparison:Frankly, when you compare what you can have here for lunch, versus
11
+ McDs or so many other sandwich shops in the city, there is no comparison.
12
+ - text: ton:We had crawfish boiled and despite making a mess, it was a ton of fun
13
+ and quite tasty as well.
14
+ - text: traffic noise:It is set far from the small street it's on, and there is no
15
+ traffic noise.
16
+ - text: food:The only thing more wonderful than the food (which is exceptional) is
17
+ the service.
18
+ metrics:
19
+ - f1_micro
20
+ - f1_macro
21
+ - precision_macro
22
+ - recall_macro
23
+ pipeline_tag: text-classification
24
+ library_name: setfit
25
+ inference: false
26
+ base_model: sentence-transformers/all-MiniLM-L6-v2
27
+ model-index:
28
+ - name: SetFit Aspect Model with sentence-transformers/all-MiniLM-L6-v2
29
+ results:
30
+ - task:
31
+ type: text-classification
32
+ name: Text Classification
33
+ dataset:
34
+ name: Unknown
35
+ type: unknown
36
+ split: test
37
+ metrics:
38
+ - type: f1_micro
39
+ value: 0.8346328195829555
40
+ name: F1_Micro
41
+ - type: f1_macro
42
+ value: 0.8211736476667757
43
+ name: F1_Macro
44
+ - type: precision_macro
45
+ value: 0.8421651129179422
46
+ name: Precision_Macro
47
+ - type: recall_macro
48
+ value: 0.8121263510071948
49
+ name: Recall_Macro
50
+ ---
51
+
52
+ # SetFit Aspect Model with sentence-transformers/all-MiniLM-L6-v2
53
+
54
+ 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.
55
+
56
+ The model has been trained using an efficient few-shot learning technique that involves:
57
+
58
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
59
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
60
+
61
+ This model was trained within the context of a larger system for ABSA, which looks like so:
62
+
63
+ 1. Use a spaCy model to select possible aspect span candidates.
64
+ 2. **Use this SetFit model to filter these possible aspect span candidates.**
65
+ 3. Use a SetFit model to classify the filtered aspect span candidates.
66
+
67
+ ## Model Details
68
+
69
+ ### Model Description
70
+ - **Model Type:** SetFit
71
+ - **Sentence Transformer body:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
72
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
73
+ - **spaCy Model:** en_core_web_lg
74
+ - **SetFitABSA Aspect Model:** [ronalhung/setfit-absa-restaurants-aspect-128](https://huggingface.co/ronalhung/setfit-absa-restaurants-aspect-128)
75
+ - **SetFitABSA Polarity Model:** [setfit-absa-polarity](https://huggingface.co/setfit-absa-polarity)
76
+ - **Maximum Sequence Length:** 256 tokens
77
+ - **Number of Classes:** 2 classes
78
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
79
+ <!-- - **Language:** Unknown -->
80
+ <!-- - **License:** Unknown -->
81
+
82
+ ### Model Sources
83
+
84
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
85
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
86
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
87
+
88
+ ### Model Labels
89
+ | Label | Examples |
90
+ |:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
91
+ | 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> |
92
+ | 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> |
93
+
94
+ ## Evaluation
95
+
96
+ ### Metrics
97
+ | Label | F1_Micro | F1_Macro | Precision_Macro | Recall_Macro |
98
+ |:--------|:---------|:---------|:----------------|:-------------|
99
+ | **all** | 0.8346 | 0.8212 | 0.8422 | 0.8121 |
100
+
101
+ ## Uses
102
+
103
+ ### Direct Use for Inference
104
+
105
+ First install the SetFit library:
106
+
107
+ ```bash
108
+ pip install setfit
109
+ ```
110
+
111
+ Then you can load this model and run inference.
112
+
113
+ ```python
114
+ from setfit import AbsaModel
115
+
116
+ # Download from the 🤗 Hub
117
+ model = AbsaModel.from_pretrained(
118
+ "ronalhung/setfit-absa-restaurants-aspect-128",
119
+ "setfit-absa-polarity",
120
+ )
121
+ # Run inference
122
+ preds = model("The food was great, but the venue is just way too busy.")
123
+ ```
124
+
125
+ <!--
126
+ ### Downstream Use
127
+
128
+ *List how someone could finetune this model on their own dataset.*
129
+ -->
130
+
131
+ <!--
132
+ ### Out-of-Scope Use
133
+
134
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
135
+ -->
136
+
137
+ <!--
138
+ ## Bias, Risks and Limitations
139
+
140
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
141
+ -->
142
+
143
+ <!--
144
+ ### Recommendations
145
+
146
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
147
+ -->
148
+
149
+ ## Training Details
150
+
151
+ ### Training Set Metrics
152
+ | Training set | Min | Median | Max |
153
+ |:-------------|:----|:--------|:----|
154
+ | Word count | 4 | 17.9296 | 37 |
155
+
156
+ | Label | Training Sample Count |
157
+ |:----------|:----------------------|
158
+ | no aspect | 71 |
159
+ | aspect | 128 |
160
+
161
+ ### Training Hyperparameters
162
+ - batch_size: (64, 64)
163
+ - num_epochs: (5, 5)
164
+ - max_steps: -1
165
+ - sampling_strategy: oversampling
166
+ - body_learning_rate: (2e-05, 1e-05)
167
+ - head_learning_rate: 0.01
168
+ - loss: CosineSimilarityLoss
169
+ - distance_metric: cosine_distance
170
+ - margin: 0.25
171
+ - end_to_end: False
172
+ - use_amp: False
173
+ - warmup_proportion: 0.1
174
+ - l2_weight: 0.01
175
+ - seed: 42
176
+ - eval_max_steps: -1
177
+ - load_best_model_at_end: True
178
+
179
+ ### Training Results
180
+ | Epoch | Step | Training Loss | Validation Loss |
181
+ |:------:|:----:|:-------------:|:---------------:|
182
+ | 0.0030 | 1 | 0.398 | - |
183
+ | 0.1479 | 50 | 0.2831 | 0.2599 |
184
+ | 0.2959 | 100 | 0.2339 | 0.2351 |
185
+ | 0.4438 | 150 | 0.1518 | 0.2007 |
186
+ | 0.5917 | 200 | 0.0194 | 0.1999 |
187
+ | 0.7396 | 250 | 0.0033 | 0.2006 |
188
+ | 0.8876 | 300 | 0.002 | 0.2019 |
189
+ | 1.0355 | 350 | 0.0011 | 0.2098 |
190
+ | 1.1834 | 400 | 0.0008 | 0.2039 |
191
+ | 1.3314 | 450 | 0.0008 | 0.2109 |
192
+
193
+ ### Framework Versions
194
+ - Python: 3.11.13
195
+ - SetFit: 1.1.2
196
+ - Sentence Transformers: 4.1.0
197
+ - spaCy: 3.8.7
198
+ - Transformers: 4.52.4
199
+ - PyTorch: 2.6.0+cu124
200
+ - Datasets: 3.6.0
201
+ - Tokenizers: 0.21.1
202
+
203
+ ## Citation
204
+
205
+ ### BibTeX
206
+ ```bibtex
207
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
208
+ doi = {10.48550/ARXIV.2209.11055},
209
+ url = {https://arxiv.org/abs/2209.11055},
210
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
211
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
212
+ title = {Efficient Few-Shot Learning Without Prompts},
213
+ publisher = {arXiv},
214
+ year = {2022},
215
+ copyright = {Creative Commons Attribution 4.0 International}
216
+ }
217
+ ```
218
+
219
+ <!--
220
+ ## Glossary
221
+
222
+ *Clearly define terms in order to be accessible across audiences.*
223
+ -->
224
+
225
+ <!--
226
+ ## Model Card Authors
227
+
228
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
229
+ -->
230
+
231
+ <!--
232
+ ## Model Card Contact
233
+
234
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
235
+ -->
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.52.4",
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": "4.1.0",
4
+ "transformers": "4.52.4",
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
+ "normalize_embeddings": false,
3
+ "labels": [
4
+ "no aspect",
5
+ "aspect"
6
+ ],
7
+ "span_context": 0,
8
+ "spacy_model": "en_core_web_lg"
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:918d2ce5025d2b6458e420b64424684fbfa9ee5d190221d612d57f18fae888c4
3
+ size 90864192
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72ba96244444cdb2bdd7fdd8baca4243acd49fa80ce107814aa8549bfd238609
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