Zero-Shot Classification
Transformers
ONNX
Safetensors
English
GLiClass
text classification
zero-shot
small language models
RAG
sentiment analysis
Instructions to use knowledgator/gliclass-base-v1.0-init with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use knowledgator/gliclass-base-v1.0-init with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="knowledgator/gliclass-base-v1.0-init")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("knowledgator/gliclass-base-v1.0-init", dtype="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- MoritzLaurer/synthetic_zeroshot_mixtral_v0.1
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
metrics:
|
| 8 |
+
- f1
|
| 9 |
+
pipeline_tag: text-classification
|
| 10 |
+
tags:
|
| 11 |
+
- text classification
|
| 12 |
+
- zero-shot
|
| 13 |
+
- small language models
|
| 14 |
+
- RAG
|
| 15 |
+
- sentiment analysis
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# ⭐ GLiClass: Generalist and Lightweight Model for Sequence Classification
|
| 19 |
+
|
| 20 |
+
This is an efficient zero-shot classifier inspired by [GLiNER](https://github.com/urchade/GLiNER/tree/main) work. It demonstrates the same performance as a cross-encoder while being more compute-efficient because classification is done at a single forward path.
|
| 21 |
+
|
| 22 |
+
It can be used for `topic classification`, `sentiment analysis` and as a reranker in `RAG` pipelines.
|
| 23 |
+
|
| 24 |
+
The model was trained on synthetic data and can be used in commercial applications.
|
| 25 |
+
|
| 26 |
+
### How to use:
|
| 27 |
+
First of all, you need to install GLiClass library:
|
| 28 |
+
```bash
|
| 29 |
+
pip install gliclass
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
Than you need to initialize a model and a pipeline:
|
| 33 |
+
```python
|
| 34 |
+
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
|
| 35 |
+
from transformers import AutoTokenizer
|
| 36 |
+
|
| 37 |
+
model = GLiClassModel.from_pretrained("knowledgator/gliclass-base-v1")
|
| 38 |
+
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-base-v1")
|
| 39 |
+
|
| 40 |
+
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')
|
| 41 |
+
|
| 42 |
+
text = "One day I will see the world!"
|
| 43 |
+
labels = ["travel", "dreams", "sport", "science", "politics"]
|
| 44 |
+
results = pipeline(text, labels, threshold=0.5)[0] #because we have one text
|
| 45 |
+
|
| 46 |
+
for result in results:
|
| 47 |
+
print(result["label"], "=>", result["score"])
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
### Benchmarks:
|
| 51 |
+
Below, you can see the F1 score on several text classification datasets. All tested models were not fine-tuned on those datasets and were tested in a zero-shot setting.
|
| 52 |
+
| Model | IMDB | AG_NEWS | Emotions |
|
| 53 |
+
|-----------------------------|------|---------|----------|
|
| 54 |
+
| [gliclass-base-v1.0 (144 M)](https://huggingface.co/knowledgator/gliclass-base-v1.0) | 0.8650 | 0.6837 | 0.4749 |
|
| 55 |
+
| [gliclass-small-v1.0 (144 M)](https://huggingface.co/knowledgator/gliclass-small-v1.0) | 0.8650 | 0.6805 | 0.4664 |
|
| 56 |
+
| [Bart-large-mnli (407 M)](https://huggingface.co/facebook/bart-large-mnli) | 0.89 | 0.6887 | 0.3765 |
|
| 57 |
+
| [Deberta-base-v3 (184 M)](https://huggingface.co/cross-encoder/nli-deberta-v3-base) | 0.85 | 0.6455 | 0.5095 |
|
| 58 |
+
| [Comprehendo (184M)](https://huggingface.co/knowledgator/comprehend_it-base) | 0.90 | 0.7982 | 0.5660 |
|
| 59 |
+
| SetFit [BAAI/bge-small-en-v1.5 (33.4M)](https://huggingface.co/BAAI/bge-small-en-v1.5) | 0.86 | 0.5636 | 0.5754 |
|