haukelicht commited on
Commit
4bf3de8
·
verified ·
1 Parent(s): 795254c

used native setfit head

Browse files
Files changed (2) hide show
  1. README.md +124 -87
  2. model_head.pkl +1 -1
README.md CHANGED
@@ -1,130 +1,167 @@
1
  ---
2
- tags:
3
- - setfit
4
- - sentence-transformers
5
- - text-classification
6
- - generated_from_setfit_trainer
7
- widget: []
8
- metrics:
9
- - accuracy
10
- pipeline_tag: text-classification
11
- library_name: setfit
12
- inference: true
 
 
 
 
 
 
 
 
 
 
 
13
  ---
14
 
15
- # SetFit
16
 
17
- This is a [SetFit](https://github.com/huggingface/setfit) model that can be used for Text Classification. A SetFitHeadWithClassWeights instance is used for classification.
18
 
19
- The model has been trained using an efficient few-shot learning technique that involves:
20
 
21
- 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
22
- 2. Training a classification head with features from the fine-tuned Sentence Transformer.
 
 
 
 
 
 
23
 
24
  ## Model Details
25
 
26
  ### Model Description
27
- - **Model Type:** SetFit
28
- <!-- - **Sentence Transformer:** [Unknown](https://huggingface.co/unknown) -->
29
- - **Classification head:** a SetFitHeadWithClassWeights instance
30
- - **Maximum Sequence Length:** 384 tokens
31
- - **Number of Classes:** 6 classes
32
- <!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
33
- <!-- - **Language:** Unknown -->
34
- <!-- - **License:** Unknown -->
 
35
 
36
  ### Model Sources
37
 
38
- - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
39
- - **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
40
- - **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
41
 
42
  ## Uses
43
 
44
- ### Direct Use for Inference
45
 
46
- First install the SetFit library:
 
 
47
 
48
- ```bash
49
- pip install setfit
50
- ```
 
 
 
51
 
52
- Then you can load this model and run inference.
 
 
 
 
 
 
 
 
53
 
54
  ```python
 
55
  from setfit import SetFitModel
56
 
57
- # Download from the 🤗 Hub
58
- model = SetFitModel.from_pretrained("setfit_model_id")
59
- # Run inference
60
- preds = model("I loved the spiderman movie!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  ```
62
 
63
- <!--
64
- ### Downstream Use
 
 
 
65
 
66
- *List how someone could finetune this model on their own dataset.*
67
- -->
68
 
69
- <!--
70
- ### Out-of-Scope Use
71
 
72
- *List how the model may foreseeably be misused and address what users ought not to do with the model.*
73
- -->
74
 
75
- <!--
76
- ## Bias, Risks and Limitations
 
77
 
78
- *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
79
- -->
80
 
81
- <!--
82
- ### Recommendations
83
 
84
- *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
85
- -->
86
 
87
- ## Training Details
88
 
89
- ### Framework Versions
90
- - Python: 3.11.11
91
- - SetFit: 1.1.2
92
- - Sentence Transformers: 5.1.0
93
- - Transformers: 4.57.1
94
- - PyTorch: 2.6.0+cu124
95
- - Datasets: 3.5.0
96
- - Tokenizers: 0.22.1
97
 
98
- ## Citation
 
 
 
 
 
99
 
100
- ### BibTeX
101
- ```bibtex
102
- @article{https://doi.org/10.48550/arxiv.2209.11055,
103
- doi = {10.48550/ARXIV.2209.11055},
104
- url = {https://arxiv.org/abs/2209.11055},
105
- author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
106
- keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
107
- title = {Efficient Few-Shot Learning Without Prompts},
108
- publisher = {arXiv},
109
- year = {2022},
110
- copyright = {Creative Commons Attribution 4.0 International}
111
- }
112
- ```
113
 
114
- <!--
115
- ## Glossary
116
 
117
- *Clearly define terms in order to be accessible across audiences.*
118
- -->
119
 
120
- <!--
121
- ## Model Card Authors
122
 
123
- *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
124
- -->
125
 
126
- <!--
127
  ## Model Card Contact
128
 
129
- *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
130
- -->
 
1
  ---
2
+ base_model: sentence-transformers/all-mpnet-base-v2
3
+ language:
4
+ - en
5
+ license: apache-2.0
6
+ tags:
7
+ - economic-attributes
8
+ - mention-classification
9
+ - mpnet-base-v2
10
+ - setfit
11
+ - multi-label-classification
12
+ model-index:
13
+ - name: all-mpnet-base-v2_economic-attributes-classifier
14
+ results:
15
+ - task:
16
+ type: multi-label-classification
17
+ name: Multi-label classification
18
+ metrics:
19
+ - type: _tba_
20
+ value: -1.0
21
+ dataset:
22
+ type: custom
23
+ name: custom human-labeled multi-label annotation dataset
24
  ---
25
 
26
+ # Group mention economic attributes classifier
27
 
28
+ A multi-label classifier for detecting **economic attribute** categories referred to in a social group mention, trained with `setfit` based on the light-weight [`sentence-transformers/all-mpnet-base-v2`](https://huggingface.co/sentence-transformers/all-mpnet-base-v2) sentence embedding model.
29
 
30
+ The economic attributes classified are:
31
 
32
+ | attribute | definition |
33
+ |:------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
34
+ | class membership | People described with their membership in or belonging to a social class such as the upper class, the middle class, lower class, or the working class. |
35
+ | employment status | People described or categorized by their employment status such as employers, employees, self-employed, or unemployed people. |
36
+ | education level | People described with or categorized by their education level such as students, apprentices, higher education, tertiary education, vocational training or graduates. |
37
+ | income/wealth/economic status | People defined or categorized by their income, wealth, or economic status such as high/medium/low income groups, rich/poor people, homeowners/tenants/homeless. |
38
+ | occupation/profession | People referred to with or categorized according to their occupation or profession such as teachers, farmers, public servants, police officers |
39
+ | ecology of group | People categorized by their relation to the ecology of society such as carbon emitters, coal miners, green employers, green workers, sustainable farmers, those working in the fossil sector |
40
 
41
  ## Model Details
42
 
43
  ### Model Description
44
+
45
+ Group mention economic attributes classifier
46
+
47
+ - **Developed by:** Hauke Licht
48
+ - **Model type:** mpnet
49
+ - **Language(s) (NLP):** ['en']
50
+ - **License:** apache-2.0
51
+ - **Finetuned from model:** sentence-transformers/all-mpnet-base-v2
52
+ - **Funded by:** The *Deutsche Forschungsgemeinschaft* (DFG, German Research Foundation) under Germany's Excellence Strategy – EXC 2126/1 – 390838866
53
 
54
  ### Model Sources
55
 
56
+ - **Repository:** _tba_
57
+ - **Paper:** _tba_
58
+ - **Demo:** [More Information Needed]
59
 
60
  ## Uses
61
 
62
+ ### Bias, Risks, and Limitations
63
 
64
+ - Evaluation of the classifier in held-out data shows that it makes mistakes.
65
+ - The model has been finetuned only on human-annotated labeled social group mentions recorded in sentences sampled from party manifestos of European parties (mostly far-right and Green parties). Applying the classifier in other domains can lead to higher error rates.
66
+ - The data used to finetune the model come from human annotators. Human annotators can be biased and factors like gender and social background can impact their annotations judgments. This may lead to bias in the detection of specific social groups.
67
 
68
+ #### Recommendations
69
+
70
+ - Users who want to apply the model outside its training data domain should evaluate its performance in the target data.
71
+ - Users who want to apply the model outside its training data domain should contuninue to finetune this model on labeled data.
72
+
73
+ ### How to Get Started with the Model
74
 
75
+ Use the code below to get started with the model.
76
+
77
+ ## Usage
78
+
79
+ You can use the model with the [`setfit` python library](https://github.com/huggingface/setfit) (>=1.1.0):
80
+
81
+ *Note:* It is recommended to use transformers version >=4.5.5,<=5.0.0 and sentence-transformers version >=4.0.1,<=5.1.0 for compatibility.
82
+
83
+ ### Classification
84
 
85
  ```python
86
+ import torch
87
  from setfit import SetFitModel
88
 
89
+ model_name = "haukelicht/all-mpnet-base-v2_economic-attributes-classifier"
90
+ device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
91
+ classifier = SetFitModel.from_pretrained(model_name)
92
+ classifier.to(device);
93
+
94
+ # Example mentions
95
+ mentions = ["working class people", "highly-educated professionals", "people without a stable job"]
96
+
97
+ # Get predictions
98
+ predictions = classifier.predict(mentions)
99
+ print(predictions)
100
+
101
+ # Map predictions to labels
102
+ [
103
+ [
104
+ classifier.id2label[l]
105
+ for l, p in enumerate(pred) if p==1
106
+ ]
107
+ for pred in predictions
108
+ ]
109
  ```
110
 
111
+ ### Mention embedding
112
+
113
+ ```python
114
+ import torch
115
+ from sentence_transformers import SentenceTransformer
116
 
117
+ model_name = "haukelicht/all-mpnet-base-v2_economic-attributes-classifier"
118
+ device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
119
 
120
+ # Load the sentence transformer component of the pre-trained classifier
121
+ model = SentenceTransformer(model_name, device=device)
122
 
123
+ # Example mentions
124
+ mentions = ["working class people", "highly-educated professionals", "people without a stable job"]
125
 
126
+ # Compute mention embeddings
127
+ embeddings = model.encode(mentions)
128
+ ````
129
 
130
+ ## Training Details
 
131
 
132
+ ### Training Data
 
133
 
134
+ The train, dev, and test splits used for model finetuning and evaluation will be made available on Github upon publication of the associated research paper.
 
135
 
136
+ ### Training Procedure
137
 
138
+ #### Training Hyperparameters
 
 
 
 
 
 
 
139
 
140
+ - num epochs: (1, 4)
141
+ - train batch sizes: (16, 4)
142
+ - body train max teps: 100
143
+ - head learning rate: 0.030
144
+ - L2 weight: 0.015
145
+ - warmup proportion: 0.10
146
 
147
+ ## Evaluation
148
+
149
+ ### Testing Data, Factors & Metrics
150
+
151
+ #### Testing Data
152
+
153
+ The train, dev, and test splits used for model finetuning and evaluation will be made available on Github upon publication of the associated research paper.
154
+
155
+ ## Citation
 
 
 
 
156
 
157
+ **BibTeX:**
 
158
 
159
+ [More Information Needed]
 
160
 
161
+ **APA:**
 
162
 
163
+ [More Information Needed]
 
164
 
 
165
  ## Model Card Contact
166
 
167
+ hauke.licht@uibk.ac.at
 
model_head.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f807412922211387c9a5a35f52871c550b700f3e14d1a5b58d383ef4b56eaea8
3
  size 19966
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9109b9e144d648da1fbf0bc4024c61799e143a852eed3d19a1f51e45878803fc
3
  size 19966