tomaarsen HF staff commited on
Commit
956b4f6
1 Parent(s): 5c66ac7

Add SetFit ABSA model

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
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
+ }
README.md ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: is the best French food you will find:It may be a bit packed on weekends,
13
+ but the vibe is good and it is the best French food you will find in the area.
14
+ - text: knew what the specials were.:Whem asked, we had to ask more detailed questions
15
+ so that we knew what the specials were.
16
+ - text: all out wow dining experience.:Go here for a romantic dinner but not for an
17
+ all out wow dining experience.
18
+ - text: vibe, the owner is super friendly:Best of all is the warm vibe, the owner
19
+ is super friendly and service is fast.
20
+ - text: all of the dishes are excellent.:The menu is limited but almost all of the
21
+ dishes are excellent.
22
+ pipeline_tag: text-classification
23
+ inference: false
24
+ co2_eq_emissions:
25
+ emissions: 3.720391621822588
26
+ source: codecarbon
27
+ training_type: fine-tuning
28
+ on_cloud: false
29
+ cpu_model: 13th Gen Intel(R) Core(TM) i7-13700K
30
+ ram_total_size: 31.777088165283203
31
+ hours_used: 0.054
32
+ hardware_used: 1 x NVIDIA GeForce RTX 3090
33
+ base_model: sentence-transformers/paraphrase-mpnet-base-v2
34
+ model-index:
35
+ - name: SetFit Polarity Model with sentence-transformers/paraphrase-mpnet-base-v2
36
+ results:
37
+ - task:
38
+ type: text-classification
39
+ name: Text Classification
40
+ dataset:
41
+ name: Unknown
42
+ type: unknown
43
+ split: test
44
+ metrics:
45
+ - type: accuracy
46
+ value: 0.7241282339707537
47
+ name: Accuracy
48
+ ---
49
+
50
+ # SetFit Polarity Model with sentence-transformers/paraphrase-mpnet-base-v2
51
+
52
+ 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 classifying aspect polarities.
53
+
54
+ The model has been trained using an efficient few-shot learning technique that involves:
55
+
56
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
57
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
58
+
59
+ This model was trained within the context of a larger system for ABSA, which looks like so:
60
+
61
+ 1. Use a spaCy model to select possible aspect span candidates.
62
+ 2. Use a SetFit model to filter these possible aspect span candidates.
63
+ 3. **Use this SetFit model to classify the filtered aspect span candidates.**
64
+
65
+ ## Model Details
66
+
67
+ ### Model Description
68
+ - **Model Type:** SetFit
69
+ - **Sentence Transformer body:** [sentence-transformers/paraphrase-mpnet-base-v2](https://huggingface.co/sentence-transformers/paraphrase-mpnet-base-v2)
70
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
71
+ - **spaCy Model:** en_core_web_lg
72
+ - **SetFitABSA Aspect Model:** [tomaarsen/setfit-absa-paraphrase-mpnet-base-v2-restaurants-aspect](https://huggingface.co/tomaarsen/setfit-absa-paraphrase-mpnet-base-v2-restaurants-aspect)
73
+ - **SetFitABSA Polarity Model:** [tomaarsen/setfit-absa-paraphrase-mpnet-base-v2-restaurants-polarity](https://huggingface.co/tomaarsen/setfit-absa-paraphrase-mpnet-base-v2-restaurants-polarity)
74
+ - **Maximum Sequence Length:** 512 tokens
75
+ - **Number of Classes:** 4 classes
76
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
77
+ <!-- - **Language:** Unknown -->
78
+ <!-- - **License:** Unknown -->
79
+
80
+ ### Model Sources
81
+
82
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
83
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
84
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
85
+
86
+ ### Model Labels
87
+ | Label | Examples |
88
+ |:---------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
89
+ | 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> |
90
+ | 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> |
91
+ | 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> |
92
+ | 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> |
93
+
94
+ ## Evaluation
95
+
96
+ ### Metrics
97
+ | Label | Accuracy |
98
+ |:--------|:---------|
99
+ | **all** | 0.7241 |
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
+ "tomaarsen/setfit-absa-paraphrase-mpnet-base-v2-restaurants-aspect",
119
+ "tomaarsen/setfit-absa-paraphrase-mpnet-base-v2-restaurants-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 | 6 | 21.3594 | 43 |
155
+
156
+ | Label | Training Sample Count |
157
+ |:---------|:----------------------|
158
+ | conflict | 2 |
159
+ | negative | 19 |
160
+ | neutral | 25 |
161
+ | positive | 82 |
162
+
163
+ ### Training Hyperparameters
164
+ - batch_size: (16, 2)
165
+ - num_epochs: (1, 16)
166
+ - max_steps: -1
167
+ - sampling_strategy: oversampling
168
+ - body_learning_rate: (2e-05, 1e-05)
169
+ - head_learning_rate: 0.01
170
+ - loss: CosineSimilarityLoss
171
+ - distance_metric: cosine_distance
172
+ - margin: 0.25
173
+ - end_to_end: False
174
+ - use_amp: False
175
+ - warmup_proportion: 0.1
176
+ - seed: 42
177
+ - eval_max_steps: -1
178
+ - load_best_model_at_end: False
179
+
180
+ ### Training Results
181
+ | Epoch | Step | Training Loss | Validation Loss |
182
+ |:------:|:----:|:-------------:|:---------------:|
183
+ | 0.0018 | 1 | 0.221 | - |
184
+ | 0.0923 | 50 | 0.1118 | - |
185
+ | 0.1845 | 100 | 0.0784 | - |
186
+ | 0.2768 | 150 | 0.0024 | - |
187
+ | 0.3690 | 200 | 0.0004 | - |
188
+ | 0.4613 | 250 | 0.0003 | - |
189
+ | 0.5535 | 300 | 0.0006 | - |
190
+ | 0.6458 | 350 | 0.0004 | - |
191
+ | 0.7380 | 400 | 0.0005 | - |
192
+ | 0.8303 | 450 | 0.0001 | - |
193
+ | 0.9225 | 500 | 0.0003 | - |
194
+
195
+ ### Environmental Impact
196
+ Carbon emissions were measured using [CodeCarbon](https://github.com/mlco2/codecarbon).
197
+ - **Carbon Emitted**: 0.004 kg of CO2
198
+ - **Hours Used**: 0.054 hours
199
+
200
+ ### Training Hardware
201
+ - **On Cloud**: No
202
+ - **GPU Model**: 1 x NVIDIA GeForce RTX 3090
203
+ - **CPU Model**: 13th Gen Intel(R) Core(TM) i7-13700K
204
+ - **RAM Size**: 31.78 GB
205
+
206
+ ### Framework Versions
207
+ - Python: 3.9.16
208
+ - SetFit: 1.0.0.dev0
209
+ - Sentence Transformers: 2.2.2
210
+ - spaCy: 3.7.2
211
+ - Transformers: 4.29.0
212
+ - PyTorch: 1.13.1+cu117
213
+ - Datasets: 2.15.0
214
+ - Tokenizers: 0.13.3
215
+
216
+ ## Citation
217
+
218
+ ### BibTeX
219
+ ```bibtex
220
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
221
+ doi = {10.48550/ARXIV.2209.11055},
222
+ url = {https://arxiv.org/abs/2209.11055},
223
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
224
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
225
+ title = {Efficient Few-Shot Learning Without Prompts},
226
+ publisher = {arXiv},
227
+ year = {2022},
228
+ copyright = {Creative Commons Attribution 4.0 International}
229
+ }
230
+ ```
231
+
232
+ <!--
233
+ ## Glossary
234
+
235
+ *Clearly define terms in order to be accessible across audiences.*
236
+ -->
237
+
238
+ <!--
239
+ ## Model Card Authors
240
+
241
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
242
+ -->
243
+
244
+ <!--
245
+ ## Model Card Contact
246
+
247
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
248
+ -->
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "C:\\Users\\tom/.cache\\torch\\sentence_transformers\\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.29.0",
23
+ "vocab_size": 30527
24
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.7.0",
5
+ "pytorch": "1.9.0+cu102"
6
+ }
7
+ }
config_setfit.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "normalize_embeddings": false,
3
+ "spacy_model": "en_core_web_lg",
4
+ "span_context": 3,
5
+ "labels": null
6
+ }
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:222064cbc4ce8507bb6c06c370012ed93cc5dde6622393676c086e686e1051ad
3
+ size 25559
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
+ ]
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:405d50828ed249c80ab6e8c8f875c9421c2e69a7a576b17026f6ff8be0a5ed9e
3
+ size 438016493
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,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "[UNK]"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "__type": "AddedToken",
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": true,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ "clean_up_tokenization_spaces": true,
11
+ "cls_token": {
12
+ "__type": "AddedToken",
13
+ "content": "<s>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false
18
+ },
19
+ "do_basic_tokenize": true,
20
+ "do_lower_case": true,
21
+ "eos_token": {
22
+ "__type": "AddedToken",
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": true,
26
+ "rstrip": false,
27
+ "single_word": false
28
+ },
29
+ "mask_token": {
30
+ "__type": "AddedToken",
31
+ "content": "<mask>",
32
+ "lstrip": true,
33
+ "normalized": true,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "model_max_length": 512,
38
+ "never_split": null,
39
+ "pad_token": {
40
+ "__type": "AddedToken",
41
+ "content": "<pad>",
42
+ "lstrip": false,
43
+ "normalized": true,
44
+ "rstrip": false,
45
+ "single_word": false
46
+ },
47
+ "sep_token": {
48
+ "__type": "AddedToken",
49
+ "content": "</s>",
50
+ "lstrip": false,
51
+ "normalized": true,
52
+ "rstrip": false,
53
+ "single_word": false
54
+ },
55
+ "strip_accents": null,
56
+ "tokenize_chinese_chars": true,
57
+ "tokenizer_class": "MPNetTokenizer",
58
+ "unk_token": {
59
+ "__type": "AddedToken",
60
+ "content": "[UNK]",
61
+ "lstrip": false,
62
+ "normalized": true,
63
+ "rstrip": false,
64
+ "single_word": false
65
+ }
66
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff