NazmusAshrafi commited on
Commit
138c5d3
1 Parent(s): 2217c9c

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 CHANGED
@@ -1,3 +1,281 @@
1
  ---
2
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ library_name: setfit
3
+ tags:
4
+ - setfit
5
+ - absa
6
+ - sentence-transformers
7
+ - text-classification
8
+ - generated_from_setfit_trainer
9
+ metrics:
10
+ - accuracy
11
+ widget:
12
+ - text: spumoni ices:It also has great ice cream and spumoni ices.
13
+ - text: place:its a cool place to come with a bunch of people or with a date for maybe
14
+ a mild dinner or some drinks.
15
+ - text: care:The Food Despite a menu that seems larger than the restaurant, great
16
+ care goes into the preparation of every dish.
17
+ - text: peoples:Upon entering, I was impressed by the room while the food on other
18
+ peoples' tables seemed enticing.
19
+ - text: group:As if that wasnt enough, after another in the group mentioned that a
20
+ portion of the sushi on her plate was not what she had ordered, the waiter came
21
+ back with chopsticks and started to remove it (as she was eating!)
22
+ pipeline_tag: text-classification
23
+ inference: false
24
+ base_model: sentence-transformers/paraphrase-mpnet-base-v2
25
+ model-index:
26
+ - name: SetFit Aspect Model with sentence-transformers/paraphrase-mpnet-base-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.9680851063829787
38
+ name: Accuracy
39
  ---
