tomaarsen HF staff commited on
Commit
29ffeac
1 Parent(s): 73edbe1

Add SetFit ABSA model

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
3
+ "pooling_mode_cls_token": true,
4
+ "pooling_mode_mean_tokens": false,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
README.md ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: setfit
3
+ tags:
4
+ - setfit
5
+ - absa
6
+ - absa
7
+ - absa
8
+ - absa
9
+ - absa
10
+ - absa
11
+ - absa
12
+ - absa
13
+ - absa
14
+ - absa
15
+ - sentence-transformers
16
+ - text-classification
17
+ - generated_from_setfit_trainer
18
+ metrics:
19
+ - accuracy
20
+ widget:
21
+ - text: people:Regardless of whether there are two people or two hundred people ahead
22
+ of you the hostess will take your name and tell you Five minutes.
23
+ - text: dish:This dish is my favorite and I always get it when I go there and never
24
+ get tired of it.
25
+ - text: food:Get your food to go, find a bench, and kick back with a plate of dumplings.
26
+ - text: crabmeat lasagna:You must have the crabmeat lasagna which is out of this world
27
+ and the chocolate bread pudding for dessert.
28
+ - text: plate:Get your food to go, find a bench, and kick back with a plate of dumplings.
29
+ pipeline_tag: text-classification
30
+ inference: false
31
+ co2_eq_emissions:
32
+ emissions: 12.403245052695876
33
+ source: codecarbon
34
+ training_type: fine-tuning
35
+ on_cloud: false
36
+ cpu_model: 13th Gen Intel(R) Core(TM) i7-13700K
37
+ ram_total_size: 31.777088165283203
38
+ hours_used: 0.158
39
+ hardware_used: 1 x NVIDIA GeForce RTX 3090
40
+ base_model: BAAI/bge-small-en-v1.5
41
+ model-index:
42
+ - name: SetFit Aspect Model Aspect Model Aspect Model Aspect Model Aspect Model Aspect
43
+ Model Aspect Model Aspect Model Aspect Model Aspect Model with BAAI/bge-small-en-v1.5
44
+ results:
45
+ - task:
46
+ type: text-classification
47
+ name: Text Classification
48
+ dataset:
49
+ name: Unknown
50
+ type: unknown
51
+ split: test
52
+ metrics:
53
+ - type: accuracy
54
+ value: 0.7871243108660857
55
+ name: Accuracy
56
+ ---
57
+
58
+ # SetFit Aspect Model Aspect Model Aspect Model Aspect Model Aspect Model Aspect Model Aspect Model Aspect Model Aspect Model Aspect Model with BAAI/bge-small-en-v1.5
59
+
60
+ This is a [SetFit](https://github.com/huggingface/setfit) model that can be used for Aspect Based Sentiment Analysis (ABSA). This SetFit model uses [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5) 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.
61
+
62
+ The model has been trained using an efficient few-shot learning technique that involves:
63
+
64
+ 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
65
+ 2. Training a classification head with features from the fine-tuned Sentence Transformer.
66
+
67
+ This model was trained within the context of a larger system for ABSA, which looks like so:
68
+
69
+ 1. Use a spaCy model to select possible aspect span candidates.
70
+ 2. **Use this SetFit model to filter these possible aspect span candidates.**
71
+ 3. Use a SetFit model to classify the filtered aspect span candidates.
72
+
73
+ ## Model Details
74
+
75
+ ### Model Description
76
+ - **Model Type:** SetFit
77
+ - **Sentence Transformer body:** [BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5)
78
+ - **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
79
+ - **SetFitABSA Aspect Model:** [tomaarsen/setfit-absa-bge-small-en-v1.5-restaurants-aspect](https://huggingface.co/tomaarsen/setfit-absa-bge-small-en-v1.5-restaurants-aspect)
80
+ - **SetFitABSA Polarity Model:** [tomaarsen/setfit-absa-bge-small-en-v1.5-restaurants-polarity](https://huggingface.co/tomaarsen/setfit-absa-bge-small-en-v1.5-restaurants-polarity)
81
+ - **Maximum Sequence Length:** 512 tokens
82
+ - **Number of Classes:** 2 classes
83
+ <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
84
+ <!-- - **Language:** Unknown -->
85
+ <!-- - **License:** Unknown -->
86
+
87
+ ### Model Sources
88
+
89
+ - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
90
+ - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
91
+ - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
92
+
93
+ ### Model Labels
94
+ | Label | Examples |
95
+ |:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
96
+ | 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> |
97
+ | 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> |
98
+
99
+ ## Evaluation
100
+
101
+ ### Metrics
102
+ | Label | Accuracy |
103
+ |:--------|:---------|
104
+ | **all** | 0.7871 |
105
+
106
+ ## Uses
107
+
108
+ ### Direct Use for Inference
109
+
110
+ First install the SetFit library:
111
+
112
+ ```bash
113
+ pip install setfit
114
+ ```
115
+
116
+ Then you can load this model and run inference.
117
+
118
+ ```python
119
+ from setfit import AbsaModel
120
+
121
+ # Download from the 🤗 Hub
122
+ model = AbsaModel.from_pretrained(
123
+ "tomaarsen/setfit-absa-bge-small-en-v1.5-restaurants-aspect",
124
+ "tomaarsen/setfit-absa-bge-small-en-v1.5-restaurants-polarity",
125
+ )
126
+ # Run inference
127
+ preds = model("The food was great, but the venue is just way too busy.")
128
+ ```
129
+
130
+ <!--
131
+ ### Downstream Use
132
+
133
+ *List how someone could finetune this model on their own dataset.*
134
+ -->
135
+
136
+ <!--
137
+ ### Out-of-Scope Use
138
+
139
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
140
+ -->
141
+
142
+ <!--
143
+ ## Bias, Risks and Limitations
144
+
145
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
146
+ -->
147
+
148
+ <!--
149
+ ### Recommendations
150
+
151
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
152
+ -->
153
+
154
+ ## Training Details
155
+
156
+ ### Training Set Metrics
157
+ | Training set | Min | Median | Max |
158
+ |:-------------|:----|:--------|:----|
159
+ | Word count | 4 | 19.3034 | 45 |
160
+
161
+ | Label | Training Sample Count |
162
+ |:----------|:----------------------|
163
+ | no aspect | 231 |
164
+ | aspect | 204 |
165
+
166
+ ### Training Hyperparameters
167
+ - batch_size: (256, 256)
168
+ - num_epochs: (5, 5)
169
+ - max_steps: 5000
170
+ - sampling_strategy: oversampling
171
+ - body_learning_rate: (2e-05, 1e-05)
172
+ - head_learning_rate: 0.01
173
+ - loss: CosineSimilarityLoss
174
+ - distance_metric: cosine_distance
175
+ - margin: 0.25
176
+ - end_to_end: False
177
+ - use_amp: True
178
+ - warmup_proportion: 0.1
179
+ - seed: 42
180
+ - load_best_model_at_end: True
181
+
182
+ ### Training Results
183
+ | Epoch | Step | Training Loss | Validation Loss |
184
+ |:----------:|:-------:|:-------------:|:---------------:|
185
+ | 0.0027 | 1 | 0.2574 | - |
186
+ | 0.1340 | 50 | 0.2561 | - |
187
+ | 0.2681 | 100 | 0.251 | 0.2543 |
188
+ | 0.4021 | 150 | 0.2451 | - |
189
+ | 0.5362 | 200 | 0.242 | 0.2506 |
190
+ | 0.6702 | 250 | 0.2239 | - |
191
+ | **0.8043** | **300** | **0.0473** | **0.2499** |
192
+ | 0.9383 | 350 | 0.0098 | - |
193
+ | 1.0724 | 400 | 0.0097 | 0.2734 |
194
+ | 1.2064 | 450 | 0.0047 | - |
195
+ | 1.3405 | 500 | 0.0071 | 0.2834 |
196
+ | 1.4745 | 550 | 0.0089 | - |
197
+ | 1.6086 | 600 | 0.005 | 0.273 |
198
+ | 1.7426 | 650 | 0.0041 | - |
199
+ | 1.8767 | 700 | 0.0042 | 0.2942 |
200
+ | 2.0107 | 750 | 0.0053 | - |
201
+ | 2.1448 | 800 | 0.0073 | 0.2898 |
202
+
203
+ * The bold row denotes the saved checkpoint.
204
+ ### Environmental Impact
205
+ Carbon emissions were measured using [CodeCarbon](https://github.com/mlco2/codecarbon).
206
+ - **Carbon Emitted**: 0.012 kg of CO2
207
+ - **Hours Used**: 0.158 hours
208
+
209
+ ### Training Hardware
210
+ - **On Cloud**: No
211
+ - **GPU Model**: 1 x NVIDIA GeForce RTX 3090
212
+ - **CPU Model**: 13th Gen Intel(R) Core(TM) i7-13700K
213
+ - **RAM Size**: 31.78 GB
214
+
215
+ ### Framework Versions
216
+ - Python: 3.9.16
217
+ - SetFit: 1.0.0.dev0
218
+ - Sentence Transformers: 2.2.2
219
+ - Transformers: 4.29.0
220
+ - PyTorch: 1.13.1+cu117
221
+ - Datasets: 2.15.0
222
+ - Tokenizers: 0.13.3
223
+
224
+ ## Citation
225
+
226
+ ### BibTeX
227
+ ```bibtex
228
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
229
+ doi = {10.48550/ARXIV.2209.11055},
230
+ url = {https://arxiv.org/abs/2209.11055},
231
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
232
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
233
+ title = {Efficient Few-Shot Learning Without Prompts},
234
+ publisher = {arXiv},
235
+ year = {2022},
236
+ copyright = {Creative Commons Attribution 4.0 International}
237
+ }
238
+ ```
239
+
240
+ <!--
241
+ ## Glossary
242
+
243
+ *Clearly define terms in order to be accessible across audiences.*
244
+ -->
245
+
246
+ <!--
247
+ ## Model Card Authors
248
+
249
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
250
+ -->
251
+
252
+ <!--
253
+ ## Model Card Contact
254
+
255
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
256
+ -->
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "models\\step_300\\",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 384,
11
+ "id2label": {
12
+ "0": "LABEL_0"
13
+ },
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 1536,
16
+ "label2id": {
17
+ "LABEL_0": 0
18
+ },
19
+ "layer_norm_eps": 1e-12,
20
+ "max_position_embeddings": 512,
21
+ "model_type": "bert",
22
+ "num_attention_heads": 12,
23
+ "num_hidden_layers": 12,
24
+ "pad_token_id": 0,
25
+ "position_embedding_type": "absolute",
26
+ "torch_dtype": "float32",
27
+ "transformers_version": "4.29.0",
28
+ "type_vocab_size": 2,
29
+ "use_cache": true,
30
+ "vocab_size": 30522
31
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.28.1",
5
+ "pytorch": "1.13.0+cu117"
6
+ }
7
+ }
config_setfit.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "labels": [
3
+ "no aspect",
4
+ "aspect"
5
+ ],
6
+ "span_context": 0,
7
+ "normalize_embeddings": false
8
+ }
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40981c12f3dc9655afbabd43a518ca9aaeb02bca44eb5812e3d98e8f04b90761
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
+ ]
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:053fcaf18552044f9fab2b6c2eccfceff2b5c353804ac31e4688befd443f7be5
3
+ size 133511213
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": true
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": true,
6
+ "mask_token": "[MASK]",
7
+ "model_max_length": 512,
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "strip_accents": null,
12
+ "tokenize_chinese_chars": true,
13
+ "tokenizer_class": "BertTokenizer",
14
+ "unk_token": "[UNK]"
15
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff