Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ⭐ [GLiClass](https://github.com/Knowledgator/GLiClass): Generalist and Lightweight Model for Sequence Classification
|
2 |
+
|
3 |
+
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.
|
4 |
+
|
5 |
+
It can be used for `topic classification`, `sentiment analysis` and as a reranker in `RAG` pipelines.
|
6 |
+
|
7 |
+
The model was trained on synthetic and licensed data that allow commercial use and can be used in commercial applications.
|
8 |
+
|
9 |
+
This version of the model uses a layer-wise selection of features that enables a better understanding of different levels of language. The backbone model is [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base), which effectively processes long sequences.
|
10 |
+
|
11 |
+
### How to use:
|
12 |
+
First of all, you need to install GLiClass library:
|
13 |
+
```bash
|
14 |
+
pip install gliclass
|
15 |
+
pip install -U transformers>=4.48.0
|
16 |
+
```
|
17 |
+
|
18 |
+
Than you need to initialize a model and a pipeline:
|
19 |
+
|
20 |
+
```python
|
21 |
+
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
|
22 |
+
from transformers import AutoTokenizer
|
23 |
+
|
24 |
+
model = GLiClassModel.from_pretrained("alexandrlukashov/gliclass_msmarco_merged")
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained("alexandrlukashov/gliclass_msmarco_merged", add_prefix_space=True)
|
26 |
+
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')
|
27 |
+
|
28 |
+
text = "I want to live in New York."
|
29 |
+
labels =[
|
30 |
+
'York is a cathedral city in North Yorkshire, England, with Roman origins',
|
31 |
+
'San Francisco,[23] officially the City and County of San Francisco, is a commercial, financial, and cultural center within Northern California, United States.',
|
32 |
+
'New York, often called New York City (NYC),[b] is the most populous city in the United States',
|
33 |
+
"New York City is the third album by electronica group Brazilian Girls, released in 2008.",
|
34 |
+
"New York City was an American R&B vocal group.",
|
35 |
+
"New York City is an album by the Peter Malick Group featuring Norah Jones.",
|
36 |
+
"New York City: The Album is the debut studio album by American rapper Troy Ave. ",
|
37 |
+
'"New York City" is a song by British new wave band The Armoury Show',
|
38 |
+
]
|
39 |
+
results = pipeline(text, labels, threshold=0.5)[0] #because we have one text
|
40 |
+
for result in results:
|
41 |
+
print(result["label"], "=>", result["score"])
|
42 |
+
```
|