Push model using huggingface_hub.
Browse files- 1_Pooling/config.json +3 -3
- README.md +94 -153
- config.json +9 -3
- model.safetensors +2 -2
- model_head.pkl +2 -2
- sentence_bert_config.json +2 -2
- tokenizer.json +1 -1
- tokenizer_config.json +3 -3
1_Pooling/config.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
-
"word_embedding_dimension":
|
| 3 |
-
"pooling_mode_cls_token":
|
| 4 |
-
"pooling_mode_mean_tokens":
|
| 5 |
"pooling_mode_max_tokens": false,
|
| 6 |
"pooling_mode_mean_sqrt_len_tokens": false,
|
| 7 |
"pooling_mode_weightedmean_tokens": false,
|
|
|
|
| 1 |
{
|
| 2 |
+
"word_embedding_dimension": 768,
|
| 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 |
"pooling_mode_weightedmean_tokens": false,
|
README.md
CHANGED
|
@@ -1,189 +1,130 @@
|
|
| 1 |
---
|
| 2 |
-
language:
|
| 3 |
-
- en
|
| 4 |
-
license: apache-2.0
|
| 5 |
-
library_name: setfit
|
| 6 |
tags:
|
| 7 |
- setfit
|
| 8 |
- sentence-transformers
|
| 9 |
- text-classification
|
| 10 |
-
-
|
| 11 |
-
|
| 12 |
-
pipeline_tag: text-classification
|
| 13 |
metrics:
|
| 14 |
- accuracy
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
model-index:
|
| 19 |
-
- name: SetFit Sentiment Analysis
|
| 20 |
-
results:
|
| 21 |
-
- task:
|
| 22 |
-
type: text-classification
|
| 23 |
-
name: Sentiment Analysis
|
| 24 |
-
metrics:
|
| 25 |
-
- name: Accuracy
|
| 26 |
-
type: accuracy
|
| 27 |
-
value: 0.81
|
| 28 |
-
- name: F1 (Weighted)
|
| 29 |
-
type: f1
|
| 30 |
-
value: 0.814252790996977
|
| 31 |
-
- name: Precision (Weighted)
|
| 32 |
-
type: precision
|
| 33 |
-
value: 0.8325319693094628
|
| 34 |
-
- name: Recall (Weighted)
|
| 35 |
-
type: recall
|
| 36 |
-
value: 0.81
|
| 37 |
---
|
| 38 |
|
| 39 |
-
# SetFit
|
| 40 |
-
|
| 41 |
-
This is a [SetFit](https://github.com/huggingface/setfit) model fine-tuned for sentiment classification on customer feedback data.
|
| 42 |
-
|
| 43 |
-
## Model Description
|
| 44 |
-
|
| 45 |
-
| Property | Value |
|
| 46 |
-
|----------|-------|
|
| 47 |
-
| **Base Model** | [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) |
|
| 48 |
-
| **Total Parameters** | 22,713,216 |
|
| 49 |
-
| **Trainable Parameters** | 22,713,216 |
|
| 50 |
-
| **Body Parameters** | 22,713,216 |
|
| 51 |
-
| **Head Parameters** | 0 |
|
| 52 |
-
| **Model Size** | 86.64 MB |
|
| 53 |
-
| **Labels** | [0, 1, 2, 3, 4] |
|
| 54 |
-
| **Number of Classes** | 5 |
|
| 55 |
-
| **Serialization** | safetensors |
|
| 56 |
-
|
| 57 |
-
## Training Configuration
|
| 58 |
-
|
| 59 |
-
| Parameter | Value |
|
| 60 |
-
|-----------|-------|
|
| 61 |
-
| **Batch Size** | 16 |
|
| 62 |
-
| **Epochs** | [1, 16] |
|
| 63 |
-
| **Training Samples** | 540 |
|
| 64 |
-
| **Test Samples** | 100 |
|
| 65 |
-
| **Loss Function** | CosineSimilarityLoss |
|
| 66 |
-
| **Metric for Best Model** | embedding_loss |
|
| 67 |
-
|
| 68 |
-
### Training Progress
|
| 69 |
-
|
| 70 |
-
- **Initial Loss:** 0.4661
|
| 71 |
-
- **Final Loss:** 0.1370
|
| 72 |
-
- **Eval Loss:** 0.1149
|
| 73 |
-
- **Training Runtime:** 594.1215 seconds
|
| 74 |
-
- **Samples/Second:** 18.1780
|
| 75 |
-
|
| 76 |
-
## Evaluation Results
|
| 77 |
-
|
| 78 |
-
| Metric | Score |
|
| 79 |
-
|--------|-------|
|
| 80 |
-
| **Accuracy** | 0.8100 |
|
| 81 |
-
| **F1 (Weighted)** | 0.8143 |
|
| 82 |
-
| **F1 (Macro)** | 0.8143 |
|
| 83 |
-
| **Precision (Weighted)** | 0.8325 |
|
| 84 |
-
| **Precision (Macro)** | 0.8325 |
|
| 85 |
-
| **Recall (Weighted)** | 0.8100 |
|
| 86 |
-
| **Recall (Macro)** | 0.8100 |
|
| 87 |
-
|
| 88 |
-
### Per-Class Performance
|
| 89 |
|
| 90 |
-
|
| 91 |
-
precision recall f1-score support
|
| 92 |
|
| 93 |
-
|
| 94 |
-
1 0.60 0.75 0.67 20
|
| 95 |
-
2 0.74 0.85 0.79 20
|
| 96 |
-
3 1.00 0.75 0.86 20
|
| 97 |
-
4 1.00 1.00 1.00 20
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
weighted avg 0.83 0.81 0.81 100
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
##
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
</p>
|
| 111 |
|
| 112 |
-
##
|
| 113 |
-
<p align="center">
|
| 114 |
-
<img src="confusion_matrix.png" alt="Confusion Matrix" width="600"/>
|
| 115 |
-
</p>
|
| 116 |
|
| 117 |
-
###
|
| 118 |
-
<p align="center">
|
| 119 |
-
<img src="loss_curve.png" alt="Training Loss Curve" width="600"/>
|
| 120 |
-
</p>
|
| 121 |
|
| 122 |
-
|
| 123 |
-
<p align="center">
|
| 124 |
-
<img src="learning_rate.png" alt="Learning Rate Schedule" width="600"/>
|
| 125 |
-
</p>
|
| 126 |
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
```python
|
| 130 |
from setfit import SetFitModel
|
| 131 |
|
| 132 |
-
#
|
| 133 |
-
model = SetFitModel.from_pretrained("
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
text = "This product exceeded my expectations!"
|
| 137 |
-
prediction = model.predict([text])
|
| 138 |
-
print(f"Sentiment: {prediction[0]}")
|
| 139 |
-
|
| 140 |
-
# Batch prediction
|
| 141 |
-
texts = [
|
| 142 |
-
"Amazing quality, highly recommend!",
|
| 143 |
-
"It's okay, nothing special.",
|
| 144 |
-
"Terrible experience, very disappointed.",
|
| 145 |
-
]
|
| 146 |
-
predictions = model.predict(texts)
|
| 147 |
-
probabilities = model.predict_proba(texts)
|
| 148 |
-
|
| 149 |
-
for text, pred, prob in zip(texts, predictions, probabilities):
|
| 150 |
-
print(f"Text: {text}")
|
| 151 |
-
print(f" Prediction: {pred}, Confidence: {max(prob):.2%}")
|
| 152 |
```
|
| 153 |
|
| 154 |
-
|
|
|
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
| 0 | Negative |
|
| 159 |
-
| 1 | Somewhat Negative |
|
| 160 |
-
| 2 | Neutral |
|
| 161 |
-
| 3 | Somewhat Positive |
|
| 162 |
-
| 4 | Positive |
|
| 163 |
|
| 164 |
-
|
|
|
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
| Python | 3.11.14 |
|
| 169 |
-
| SetFit | 1.1.3 |
|
| 170 |
-
| PyTorch | 2.9.1 |
|
| 171 |
-
| scikit-learn | 1.8.0 |
|
| 172 |
-
| Transformers | N/A |
|
| 173 |
|
| 174 |
-
|
|
|
|
| 175 |
|
| 176 |
-
|
|
|
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
```bibtex
|
| 179 |
-
@article{
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
}
|
| 185 |
```
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
| 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 [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) 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 [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
|
| 30 |
+
- **Maximum Sequence Length:** 512 tokens
|
| 31 |
+
- **Number of Classes:** 5 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.14
|
| 91 |
+
- SetFit: 1.1.3
|
| 92 |
+
- Sentence Transformers: 5.2.0
|
| 93 |
+
- Transformers: 4.57.5
|
| 94 |
+
- PyTorch: 2.9.1
|
| 95 |
+
- Datasets: 4.4.2
|
| 96 |
+
- Tokenizers: 0.22.2
|
| 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 |
+
-->
|
config.json
CHANGED
|
@@ -8,14 +8,20 @@
|
|
| 8 |
"gradient_checkpointing": false,
|
| 9 |
"hidden_act": "gelu",
|
| 10 |
"hidden_dropout_prob": 0.1,
|
| 11 |
-
"hidden_size":
|
|
|
|
|
|
|
|
|
|
| 12 |
"initializer_range": 0.02,
|
| 13 |
-
"intermediate_size":
|
|
|
|
|
|
|
|
|
|
| 14 |
"layer_norm_eps": 1e-12,
|
| 15 |
"max_position_embeddings": 512,
|
| 16 |
"model_type": "bert",
|
| 17 |
"num_attention_heads": 12,
|
| 18 |
-
"num_hidden_layers":
|
| 19 |
"pad_token_id": 0,
|
| 20 |
"position_embedding_type": "absolute",
|
| 21 |
"transformers_version": "4.57.5",
|
|
|
|
| 8 |
"gradient_checkpointing": false,
|
| 9 |
"hidden_act": "gelu",
|
| 10 |
"hidden_dropout_prob": 0.1,
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "LABEL_0"
|
| 14 |
+
},
|
| 15 |
"initializer_range": 0.02,
|
| 16 |
+
"intermediate_size": 3072,
|
| 17 |
+
"label2id": {
|
| 18 |
+
"LABEL_0": 0
|
| 19 |
+
},
|
| 20 |
"layer_norm_eps": 1e-12,
|
| 21 |
"max_position_embeddings": 512,
|
| 22 |
"model_type": "bert",
|
| 23 |
"num_attention_heads": 12,
|
| 24 |
+
"num_hidden_layers": 12,
|
| 25 |
"pad_token_id": 0,
|
| 26 |
"position_embedding_type": "absolute",
|
| 27 |
"transformers_version": "4.57.5",
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e7ebb39c9b6f04b72a435dd467d6e4a6f8da9a408fdc023095d39b52b19a6601
|
| 3 |
+
size 437951328
|
model_head.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e36d4eac37889fc53236f989c8cd99a56b01cb93c4aa604178f503c6f52f5388
|
| 3 |
+
size 31647
|
sentence_bert_config.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"max_seq_length":
|
| 3 |
-
"do_lower_case":
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"max_seq_length": 512,
|
| 3 |
+
"do_lower_case": true
|
| 4 |
}
|
tokenizer.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"version": "1.0",
|
| 3 |
"truncation": {
|
| 4 |
"direction": "Right",
|
| 5 |
-
"max_length":
|
| 6 |
"strategy": "LongestFirst",
|
| 7 |
"stride": 0
|
| 8 |
},
|
|
|
|
| 2 |
"version": "1.0",
|
| 3 |
"truncation": {
|
| 4 |
"direction": "Right",
|
| 5 |
+
"max_length": 512,
|
| 6 |
"strategy": "LongestFirst",
|
| 7 |
"stride": 0
|
| 8 |
},
|
tokenizer_config.json
CHANGED
|
@@ -41,14 +41,14 @@
|
|
| 41 |
"special": true
|
| 42 |
}
|
| 43 |
},
|
| 44 |
-
"clean_up_tokenization_spaces":
|
| 45 |
"cls_token": "[CLS]",
|
| 46 |
"do_basic_tokenize": true,
|
| 47 |
"do_lower_case": true,
|
| 48 |
"extra_special_tokens": {},
|
| 49 |
"mask_token": "[MASK]",
|
| 50 |
-
"max_length":
|
| 51 |
-
"model_max_length":
|
| 52 |
"never_split": null,
|
| 53 |
"pad_to_multiple_of": null,
|
| 54 |
"pad_token": "[PAD]",
|
|
|
|
| 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 |
"extra_special_tokens": {},
|
| 49 |
"mask_token": "[MASK]",
|
| 50 |
+
"max_length": 512,
|
| 51 |
+
"model_max_length": 512,
|
| 52 |
"never_split": null,
|
| 53 |
"pad_to_multiple_of": null,
|
| 54 |
"pad_token": "[PAD]",
|