ronalhung commited on
Commit
832b4c8
·
verified ·
1 Parent(s): b439272

Add SetFit ABSA 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,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - setfit
4
+ - absa
5
+ - sentence-transformers
6
+ - text-classification
7
+ - generated_from_setfit_trainer
8
+ widget:
9
+ - text: even the wine by the glass was good.:even the wine by the glass was good.
10
+ - text: I had the Pad Thai and the noodles:I had the Pad Thai and the noodles were
11
+ sticky.
12
+ - text: happy and the food was delicious,:The have over 100 different beers to offer
13
+ thier guest so that made my husband very happy and the food was delicious, if
14
+ I must recommend a dish it must be the pumkin tortelini.
15
+ - text: The takeout menu says to keep:The takeout menu says to keep an eye out for
16
+ an expanded menu offering more italian dishes, I can't wait!
17
+ - text: fresh garlic or eggplant.:Try their plain pizza with fresh garlic or eggplant.
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-mpnet-base-v2
27
+ model-index:
28
+ - name: SetFit Polarity Model with sentence-transformers/all-mpnet-base-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.7398546335554209
40
+ name: F1_Micro
41
+ - type: f1_macro
42
+ value: 0.47927842814066474
43
+ name: F1_Macro
44
+ - type: precision_macro
45
+ value: 0.49187400153564864
46
+ name: Precision_Macro
47
+ - type: recall_macro
48
+ value: 0.48087480356207435
49
+ name: Recall_Macro
50
+ ---
51
+
52
+ # SetFit Polarity Model with sentence-transformers/all-mpnet-base-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-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-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. In particular, this model is in charge of classifying aspect polarities.
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 a SetFit model to filter these possible aspect span candidates.
65
+ 3. **Use this 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-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-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:** [setfit-absa-aspect](https://huggingface.co/setfit-absa-aspect)
75
+ - **SetFitABSA Polarity Model:** [ronalhung/setfit-absa-restaurants-polarity-128](https://huggingface.co/ronalhung/setfit-absa-restaurants-polarity-128)
76
+ - **Maximum Sequence Length:** 384 tokens
77
+ - **Number of Classes:** 4 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
+ | negative | <ul><li>'But the staff was so horrible:But the staff was so horrible to us.'</li><li>', forgot our toast, left out:They did not have mayonnaise, forgot our toast, left out ingredients (ie cheese in an omelet), below hot temperatures and the bacon was so over cooked it crumbled on the plate when you touched it.'</li><li>'did not have mayonnaise, forgot our:They did not have mayonnaise, forgot our toast, left out ingredients (ie cheese in an omelet), below hot temperatures and the bacon was so over cooked it crumbled on the plate when you touched it.'</li></ul> |
92
+ | positive | <ul><li>"factor was the food, which was: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>"The food is uniformly exceptional: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><li>"a very capable kitchen which will proudly: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> |
93
+ | neutral | <ul><li>"'s on the menu or not.: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><li>'to sample both meats).:Our agreed favorite is the orrechiete with sausage and chicken (usually the waiters are kind enough to split the dish in half so you get to sample both meats).'</li><li>'to split the dish in half so:Our agreed favorite is the orrechiete with sausage and chicken (usually the waiters are kind enough to split the dish in half so you get to sample both meats).'</li></ul> |
94
+ | conflict | <ul><li>'The food was delicious but:The food was delicious but do not come here on a empty stomach.'</li><li>"The service varys from day:The service varys from day to day- sometimes they're very nice, and sometimes not."</li></ul> |
95
+
96
+ ## Evaluation
97
+
98
+ ### Metrics
99
+ | Label | F1_Micro | F1_Macro | Precision_Macro | Recall_Macro |
100
+ |:--------|:---------|:---------|:----------------|:-------------|
101
+ | **all** | 0.7399 | 0.4793 | 0.4919 | 0.4809 |
102
+
103
+ ## Uses
104
+
105
+ ### Direct Use for Inference
106
+
107
+ First install the SetFit library:
108
+
109
+ ```bash
110
+ pip install setfit
111
+ ```
112
+
113
+ Then you can load this model and run inference.
114
+
115
+ ```python
116
+ from setfit import AbsaModel
117
+
118
+ # Download from the 🤗 Hub
119
+ model = AbsaModel.from_pretrained(
120
+ "setfit-absa-aspect",
121
+ "ronalhung/setfit-absa-restaurants-polarity-128",
122
+ )
123
+ # Run inference
124
+ preds = model("The food was great, but the venue is just way too busy.")
125
+ ```
126
+
127
+ <!--
128
+ ### Downstream Use
129
+
130
+ *List how someone could finetune this model on their own dataset.*
131
+ -->
132
+
133
+ <!--
134
+ ### Out-of-Scope Use
135
+
136
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
137
+ -->
138
+
139
+ <!--
140
+ ## Bias, Risks and Limitations
141
+
142
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
143
+ -->
144
+
145
+ <!--
146
+ ### Recommendations
147
+
148
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
149
+ -->
150
+
151
+ ## Training Details
152
+
153
+ ### Training Set Metrics
154
+ | Training set | Min | Median | Max |
155
+ |:-------------|:----|:--------|:----|
156
+ | Word count | 6 | 21.3594 | 43 |
157
+
158
+ | Label | Training Sample Count |
159
+ |:---------|:----------------------|
160
+ | conflict | 2 |
161
+ | negative | 19 |
162
+ | neutral | 25 |
163
+ | positive | 82 |
164
+
165
+ ### Training Hyperparameters
166
+ - batch_size: (64, 64)
167
+ - num_epochs: (5, 5)
168
+ - max_steps: -1
169
+ - sampling_strategy: oversampling
170
+ - body_learning_rate: (2e-05, 1e-05)
171
+ - head_learning_rate: 0.01
172
+ - loss: CosineSimilarityLoss
173
+ - distance_metric: cosine_distance
174
+ - margin: 0.25
175
+ - end_to_end: False
176
+ - use_amp: False
177
+ - warmup_proportion: 0.1
178
+ - l2_weight: 0.01
179
+ - seed: 42
180
+ - eval_max_steps: -1
181
+ - load_best_model_at_end: True
182
+
183
+ ### Training Results
184
+ | Epoch | Step | Training Loss | Validation Loss |
185
+ |:------:|:----:|:-------------:|:---------------:|
186
+ | 0.0074 | 1 | 0.3008 | - |
187
+ | 0.3676 | 50 | 0.1867 | 0.1974 |
188
+ | 0.7353 | 100 | 0.0346 | 0.1855 |
189
+ | 1.1029 | 150 | 0.0061 | 0.2165 |
190
+ | 1.4706 | 200 | 0.0007 | 0.2194 |
191
+ | 1.8382 | 250 | 0.0003 | 0.2145 |
192
+ | 2.2059 | 300 | 0.0006 | 0.2150 |
193
+ | 2.5735 | 350 | 0.0002 | 0.2223 |
194
+
195
+ ### Framework Versions
196
+ - Python: 3.11.13
197
+ - SetFit: 1.1.2
198
+ - Sentence Transformers: 4.1.0
199
+ - spaCy: 3.8.7
200
+ - Transformers: 4.52.4
201
+ - PyTorch: 2.6.0+cu124
202
+ - Datasets: 3.6.0
203
+ - Tokenizers: 0.21.1
204
+
205
+ ## Citation
206
+
207
+ ### BibTeX
208
+ ```bibtex
209
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
210
+ doi = {10.48550/ARXIV.2209.11055},
211
+ url = {https://arxiv.org/abs/2209.11055},
212
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
213
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
214
+ title = {Efficient Few-Shot Learning Without Prompts},
215
+ publisher = {arXiv},
216
+ year = {2022},
217
+ copyright = {Creative Commons Attribution 4.0 International}
218
+ }
219
+ ```
220
+
221
+ <!--
222
+ ## Glossary
223
+
224
+ *Clearly define terms in order to be accessible across audiences.*
225
+ -->
226
+
227
+ <!--
228
+ ## Model Card Authors
229
+
230
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
231
+ -->
232
+
233
+ <!--
234
+ ## Model Card Contact
235
+
236
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
237
+ -->
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MPNetModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "eos_token_id": 2,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "layer_norm_eps": 1e-05,
14
+ "max_position_embeddings": 514,
15
+ "model_type": "mpnet",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 1,
19
+ "relative_attention_num_buckets": 32,
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.52.4",
22
+ "vocab_size": 30527
23
+ }
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,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "normalize_embeddings": false,
3
+ "labels": [
4
+ "conflict",
5
+ "negative",
6
+ "neutral",
7
+ "positive"
8
+ ],
9
+ "span_context": 3,
10
+ "spacy_model": "en_core_web_lg"
11
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d19a8ffb3d43386588a5e9dbdb2d7facbcb765b65b9645b4f7cfea48493d1f22
3
+ size 437967672
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d416b37fc78748343c62b25a0b46e534c40dba37ace49f9b17010d62b5885946
3
+ size 25575
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": 384,
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,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "104": {
36
+ "content": "[UNK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "30526": {
44
+ "content": "<mask>",
45
+ "lstrip": true,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ }
51
+ },
52
+ "bos_token": "<s>",
53
+ "clean_up_tokenization_spaces": false,
54
+ "cls_token": "<s>",
55
+ "do_lower_case": true,
56
+ "eos_token": "</s>",
57
+ "extra_special_tokens": {},
58
+ "mask_token": "<mask>",
59
+ "max_length": 128,
60
+ "model_max_length": 384,
61
+ "pad_to_multiple_of": null,
62
+ "pad_token": "<pad>",
63
+ "pad_token_type_id": 0,
64
+ "padding_side": "right",
65
+ "sep_token": "</s>",
66
+ "stride": 0,
67
+ "strip_accents": null,
68
+ "tokenize_chinese_chars": true,
69
+ "tokenizer_class": "MPNetTokenizer",
70
+ "truncation_side": "right",
71
+ "truncation_strategy": "longest_first",
72
+ "unk_token": "[UNK]"
73
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff