---
tags:
- setfit
- sentence-transformers
- text-classification
- generated_from_setfit_trainer
widget:
- text: 'Code Is an Afterthought [source: Hacker News] [topic: engineering]'
- text: 'Iran has accepted terms of ceasefire, per NYT www.... [source: bluesky links]
[topic: feeds]'
- text: 'Someone at BrowserStack is Leaking Users'' Email Address [source: Terence
Eden''s Blog] [topic: engineering]'
- text: 'Touchscreens expose a major spatial reasoning gap in LLM agents [source:
Reddit Home] [topic: AI]'
- text: 'New Strides Made on Deceptively Simple ''Lonely Runner'' Problem [source:
Hacker News: Newest] [topic: other]'
metrics:
- accuracy
pipeline_tag: text-classification
library_name: setfit
inference: true
base_model: sentence-transformers/all-MiniLM-L6-v2
---
# SetFit with sentence-transformers/all-MiniLM-L6-v2
This is a [SetFit](https://github.com/huggingface/setfit) model that can be used for Text Classification. 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.
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 body:** [sentence-transformers/all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)
- **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
- **Maximum Sequence Length:** 256 tokens
- **Number of Classes:** 2 classes
### 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 |
|:------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0 |
- 'Sad Story of My Google Workspace Account Suspension [source: Hacker News] [topic: engineering]'
- '“CEO said a thing!” [source: marcus-on-ai] [topic: Leadership / Corporate Culture]'
- 'How to Be Silicon Valley [source: Paul Graham: Essays] [topic: startup]'
|
| 1 | - 'Organizing in Hard Times: Lessons from Read This When Things Fall Apart [source: bluesky links] [topic: leadership|philosophy|startup]'
- 'Iran-Linked Hackers Sabotaging US Energy and Water Infrastructure [source: bluesky links] [topic: security]'
- 'Live Rocket Telemetry and Logging in Two Weeks [source: Hacker News] [topic: Observability / Telemetry]'
|
## 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("setfit_model_id")
# Run inference
preds = model("Code Is an Afterthought [source: Hacker News] [topic: engineering]")
```
## Training Details
### Training Set Metrics
| Training set | Min | Median | Max |
|:-------------|:----|:--------|:----|
| Word count | 6 | 12.5652 | 27 |
| Label | Training Sample Count |
|:------|:----------------------|
| 0 | 87 |
| 1 | 74 |
### Training Hyperparameters
- batch_size: (16, 16)
- num_epochs: (1, 1)
- max_steps: -1
- sampling_strategy: oversampling
- num_iterations: 20
- 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
- l2_weight: 0.01
- seed: 42
- evaluation_strategy: epoch
- eval_max_steps: -1
- load_best_model_at_end: True
### Training Results
| Epoch | Step | Training Loss | Validation Loss |
|:------:|:----:|:-------------:|:---------------:|
| 0.0025 | 1 | 0.4129 | - |
| 0.1241 | 50 | 0.2716 | - |
| 0.2481 | 100 | 0.2432 | - |
| 0.3722 | 150 | 0.2218 | - |
| 0.4963 | 200 | 0.1869 | - |
| 0.6203 | 250 | 0.1302 | - |
| 0.7444 | 300 | 0.0617 | - |
| 0.8685 | 350 | 0.0343 | - |
| 0.9926 | 400 | 0.022 | - |
| 1.0 | 403 | - | 0.2546 |
### Framework Versions
- Python: 3.13.9
- SetFit: 1.1.3
- Sentence Transformers: 5.4.0
- Transformers: 4.50.3
- PyTorch: 2.11.0
- Datasets: 4.8.4
- Tokenizers: 0.21.4
## 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}
}
```