
# SetFit

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.

The model has been trained using an efficient few-shot learning technique that involves:

1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
2. Training a classification head with features from the fine-tuned Sentence Transformer.

## Model Details

### Model Description
- **Model Type:** SetFit
<!-- - **Sentence Transformer:** [Unknown](https://huggingface.co/unknown) -->
- **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
- **Maximum Sequence Length:** 512 tokens
- **Number of Classes:** 4 classes
<!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
<!-- - **Language:** Unknown -->
<!-- - **License:** Unknown -->

### Model Sources

- **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
- **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
- **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)

### Model Labels
| Label | Examples                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
|:------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| loc4  | <ul><li>'flatness'</li><li>'it would seem the moments that the centre and falls away and the self comes more less and less that'</li><li>'so and then in addition to other more percent changes in perception and a very deep layer four type experiences that youre reporting'</li></ul>                                                                                                                                                                              |
| loc1  | <ul><li>'layer one you can get a feel for is this a useful thing or would i prefer to have you know access to something like layer one from somewhere else whether a more awareness'</li><li>'mean was the anger'</li><li>'up through that location layer one'</li></ul>                                                                                                                                                                                               |
| loc2  | <ul><li>'s im not im not you know concluding this yet but it does look like that that description is more layer two'</li><li>'layer two more spacious more distance more space around thoughts and emotions type of thing um'</li><li>'what you what youre describing by stepping back may be placing more attention on the layer two qualities that are also in your experience or it might be some shift in terms of where your sense of self is centered'</li></ul> |
| loc3  | <ul><li>'sense of fullness'</li><li>'so you can sort of sink into deeper layers if you want of layer three where that center starts to drop away um and is there a what is the experience of stillness or silence um at layer three for you'</li><li>'is everything'</li></ul>                                                                                                                                                                                         |

## Evaluation

### Metrics
| Label   | Accuracy |
|:--------|:---------|
| **all** | 0.5636   |

## Uses

### Direct Use for Inference

First install the SetFit library:

```bash
pip install setfit
```

Then you can load this model and run inference.

```python
from setfit import SetFitModel

# Download from the 🤗 Hub
model = SetFitModel.from_pretrained("jam1599/bert-text-classification-layers-p5")
# Run inference
preds = model("spaciousness")
```

<!--
### Downstream Use

*List how someone could finetune this model on their own dataset.*
-->

<!--
### Out-of-Scope Use

*List how the model may foreseeably be misused and address what users ought not to do with the model.*
-->

<!--
## Bias, Risks and Limitations

*What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
-->

<!--
### Recommendations

*What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
-->

## Training Details

### Training Set Metrics
| Training set | Min | Median | Max |
|:-------------|:----|:-------|:----|
| Word count   | 1   | 21.275 | 87  |

| Label | Training Sample Count |
|:------|:----------------------|
| loc1  | 10                    |
| loc2  | 10                    |
| loc3  | 10                    |
| loc4  | 10                    |
| loc5  | 0                     |
| loc5+ | 0                     |

### Training Hyperparameters
- batch_size: (16, 16)
- num_epochs: (4, 4)
- max_steps: -1
- sampling_strategy: oversampling
- body_learning_rate: (2e-05, 1e-05)
- head_learning_rate: 0.01
- loss: CosineSimilarityLoss
- distance_metric: cosine_distance
- margin: 0.25
- end_to_end: False
- use_amp: False
- warmup_proportion: 0.1
- seed: 42
- eval_max_steps: -1
- load_best_model_at_end: True

### Training Results
| Epoch   | Step   | Training Loss | Validation Loss |
|:-------:|:------:|:-------------:|:---------------:|
| 0.0133  | 1      | 0.3239        | -               |
| 0.6667  | 50     | 0.202         | -               |
| **1.0** | **75** | **-**         | **0.2364**      |
| 1.3333  | 100    | 0.0948        | -               |
| 2.0     | 150    | 0.0015        | 0.2611          |
| 2.6667  | 200    | 0.0007        | -               |
| 3.0     | 225    | -             | 0.2612          |
| 3.3333  | 250    | 0.0007        | -               |
| 4.0     | 300    | 0.0006        | 0.2599          |

* The bold row denotes the saved checkpoint.
### Framework Versions
- Python: 3.10.12
- SetFit: 1.0.3
- Sentence Transformers: 2.2.2
- Transformers: 4.35.2
- PyTorch: 2.1.0+cu121
- Datasets: 2.16.1
- Tokenizers: 0.15.0

## Citation

### BibTeX
```bibtex
@article{https://doi.org/10.48550/arxiv.2209.11055,
    doi = {10.48550/ARXIV.2209.11055},
    url = {https://arxiv.org/abs/2209.11055},
    author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
    keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
    title = {Efficient Few-Shot Learning Without Prompts},
    publisher = {arXiv},
    year = {2022},
    copyright = {Creative Commons Attribution 4.0 International}
}
```

<!--
## Glossary

*Clearly define terms in order to be accessible across audiences.*
-->

<!--
## Model Card Authors

*Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
-->

<!--
## Model Card Contact

*Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
-->
{"library_name": "setfit", "tags": ["setfit", "sentence-transformers", "text-classification", "generated_from_setfit_trainer"], "metrics": ["accuracy"], "widget": [{"text": "from layer three most of the time"}, {"text": " i think thats maybe why layer two seems less familiar"}, {"text": "spaciousness"}, {"text": "like disapproval like i noticed that i kind of had a lot of these disapproval patterns of myself and so i started noticing them more and kind of like just kind of letting them go so maybe that was a big shift and now more recently ive been noticing that there is a lot of this anxiety kind of pattern that feels like a its like a performance type anxiety or like approval type of thing and that comes up like really a lot every day yeah so yeah so thats like thats dropping me down to layer one often"}, {"text": "centerless or boldness"}], "pipeline_tag": "text-classification", "inference": true, "model-index": [{"name": "SetFit", "results": [{"task": {"type": "text-classification", "name": "Text Classification"}, "dataset": {"name": "Unknown", "type": "unknown", "split": "test"}, "metrics": [{"type": "accuracy", "value": 0.5636363636363636, "name": "Accuracy"}]}]}]}
setfit safetensors bert sentence-transformers text-classification generated_from_setfit_trainer arxiv:2209.11055 model-index has_space region:us