40
+
41
+ # SetFit Aspect Model with sentence-transformers/paraphrase-mpnet-base-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/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. 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/paraphrase-mpnet-base-v2](https://huggingface.co/sentence-transformers/paraphrase-mpnet-base-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_lg
63
+ - **SetFitABSA Aspect Model:** [NazmusAshrafi/mams-ds-setfit-MiniLM-mpnet-absa-tesla-tweet-aspect](https://huggingface.co/NazmusAshrafi/mams-ds-setfit-MiniLM-mpnet-absa-tesla-tweet-aspect)
64
+ - **SetFitABSA Polarity Model:** [NazmusAshrafi/mams-ds-setfit-MiniLM-mpnet-absa-tesla-tweet-polarity](https://huggingface.co/NazmusAshrafi/mams-ds-setfit-MiniLM-mpnet-absa-tesla-tweet-polarity)
65
+ - **Maximum Sequence Length:** 512 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>"food:It might be the best sit down food I've had in the area, so if you are going to the upright citizen brigade, or the garden, it could be just the place for you."</li><li>"place:It might be the best sit down food I've had in the area, so if you are going to the upright citizen brigade, or the garden, it could be just the place for you."</li><li>'service:Though the service might be a little slow, the waitresses are very friendly.'</li></ul> |
81
+ | no aspect | <ul><li>"sit:It might be the best sit down food I've had in the area, so if you are going to the upright citizen brigade, or the garden, it could be just the place for you."</li><li>"area:It might be the best sit down food I've had in the area, so if you are going to the upright citizen brigade, or the garden, it could be just the place for you."</li><li>"citizen brigade:It might be the best sit down food I've had in the area, so if you are going to the upright citizen brigade, or the garden, it could be just the place for you."</li></ul> |
82
+
83
+ ## Evaluation
84
+
85
+ ### Metrics
86
+ | Label | Accuracy |
87
+ |:--------|:---------|
88
+ | **all** | 0.9681 |
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
+ "NazmusAshrafi/mams-ds-setfit-MiniLM-mpnet-absa-tesla-tweet-aspect",
108
+ "NazmusAshrafi/mams-ds-setfit-MiniLM-mpnet-absa-tesla-tweet-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 | 8 | 26.6069 | 52 |
144
+
145
+ | Label | Training Sample Count |
146
+ |:----------|:----------------------|
147
+ | no aspect | 229 |
148
+ | aspect | 33 |
149
+
150
+ ### Training Hyperparameters
151
+ - batch_size: (16, 2)
152
+ - num_epochs: (1, 16)
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: False
162
+ - warmup_proportion: 0.1
163
+ - seed: 42
164
+ - eval_max_steps: -1
165
+ - load_best_model_at_end: False
166
+
167
+ ### Training Results
168
+ | Epoch | Step | Training Loss | Validation Loss |
169
+ |:------:|:----:|:-------------:|:---------------:|
170
+ | 0.0003 | 1 | 0.2315 | - |
171
+ | 0.0149 | 50 | 0.2637 | - |
172
+ | 0.0297 | 100 | 0.1795 | - |
173
+ | 0.0446 | 150 | 0.1164 | - |
174
+ | 0.0595 | 200 | 0.0131 | - |
175
+ | 0.0744 | 250 | 0.0036 | - |
176
+ | 0.0892 | 300 | 0.0004 | - |
177
+ | 0.1041 | 350 | 0.0003 | - |
178
+ | 0.1190 | 400 | 0.0001 | - |
179
+ | 0.1338 | 450 | 0.0002 | - |
180
+ | 0.1487 | 500 | 0.0001 | - |
181
+ | 0.1636 | 550 | 0.0001 | - |
182
+ | 0.1785 | 600 | 0.0001 | - |
183
+ | 0.1933 | 650 | 0.0001 | - |
184
+ | 0.2082 | 700 | 0.0 | - |
185
+ | 0.2231 | 750 | 0.0001 | - |
186
+ | 0.2380 | 800 | 0.0001 | - |
187
+ | 0.2528 | 850 | 0.0 | - |
188
+ | 0.2677 | 900 | 0.0001 | - |
189
+ | 0.2826 | 950 | 0.0003 | - |
190
+ | 0.2974 | 1000 | 0.0008 | - |
191
+ | 0.3123 | 1050 | 0.0001 | - |
192
+ | 0.3272 | 1100 | 0.0 | - |
193
+ | 0.3421 | 1150 | 0.0 | - |
194
+ | 0.3569 | 1200 | 0.0 | - |
195
+ | 0.3718 | 1250 | 0.0 | - |
196
+ | 0.3867 | 1300 | 0.0 | - |
197
+ | 0.4015 | 1350 | 0.0 | - |
198
+ | 0.4164 | 1400 | 0.0 | - |
199
+ | 0.4313 | 1450 | 0.0 | - |
200
+ | 0.4462 | 1500 | 0.0 | - |
201
+ | 0.4610 | 1550 | 0.0 | - |
202
+ | 0.4759 | 1600 | 0.0 | - |
203
+ | 0.4908 | 1650 | 0.0 | - |
204
+ | 0.5057 | 1700 | 0.0 | - |
205
+ | 0.5205 | 1750 | 0.0 | - |
206
+ | 0.5354 | 1800 | 0.0 | - |
207
+ | 0.5503 | 1850 | 0.0 | - |
208
+ | 0.5651 | 1900 | 0.0 | - |
209
+ | 0.5800 | 1950 | 0.0 | - |
210
+ | 0.5949 | 2000 | 0.0 | - |
211
+ | 0.6098 | 2050 | 0.0 | - |
212
+ | 0.6246 | 2100 | 0.0 | - |
213
+ | 0.6395 | 2150 | 0.0 | - |
214
+ | 0.6544 | 2200 | 0.0 | - |
215
+ | 0.6692 | 2250 | 0.0 | - |
216
+ | 0.6841 | 2300 | 0.0 | - |
217
+ | 0.6990 | 2350 | 0.0 | - |
218
+ | 0.7139 | 2400 | 0.0 | - |
219
+ | 0.7287 | 2450 | 0.0 | - |
220
+ | 0.7436 | 2500 | 0.0 | - |
221
+ | 0.7585 | 2550 | 0.0 | - |
222
+ | 0.7733 | 2600 | 0.0 | - |
223
+ | 0.7882 | 2650 | 0.0 | - |
224
+ | 0.8031 | 2700 | 0.0 | - |
225
+ | 0.8180 | 2750 | 0.0 | - |
226
+ | 0.8328 | 2800 | 0.0 | - |
227
+ | 0.8477 | 2850 | 0.0 | - |
228
+ | 0.8626 | 2900 | 0.0 | - |
229
+ | 0.8775 | 2950 | 0.0 | - |
230
+ | 0.8923 | 3000 | 0.0 | - |
231
+ | 0.9072 | 3050 | 0.0 | - |
232
+ | 0.9221 | 3100 | 0.0 | - |
233
+ | 0.9369 | 3150 | 0.0 | - |
234
+ | 0.9518 | 3200 | 0.0 | - |
235
+ | 0.9667 | 3250 | 0.0 | - |
236
+ | 0.9816 | 3300 | 0.0 | - |
237
+ | 0.9964 | 3350 | 0.0 | - |
238
+
239
+ ### Framework Versions
240
+ - Python: 3.10.12
241
+ - SetFit: 1.0.3
242
+ - Sentence Transformers: 2.4.0
243
+ - spaCy: 3.7.4
244
+ - Transformers: 4.37.2
245
+ - PyTorch: 2.1.0+cu121
246
+ - Datasets: 2.17.1
247
+ - Tokenizers: 0.15.2
248
+
249
+ ## Citation
250
+
251
+ ### BibTeX
252
+ ```bibtex
253
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
254
+ doi = {10.48550/ARXIV.2209.11055},
255
+ url = {https://arxiv.org/abs/2209.11055},
256
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
257
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
258
+ title = {Efficient Few-Shot Learning Without Prompts},
259
+ publisher = {arXiv},
260
+ year = {2022},
261
+ copyright = {Creative Commons Attribution 4.0 International}
262
+ }
263
+ ```
264
+
265
+ <!--
266
+ ## Glossary
267
+
268
+ *Clearly define terms in order to be accessible across audiences.*
269
+ -->
270
+
271
+ <!--
272
+ ## Model Card Authors
273
+
274
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
275
+ -->
276
+
277
+ <!--
278
+ ## Model Card Contact
279
+
280
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
281
+ -->
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "sentence-transformers/paraphrase-mpnet-base-v2",
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.37.2",
23
+ "vocab_size": 30527
24
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.7.0",
5
+ "pytorch": "1.9.0+cu102"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null
9
+ }
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_lg"
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e10c8516f4ddde135d3e4e7730a2963084485547e5a0f661a6a21fb1fda99cce
3
+ size 437967672
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61b6365d5980f58d66a649df33fbe0f1ba7e0e8ed8628407b7ccd82febbd3166
3
+ size 6991
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,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "model_max_length": 512,
52
+ "never_split": null,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "strip_accents": null,
56
+ "tokenize_chinese_chars": true,
57
+ "tokenizer_class": "MPNetTokenizer",
58
+ "unk_token": "[UNK]"
59
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff