ZeaNL commited on
Commit
191840e
·
verified ·
1 Parent(s): 52ed192

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,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - setfit
4
+ - absa
5
+ - sentence-transformers
6
+ - text-classification
7
+ - generated_from_setfit_trainer
8
+ widget:
9
+ - text: prices:What is even better, is that the prices are very affordable as well,
10
+ and the food is really good.
11
+ - text: 'soups:An oasis of refinement: Food, though somewhat uneven, often reaches
12
+ the pinnacles of new American fine cuisine - chef''s passion (and kitchen''s precise
13
+ execution) is most evident in the fish dishes and soups.'
14
+ - text: lobster sandwich:We had the lobster sandwich and it was FANTASTIC.
15
+ - text: captain:I understand the area and folks you need not come here for the romantic,
16
+ alluring ambiance or the five star service featuring a sommlier and a complicated
17
+ maze of captain and back waiters - you come for the authentic foods, the tastes,
18
+ the experiance.
19
+ - text: dining experience:The entire dining experience was wonderful!
20
+ metrics:
21
+ - accuracy
22
+ pipeline_tag: text-classification
23
+ library_name: setfit
24
+ inference: false
25
+ base_model: sentence-transformers/all-MiniLM-L6-v2
26
+ model-index:
27
+ - name: SetFit Aspect Model with sentence-transformers/all-MiniLM-L6-v2
28
+ results:
29
+ - task:
30
+ type: text-classification
31
+ name: Text Classification
32
+ dataset:
33
+ name: Unknown
34
+ type: unknown
35
+ split: test
36
+ metrics:
37
+ - type: accuracy
38
+ value: 0.8502202643171806
39
+ name: Accuracy
40
+ ---
41
+
42
+ # SetFit Aspect Model with sentence-transformers/all-MiniLM-L6-v2
43
+
44
+ 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.
45
+
46
+ The model has been trained using an efficient few-shot learning technique that involves:
47
+
48
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
49
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
50
+
51
+ This model was trained within the context of a larger system for ABSA, which looks like so:
52
+
53
+ 1. Use a spaCy model to select possible aspect span candidates.
54
+ 2. **Use this SetFit model to filter these possible aspect span candidates.**
55
+ 3. Use a SetFit model to classify the filtered aspect span candidates.
56
+
57
+ ## Model Details
58
+
59
+ ### Model Description
60
+ - **Model Type:** SetFit
61
+ - **Sentence Transformer body:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
62
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
63
+ - **spaCy Model:** en_core_web_sm
64
+ - **SetFitABSA Aspect Model:** [ZeaNL/setfit-absa-bge-small-en-v1.5-restaurants-aspect](https://huggingface.co/ZeaNL/setfit-absa-bge-small-en-v1.5-restaurants-aspect)
65
+ - **SetFitABSA Polarity Model:** [ZeaNL/setfit-absa-bge-small-en-v1.5-restaurants-polarity](https://huggingface.co/ZeaNL/setfit-absa-bge-small-en-v1.5-restaurants-polarity)
66
+ - **Maximum Sequence Length:** 256 tokens
67
+ - **Number of Classes:** 2 classes
68
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
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
+ | 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> |
82
+ | 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> |
83
+
84
+ ## Evaluation
85
+
86
+ ### Metrics
87
+ | Label | Accuracy |
88
+ |:--------|:---------|
89
+ | **all** | 0.8502 |
90
+
91
+ ## Uses
92
+
93
+ ### Direct Use for Inference
94
+
95
+ First install the SetFit library:
96
+
97
+ ```bash
98
+ pip install setfit
99
+ ```
100
+
101
+ Then you can load this model and run inference.
102
+
103
+ ```python
104
+ from setfit import AbsaModel
105
+
106
+ # Download from the 🤗 Hub
107
+ model = AbsaModel.from_pretrained(
108
+ "ZeaNL/setfit-absa-bge-small-en-v1.5-restaurants-aspect",
109
+ "ZeaNL/setfit-absa-bge-small-en-v1.5-restaurants-polarity",
110
+ )
111
+ # Run inference
112
+ preds = model("The food was great, but the venue is just way too busy.")
113
+ ```
114
+
115
+ <!--
116
+ ### Downstream Use
117
+
118
+ *List how someone could finetune this model on their own dataset.*
119
+ -->
120
+
121
+ <!--
122
+ ### Out-of-Scope Use
123
+
124
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
125
+ -->
126
+
127
+ <!--
128
+ ## Bias, Risks and Limitations
129
+
130
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
131
+ -->
132
+
133
+ <!--
134
+ ### Recommendations
135
+
136
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
137
+ -->
138
+
139
+ ## Training Details
140
+
141
+ ### Training Set Metrics
142
+ | Training set | Min | Median | Max |
143
+ |:-------------|:----|:-------|:----|
144
+ | Word count | 4 | 17.915 | 37 |
145
+
146
+ | Label | Training Sample Count |
147
+ |:----------|:----------------------|
148
+ | no aspect | 72 |
149
+ | aspect | 128 |
150
+
151
+ ### Training Hyperparameters
152
+ - batch_size: (128, 128)
153
+ - num_epochs: (5, 5)
154
+ - max_steps: -1
155
+ - sampling_strategy: oversampling
156
+ - body_learning_rate: (2e-05, 1e-05)
157
+ - head_learning_rate: 0.01
158
+ - loss: CosineSimilarityLoss
159
+ - distance_metric: cosine_distance
160
+ - margin: 0.25
161
+ - end_to_end: False
162
+ - use_amp: True
163
+ - warmup_proportion: 0.1
164
+ - l2_weight: 0.01
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.0058 | 1 | 0.2746 | - |
173
+ | 0.2924 | 50 | 0.2771 | 0.2563 |
174
+ | 0.5848 | 100 | 0.1821 | 0.2233 |
175
+ | 0.8772 | 150 | 0.0216 | 0.2231 |
176
+ | 1.1696 | 200 | 0.0028 | 0.2303 |
177
+ | 1.4620 | 250 | 0.0017 | 0.2352 |
178
+ | 1.7544 | 300 | 0.0011 | 0.2370 |
179
+ | 2.0468 | 350 | 0.0009 | 0.2363 |
180
+ | 2.3392 | 400 | 0.0005 | 0.2356 |
181
+
182
+ ### Framework Versions
183
+ - Python: 3.11.12
184
+ - SetFit: 1.1.2
185
+ - Sentence Transformers: 3.4.1
186
+ - spaCy: 3.7.5
187
+ - Transformers: 4.51.3
188
+ - PyTorch: 2.6.0+cu124
189
+ - Datasets: 3.5.1
190
+ - Tokenizers: 0.21.1
191
+
192
+ ## Citation
193
+
194
+ ### BibTeX
195
+ ```bibtex
196
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
197
+ doi = {10.48550/ARXIV.2209.11055},
198
+ url = {https://arxiv.org/abs/2209.11055},
199
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
200
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
201
+ title = {Efficient Few-Shot Learning Without Prompts},
202
+ publisher = {arXiv},
203
+ year = {2022},
204
+ copyright = {Creative Commons Attribution 4.0 International}
205
+ }
206
+ ```
207
+
208
+ <!--
209
+ ## Glossary
210
+
211
+ *Clearly define terms in order to be accessible across audiences.*
212
+ -->
213
+
214
+ <!--
215
+ ## Model Card Authors
216
+
217
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
218
+ -->
219
+
220
+ <!--
221
+ ## Model Card Contact
222
+
223
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
224
+ -->
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.3",
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.3",
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
+ "span_context": 0,
4
+ "labels": [
5
+ "no aspect",
6
+ "aspect"
7
+ ],
8
+ "spacy_model": "en_core_web_sm"
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c5671c23ef50de7720679aac98b26e1625bc20c234b9a84249c326d1f0656f27
3
+ size 90864192
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7e6fdfbbb7c56c3c03b1eeb3b829847f88c14e9e2123ec899e4d46f2344e674e
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