omymble commited on
Commit
f9f6a24
1 Parent(s): 3795466

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,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: be an absolute thrill to read when:Having said that, this must be an absolute
15
+ thrill to read when you're nine or ten
16
+ - text: market followed classical economic laws:Levi describes how the market followed
17
+ classical economic laws
18
+ - text: This fantasy will certainly hit:This fantasy will certainly hit the mark for
19
+ anyone who enjoys the genre
20
+ - text: a bit of brutal reality and a rape:There is quite a bit of brutal reality
21
+ and a rape too terrible to even think about, but Val McDermid has created characters
22
+ and a story that I just couldn't put down
23
+ - text: Kingston is no Steinem:Kingston is no Steinem and doesn't suggest that a woman
24
+ needs a man like a fish needs a bicycle (though she is unmarried)
25
+ inference: false
26
+ model-index:
27
+ - name: SetFit Polarity 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.7142857142857143
39
+ name: Accuracy
40
+ ---
41
+
42
+ # SetFit Polarity 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 classifying aspect polarities.
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 a SetFit model to filter these possible aspect span candidates.
55
+ 3. **Use this 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:** 3 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
+ | neutral | <ul><li>'30 novels, Poirot had been a:After reading nearly 30 novels, Poirot had been a part of life'</li><li>'sweeping story by Michael Dobbs of political maneuvering: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>', the "key" and ":When he recovers, the "key" and " A Compleat Atlas of The House" are still there'</li></ul> |
82
+ | positive | <ul><li>"Jack is a wonderful: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><li>'is a detailed biography of Alphonse Capone:This is a detailed biography of Alphonse Capone'</li><li>'to an undercover assignment:Carol is offered the bone of a possible promotion if she would agree to an undercover assignment'</li></ul> |
83
+ | negative | <ul><li>'making the entire killer plot read like an:The emotional connection between Hill and the killers in the two previous books is missing here, making the entire killer plot read like an afterthought'</li><li>'felt the whole story was pointless:In the end, I felt the whole story was pointless'</li><li>'Diabola becomes mad and:Diabola becomes mad and uses her powers to make their eyes sting'</li></ul> |
84
+
85
+ ## Evaluation
86
+
87
+ ### Metrics
88
+ | Label | Accuracy |
89
+ |:--------|:---------|
90
+ | **all** | 0.7143 |
91
+
92
+ ## Uses
93
+
94
+ ### Direct Use for Inference
95
+
96
+ First install the SetFit library:
97
+
98
+ ```bash
99
+ pip install setfit
100
+ ```
101
+
102
+ Then you can load this model and run inference.
103
+
104
+ ```python
105
+ from setfit import AbsaModel
106
+
107
+ # Download from the 🤗 Hub
108
+ model = AbsaModel.from_pretrained(
109
+ "omymble/setfit-absa-books-aspect",
110
+ "omymble/setfit-absa-books-polarity",
111
+ )
112
+ # Run inference
113
+ preds = model("The food was great, but the venue is just way too busy.")
114
+ ```
115
+
116
+ <!--
117
+ ### Downstream Use
118
+
119
+ *List how someone could finetune this model on their own dataset.*
120
+ -->
121
+
122
+ <!--
123
+ ### Out-of-Scope Use
124
+
125
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
126
+ -->
127
+
128
+ <!--
129
+ ## Bias, Risks and Limitations
130
+
131
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
132
+ -->
133
+
134
+ <!--
135
+ ### Recommendations
136
+
137
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
138
+ -->
139
+
140
+ ## Training Details
141
+
142
+ ### Training Set Metrics
143
+ | Training set | Min | Median | Max |
144
+ |:-------------|:----|:--------|:----|
145
+ | Word count | 9 | 30.2105 | 84 |
146
+
147
+ | Label | Training Sample Count |
148
+ |:---------|:----------------------|
149
+ | negative | 6 |
150
+ | neutral | 42 |
151
+ | positive | 9 |
152
+
153
+ ### Training Hyperparameters
154
+ - batch_size: (256, 256)
155
+ - num_epochs: (2, 2)
156
+ - max_steps: -1
157
+ - sampling_strategy: oversampling
158
+ - body_learning_rate: (2e-05, 1e-05)
159
+ - head_learning_rate: 0.01
160
+ - loss: CosineSimilarityLoss
161
+ - distance_metric: cosine_distance
162
+ - margin: 0.25
163
+ - end_to_end: False
164
+ - use_amp: True
165
+ - warmup_proportion: 0.1
166
+ - seed: 42
167
+ - eval_max_steps: -1
168
+ - load_best_model_at_end: True
169
+
170
+ ### Training Results
171
+ | Epoch | Step | Training Loss | Validation Loss |
172
+ |:-----:|:----:|:-------------:|:---------------:|
173
+ | 0.125 | 1 | 0.3786 | - |
174
+
175
+ ### Framework Versions
176
+ - Python: 3.10.12
177
+ - SetFit: 1.0.3
178
+ - Sentence Transformers: 3.0.1
179
+ - spaCy: 3.7.4
180
+ - Transformers: 4.39.0
181
+ - PyTorch: 2.3.1+cu121
182
+ - Datasets: 2.20.0
183
+ - Tokenizers: 0.15.2
184
+
185
+ ## Citation
186
+
187
+ ### BibTeX
188
+ ```bibtex
189
+ @article{https://doi.org/10.48550/arxiv.2209.11055,
190
+ doi = {10.48550/ARXIV.2209.11055},
191
+ url = {https://arxiv.org/abs/2209.11055},
192
+ author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
193
+ keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
194
+ title = {Efficient Few-Shot Learning Without Prompts},
195
+ publisher = {arXiv},
196
+ year = {2022},
197
+ copyright = {Creative Commons Attribution 4.0 International}
198
+ }
199
+ ```
200
+
201
+ <!--
202
+ ## Glossary
203
+
204
+ *Clearly define terms in order to be accessible across audiences.*
205
+ -->
206
+
207
+ <!--
208
+ ## Model Card Authors
209
+
210
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
211
+ -->
212
+
213
+ <!--
214
+ ## Model Card Contact
215
+
216
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
217
+ -->
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "sentence-transformers/all-MiniLM-L6-v2",
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,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "labels": [
3
+ "negative",
4
+ "neutral",
5
+ "positive"
6
+ ],
7
+ "spacy_model": "en_core_web_lg",
8
+ "span_context": 3,
9
+ "normalize_embeddings": false
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65031a1cafd75854a204400dd8ab3f8dca7545a1477bfc57a013841f6577effa
3
+ size 90864192
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac73b31d302189835ed41c787ef5ab3018489623693d09845757b4ac53d2c684
3
+ size 10159
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