Text Classification
setfit
Safetensors
sentence-transformers
English
bert
spam-detection
email-classification
few-shot-learning
efficient
tinymodels
text-embeddings-inference
Instructions to use TinyModels/Setfit-Banking-Spam with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- setfit
How to use TinyModels/Setfit-Banking-Spam with setfit:
from setfit import SetFitModel model = SetFitModel.from_pretrained("TinyModels/Setfit-Banking-Spam") preds = model.predict(["i loved the spiderman movie!", "pineapple on pizza is the worst"]) print(preds) - sentence-transformers
How to use TinyModels/Setfit-Banking-Spam with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("TinyModels/Setfit-Banking-Spam") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
|
Download README.md from TinyModels/Setfit-Banking-Spam: direct link, hf CLI and curl.
- Browser
- Download file 9.93 kB
-
https://huggingface.co/TinyModels/Setfit-Banking-Spam/resolve/main/README.md
- Command line
-
hf download hf://TinyModels/Setfit-Banking-Spam/README.md
-
curl -L -o README.md https://huggingface.co/TinyModels/Setfit-Banking-Spam/resolve/main/README.md
9.93 kB
| license: apache-2.0 | |
| language: | |
| - en | |
| tags: | |
| - setfit | |
| - sentence-transformers | |
| - text-classification | |
| - spam-detection | |
| - email-classification | |
| - few-shot-learning | |
| - efficient | |
| - tinymodels | |
| pipeline_tag: text-classification | |
| library_name: setfit | |
| base_model: BAAI/bge-small-en-v1.5 | |
| datasets: | |
| - SetFit/enron_spam | |
| <div align="center"> | |
| <img src="https://readme-typing-svg.demolab.com?font=JetBrains+Mono&size=30&duration=2500&pause=700&color=FF0080¢er=true&vCenter=true&width=650&lines=%E2%9A%A1+TinyModels;SetFit+%C2%B7+Spam+Detection;16+Examples+%E2%86%92+Classifier;Small+Model.+Real+Task." alt="TinyModels animated header"> | |
| <br> | |
| <img src="https://img.shields.io/badge/TinyModels-FF0080?style=for-the-badge&logoColor=white"> | |
| <img src="https://img.shields.io/badge/SetFit-7928CA?style=for-the-badge"> | |
| <img src="https://img.shields.io/badge/2--Class-Text%20Classification-FF0080?style=for-the-badge"> | |
| <img src="https://img.shields.io/badge/Few--Shot-Training-7928CA?style=for-the-badge"> | |
| <img src="https://img.shields.io/badge/Apache%202.0-000000?style=for-the-badge"> | |
| <br><br> | |
| ### ๐ง Tiny model. Tiny dataset. Real classification. | |
| A compact **few-shot spam classifier** built with | |
| **SetFit + BAAI/bge-small-en-v1.5**. | |
| </div> | |
| --- | |
| <div align="center"> | |
| ## โก `TINY โ FAST โ USEFUL` | |
| </div> | |
| This model is a small experiment in **few-shot text classification**. | |
| It learns to separate: | |
| > โ๏ธ **HAM** โ legitimate email | |
| > ๐จ **SPAM** โ unwanted / suspicious email | |
| The interesting part? | |
| **Only 16 labeled training examples.** | |
| ```text | |
| โโโโโโโโโโโโโโโโโโโโโโโโ | |
| โ 16 EXAMPLES โ | |
| โ โ | |
| โ 8 HAM + 8 SPAM โ | |
| โโโโโโโโโโโโฌโโโโโโโโโโโโ | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโโโโโโโโ | |
| โ BAAI/bge-small-en-v1.5โ | |
| โโโโโโโโโโโโโฌโโโโโโโโโโโโ | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโ | |
| โ SetFit โ | |
| โ Few-shot NLP โ | |
| โโโโโโโโโฌโโโโโโโโโ | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโโโโโโโโ | |
| โ Logistic Regression โ | |
| โโโโโโโโโโโโโฌโโโโโโโโโโโโ | |
| โ | |
| โโโโโโโโดโโโโโโโ | |
| โผ โผ | |
| HAM SPAM | |
| ``` | |
| --- | |
| # ๐ก Model Status | |
| <div align="center"> | |
| | โ๏ธ Component | ๐ง Configuration | | |
| | ----------------------- | ------------------------ | | |
| | **Task** | Spam Classification | | |
| | **Classes** | `2` | | |
| | **Backbone** | `BAAI/bge-small-en-v1.5` | | |
| | **Framework** | SetFit | | |
| | **Dataset** | `SetFit/enron_spam` | | |
| | **Training Examples** | `16` | | |
| | **Examples / Class** | `8` | | |
| | **Iterations** | `20` | | |
| | **Epochs** | `1` | | |
| | **Batch Size** | `16` | | |
| | **Classification Head** | Logistic Regression | | |
| | **Language** | English | | |
| </div> | |
| --- | |
| # ๐ Results | |
| <div align="center"> | |
| ### `91.4%` Accuracy | |
| ### `91.4%` Macro F1 | |
| <br> | |
| ```text | |
| Accuracy โโโโโโโโโโโโโโโโโโโโ 91.4% | |
| Macro F1 โโโโโโโโโโโโโโโโโโโโ 91.4% | |
| ``` | |
| </div> | |
| > These results come from a very small few-shot training setup. They should not be interpreted as a benchmark against production spam-filtering systems. | |
| --- | |
| # ๐งฌ The TinyModels Recipe | |
| ```text | |
| โโโโโโโโโโโโโโโโโโโโโ | |
| โ SetFit/enron โ | |
| โ _spam โ | |
| โโโโโโโโโโโฌโโโโโโโโโโ | |
| โ | |
| 16 examples | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโโโโ | |
| โ BGE-small โ | |
| โ text encoder โ | |
| โโโโโโโโโโโฌโโโโโโโโโโ | |
| โ | |
| embeddings | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโโโโ | |
| โ SetFit โ | |
| โ contrastive loss โ | |
| โโโโโโโโโโโฌโโโโโโโโโโ | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโโโโ | |
| โ LogisticRegressionโ | |
| โโโโโโโโโโโฌโโโโโโโโโโ | |
| โ | |
| โโโโโโโโดโโโโโโโ | |
| โผ โผ | |
| โ๏ธ HAM ๐จ SPAM | |
| ``` | |
| ### Training configuration | |
| ```yaml | |
| backbone: BAAI/bge-small-en-v1.5 | |
| dataset: SetFit/enron_spam | |
| examples: | |
| total: 16 | |
| per_class: 8 | |
| setfit: | |
| iterations: 20 | |
| epochs: 1 | |
| batch_size: 16 | |
| loss: CosineSimilarityLoss | |
| distance_metric: cosine_distance | |
| classifier: | |
| type: LogisticRegression | |
| seed: 42 | |
| ``` | |
| --- | |
| # ๐ Run It | |
| ```bash | |
| pip install -q setfit | |
| ``` | |
| ```python | |
| from setfit import SetFitModel | |
| model = SetFitModel.from_pretrained( | |
| "TinyModels/setfit-banking-spam" | |
| ) | |
| text = """ | |
| Congratulations! You have won $1,000,000. | |
| Click here immediately to claim your prize. | |
| """ | |
| prediction = model(text) | |
| print(prediction) | |
| ``` | |
| ### Example output | |
| ```text | |
| 1 | |
| ``` | |
| --- | |
| # ๐งช Quick Examples | |
| ### ๐จ Spam | |
| ```text | |
| CONGRATULATIONS!!! | |
| You have been selected to receive | |
| $1,000,000. Click the link below | |
| to claim your prize immediately. | |
| ``` | |
| ```text | |
| โ SPAM | |
| ``` | |
| --- | |
| ### โ๏ธ Legitimate | |
| ```text | |
| Please find attached the global markets | |
| monitor for the week ending 12 January 2001. | |
| ``` | |
| ```text | |
| โ HAM | |
| ``` | |
| --- | |
| # ๐ง Why SetFit? | |
| Traditional supervised classification can require a large labeled dataset. | |
| SetFit takes a different route: | |
| ```text | |
| Large Dataset | |
| โ | |
| โ | |
| โ | |
| โโโโโโโผโโโโโโ | |
| โ SetFit โ | |
| โโโโโโโฌโโโโโโ | |
| โ | |
| โผ | |
| Few labeled examples | |
| โ | |
| โผ | |
| Useful classifier | |
| ``` | |
| This makes the experiment useful for exploring: | |
| * โก Few-shot learning | |
| * ๐ง Sentence embeddings | |
| * ๐ Text classification | |
| * ๐จ Spam detection | |
| * ๐ฌ Efficient training | |
| * ๐ค SetFit | |
| --- | |
| # ๐งฉ Architecture | |
| <div align="center"> | |
| ```text | |
| INPUT | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| โ BAAI/bge-small-en-v1.5 โ | |
| โ โ | |
| โ Sentence Transformer โ | |
| โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ | |
| โ | |
| โผ | |
| Dense Embedding | |
| โ | |
| โผ | |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| โ Logistic Regression โ | |
| โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ | |
| โ | |
| โโโโโโโโดโโโโโโโ | |
| โผ โผ | |
| HAM SPAM | |
| โ๏ธ ๐จ | |
| ``` | |
| </div> | |
| --- | |
| # โ ๏ธ Limitations | |
| This is intentionally a **tiny experimental model**. | |
| Because only 16 examples were used for training: | |
| * Performance can vary on unseen data. | |
| * Domain shift can significantly affect predictions. | |
| * Unusual spam may be missed. | |
| * Enron-style email does not represent every modern spam pattern. | |
| * The reported score comes from a lightweight few-shot experiment. | |
| **Do not use this model as the sole component of a security-critical email filtering system.** | |
| --- | |
| # ๐ฆ Model Identity | |
| <div align="center"> | |
| ```text | |
| โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ | |
| โ TINYMODEL โ | |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค | |
| โ โ | |
| โ MODEL SetFit Banking Spam โ | |
| โ BACKBONE BGE-small โ | |
| โ TASK Binary Classification โ | |
| โ DATA Enron Spam โ | |
| โ EXAMPLES 16 โ | |
| โ RESULT 91.4% Accuracy โ | |
| โ โ | |
| โ STATUS โ EXPERIMENTAL โ | |
| โ โ | |
| โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ | |
| ``` | |
| </div> | |
| --- | |
| <div align="center"> | |
| # โก 16 Examples. | |
| # ๐ง One Small Model. | |
| # ๐จ One Real Task. | |
| <br> | |
| <img src="https://img.shields.io/badge/BUILT%20BY-TinyModels-FF0080?style=for-the-badge"> | |
| <img src="https://img.shields.io/badge/POWERED%20BY-SetFit-7928CA?style=for-the-badge"> | |
| <br><br> | |
| **TinyModels โ building small models that actually do things.** | |
| </div> | |