omymble commited on
Commit
169d5ac
1 Parent(s): b946900

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,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: sentence-transformers/all-MiniLM-L6-v2
3
+ library_name: setfit
4
+ metrics:
5
+ - accuracy
6
+ pipeline_tag: text-classification
7
+ tags:
8
+ - setfit
9
+ - absa
10
+ - sentence-transformers
11
+ - text-classification
12
+ - generated_from_setfit_trainer
13
+ widget:
14
+ - text: world:Though Arthur skips to another world, he's clearly from our own
15
+ - text: attire:Among those are the army of doglike and winged creatures, all dressed
16
+ in attire befitting a civilization one hundred and fifty years ago
17
+ - text: Mister Monday:This is a 361 page book about a boy named Arthur Penhaligon
18
+ who is destined to die an early death, but is saved by a key given to him by a
19
+ mysterious man named Mister Monday
20
+ - text: parents:Do their parents understand or even care about them? Are they ready
21
+ for sex? Meanwhile can Maggie and Dennis learn to communicate enough to stay together?
22
+ - text: boy:This is a 361 page book about a boy named Arthur Penhaligon who is destined
23
+ to die an early death, but is saved by a key given to him by a mysterious man
24
+ named Mister Monday
25
+ inference: false
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.8541666666666666
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_lg
64
+ - **SetFitABSA Aspect Model:** [omymble/setfit-absa-books-aspect](https://huggingface.co/omymble/setfit-absa-books-aspect)
65
+ - **SetFitABSA Polarity Model:** [omymble/setfit-absa-books-polarity](https://huggingface.co/omymble/setfit-absa-books-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>'Poirot:After reading nearly 30 novels, Poirot had been a part of life'</li><li>'Michael Dobbs:The cast of characters in this sweeping story by Michael Dobbs of political maneuvering, skullduggery, and backstabbing is an historical Who\'s Who of the times: the ailing, haughty, and pacifist Chamberlain, who personifies England\'s bitter memories of the Great War and the popular concept of "never again"; the ambitious and self-absorbed Churchill, whose pugnacity sometimes clouds prudence; the defeatist, philandering, and anti-Semitic U'</li><li>"Jack:Jack is a wonderful beleaguered hero who starts off by quickly realizing he don't know jack even about himself and as he investigates realizes each new clue proves he knows even less than he thought"</li></ul> |
82
+ | no aspect | <ul><li>'novels:After reading nearly 30 novels, Poirot had been a part of life'</li><li>'part:After reading nearly 30 novels, Poirot had been a part of life'</li><li>'life:After reading nearly 30 novels, Poirot had been a part of life'</li></ul> |
83
+
84
+ ## Evaluation
85
+
86
+ ### Metrics
87
+ | Label | Accuracy |
88
+ |:--------|:---------|
89
+ | **all** | 0.8542 |
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
+ "omymble/setfit-absa-books-aspect",
109
+ "omymble/setfit-absa-books-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 | 6 | 34.7122 | 79 |
145
+
146
+ | Label | Training Sample Count |
147
+ |:----------|:----------------------|
148
+ | no aspect | 280 |
149
+ | aspect | 57 |
150
+
151
+ ### Training Hyperparameters
152
+ - batch_size: (256, 256)
153
+ - num_epochs: (2, 2)
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
+ - seed: 42
165
+ - eval_max_steps: -1
166
+ - load_best_model_at_end: True
167
+
168
+ ### Training Results
169
+ | Epoch | Step | Training Loss | Validation Loss |
170
+ |:----------:|:-------:|:-------------:|:---------------:|
171
+ | 0.0031 | 1 | 0.3698 | - |
172
+ | 0.1558 | 50 | 0.3449 | 0.3303 |
173
+ | 0.3115 | 100 | 0.3032 | 0.294 |
174
+ | 0.4673 | 150 | 0.2878 | 0.266 |
175
+ | 0.6231 | 200 | 0.2414 | 0.2535 |
176
+ | 0.7788 | 250 | 0.2456 | 0.2494 |
177
+ | 0.9346 | 300 | 0.2374 | 0.2477 |
178
+ | 1.0903 | 350 | 0.2407 | 0.2472 |
179
+ | 1.2461 | 400 | 0.2406 | 0.2467 |
180
+ | 1.4019 | 450 | 0.2276 | 0.2465 |
181
+ | 1.5576 | 500 | 0.2248 | 0.2465 |
182
+ | 1.7134 | 550 | 0.2241 | 0.2464 |
183
+ | **1.8692** | **600** | **0.2245** | **0.2463** |
184
+
185
+ * The bold row denotes the saved checkpoint.
186
+ ### Framework Versions
187
+ - Python: 3.10.12
188
+ - SetFit: 1.0.3
189
+ - Sentence Transformers: 3.0.1
190
+ - spaCy: 3.7.4
191
+ - Transformers: 4.39.0
192
+ - PyTorch: 2.3.1+cu121
193
+ - Datasets: 2.20.0
194
+ - Tokenizers: 0.15.2
195
+
196
+ ## Citation
197
+
198
+ ### BibTeX
199
+ ```bibtex
200
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
201
+ doi = {10.48550/ARXIV.2209.11055},
202
+ url = {https://arxiv.org/abs/2209.11055},
203
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
204
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
205
+ title = {Efficient Few-Shot Learning Without Prompts},
206
+ publisher = {arXiv},
207
+ year = {2022},
208
+ copyright = {Creative Commons Attribution 4.0 International}
209
+ }
210
+ ```
211
+
212
+ <!--
213
+ ## Glossary
214
+
215
+ *Clearly define terms in order to be accessible across audiences.*
216
+ -->
217
+
218
+ <!--
219
+ ## Model Card Authors
220
+
221
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
222
+ -->
223
+
224
+ <!--
225
+ ## Model Card Contact
226
+
227
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
228
+ -->
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "models/step_600",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 384,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 1536,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 6,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.39.0",
23
+ "type_vocab_size": 2,
24
+ "use_cache": true,
25
+ "vocab_size": 30522
26
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "3.0.1",
4
+ "transformers": "4.39.0",
5
+ "pytorch": "2.3.1+cu121"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null,
9
+ "similarity_fn_name": null
10
+ }
config_setfit.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "labels": [
3
+ "no aspect",
4
+ "aspect"
5
+ ],
6
+ "spacy_model": "en_core_web_lg",
7
+ "span_context": 0,
8
+ "normalize_embeddings": false
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f00d224eafb5dc286689d6dcafbab4e9c1853b88e87f81f6180a412062a3dee
3
+ size 90864192
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:141850e6f5e5f6f58d5d1ea0c70ec56bd1fa53966e4935bc651df2fee7b1284c
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,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "mask_token": "[MASK]",
49
+ "max_length": 128,
50
+ "model_max_length": 256,
51
+ "never_split": null,
52
+ "pad_to_multiple_of": null,
53
+ "pad_token": "[PAD]",
54
+ "pad_token_type_id": 0,
55
+ "padding_side": "right",
56
+ "sep_token": "[SEP]",
57
+ "stride": 0,
58
+ "strip_accents": null,
59
+ "tokenize_chinese_chars": true,
60
+ "tokenizer_class": "BertTokenizer",
61
+ "truncation_side": "right",
62
+ "truncation_strategy": "longest_first",
63
+ "unk_token": "[UNK]"
64
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff