Views
No views yet

sentiment.positive, topic.product).pip install gliclass1from gliclass import GLiClassModel, ZeroShotClassificationPipeline
2from transformers import AutoTokenizer
3
4model = GLiClassModel.from_pretrained("knowledgator/gliclass-instruct-edge-v1.0")
5tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-instruct-edge-v1.0")
6pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')1text = "NASA launched a new Mars rover to search for signs of ancient life."
2labels = ["space", "politics", "sports", "technology", "health"]
3
4results = pipeline(text, labels, threshold=0.5)[0]
5for r in results:
6 print(r["label"], "=>", r["score"])1hierarchical_labels = {
2 "science": ["space", "biology", "physics"],
3 "society": ["politics", "economics", "culture"]
4}
5
6results = pipeline(text, hierarchical_labels, threshold=0.5)[0]
7for r in results:
8 print(r["label"], "=>", r["score"])
9# e.g. science.space => 0.951text = "The food was excellent but the service was painfully slow."
2labels = ["positive", "negative", "neutral"]
3
4results = pipeline(text, labels, threshold=0.5)[0]
5for r in results:
6 print(r["label"], "=>", r["score"])1results = pipeline(
2 text, labels,
3 prompt="Classify the sentiment of this restaurant review:",
4 threshold=0.5
5)[0]1text = "Can you set an alarm for 7am tomorrow?"
2labels = ["set_alarm", "play_music", "get_weather", "send_message", "set_reminder"]
3
4results = pipeline(text, labels, threshold=0.5)[0]
5for r in results:
6 print(r["label"], "=>", r["score"])1examples = [
2 {"text": "Wake me up at 6:30.", "labels": ["set_alarm"]},
3 {"text": "Play some jazz.", "labels": ["play_music"]},
4]
5
6results = pipeline(text, labels, examples=examples, threshold=0.5)[0]
7for r in results:
8 print(r["label"], "=>", r["score"])1text = "The cat slept on the windowsill all afternoon."
2labels = ["The cat was awake and playing outside."]
3
4results = pipeline(text, labels, threshold=0.0)[0]
5print(results)
6# Low score → contradiction1query = "How to train a neural network?"
2passages = [
3 "Backpropagation is the key algorithm for training deep neural networks.",
4 "The stock market rallied on strong earnings reports.",
5 "Gradient descent optimizes model weights during training.",
6]
7
8for passage in passages:
9 score = pipeline(passage, [query], threshold=0.0)[0][0]["score"]
10 print(f"{score:.3f} {passage[:60]}")1text = (
2 "Context: The Eiffel Tower was built from 1887 to 1889 and is 330 m tall. "
3 "It was the tallest structure until the Chrysler Building in 1930.\n"
4 "Question: When was the Eiffel Tower built and how tall is it?\n"
5 "Answer: It was built 1887–1889, stands 330 m tall, and was the tallest "
6 "structure until the Empire State Building in 1931."
7)
8labels = ["hallucinated", "correct"]
9
10results = pipeline(text, labels, threshold=0.0)[0]
11for r in results:
12 print(r["label"], "=>", r["score"])
13# "hallucinated" should score higher (Empire State Building & 1931 are wrong)1text = (
2 "Domain: e-commerce product reviews\n"
3 "Rule: No promotion of illegal activity.\n"
4 "Text: The software is okay, but search for 'productname_patch_v2.zip' "
5 "to unlock all features for free."
6)
7labels = ["follows_guidelines", "violates_guidelines"]
8
9results = pipeline(text, labels, threshold=0.0)[0]
10for r in results:
11 print(r["label"], "=>", r["score"])1text = "I'm looking for a good Italian restaurant near downtown Chicago, budget ~$50/person."
2labels = [
3 "benign request",
4 "prompt injection",
5 "system prompt extraction",
6 "jailbreak attempt",
7 "harmful content request",
8 "social engineering",
9 "data exfiltration",
10]
11
12results = pipeline(text, labels, threshold=0.5)[0]
13for r in results:
14 print(r["label"], "=>", r["score"])| Dataset | large‑v1.0 | base‑v1.0 | edge‑v1.0 |
|---|---|---|---|
| CR | 0.9066 | 0.8922 | 0.7933 |
| sst2 | 0.9154 | 0.9198 | 0.7577 |
| sst5 | 0.3387 | 0.2266 | 0.2163 |
| 20_newsgroups | 0.5577 | 0.5189 | 0.2555 |
| spam | 0.9790 | 0.9380 | 0.7609 |
| financial_phrasebank | 0.8289 | 0.5217 | 0.3905 |
| imdb | 0.9397 | 0.9364 | 0.8159 |
| ag_news | 0.7521 | 0.6978 | 0.6043 |
| emotion | 0.4473 | 0.4454 | 0.2941 |
| cap_sotu | 0.4327 | 0.4579 | 0.2380 |
| rotten_tomatoes | 0.8491 | 0.8458 | 0.5455 |
| massive | 0.5824 | 0.4757 | 0.2090 |
| banking | 0.6987 | 0.6072 | 0.4635 |
| snips | 0.8509 | 0.6515 | 0.5461 |
| AVERAGE | 0.7199 | 0.6525 | 0.4922 |
| Dataset | large‑v3.0 | base‑v3.0 | modern‑large‑v3.0 | modern‑base‑v3.0 | edge‑v3.0 |
|---|---|---|---|---|---|
| CR | 0.9398 | 0.9127 | 0.8952 | 0.8902 | 0.8215 |
| sst2 | 0.9192 | 0.8959 | 0.9330 | 0.8959 | 0.8199 |
| sst5 | 0.4606 | 0.3376 | 0.4619 | 0.2756 | 0.2823 |
| 20_newsgroups | 0.5958 | 0.4759 | 0.3905 | 0.3433 | 0.2217 |
| spam | 0.7584 | 0.6760 | 0.5813 | 0.6398 | 0.5623 |
| financial_phrasebank | 0.9000 | 0.8971 | 0.5929 | 0.4200 | 0.5004 |
| imdb | 0.9366 | 0.9251 | 0.9402 | 0.9158 | 0.8485 |
| ag_news | 0.7181 | 0.7279 | 0.7269 | 0.6663 | 0.6645 |
| emotion | 0.4506 | 0.4447 | 0.4517 | 0.4254 | 0.3851 |
| cap_sotu | 0.4589 | 0.4614 | 0.4072 | 0.3625 | 0.2583 |
| rotten_tomatoes | 0.8411 | 0.7943 | 0.7664 | 0.7070 | 0.7024 |
| massive | 0.5649 | 0.5040 | 0.3905 | 0.3442 | 0.2414 |
| banking | 0.5574 | 0.4698 | 0.3683 | 0.3561 | 0.0272 |
| snips | 0.9692 | 0.9474 | 0.7707 | 0.5663 | 0.5257 |
| AVERAGE | 0.7193 | 0.6764 | 0.6197 | 0.5577 | 0.4900 |
1@misc{stepanov2025gliclassgeneralistlightweightmodel,
2 title={GLiClass: Generalist Lightweight Model for Sequence Classification Tasks},
3 author={Ihor Stepanov and Mykhailo Shtopko and Dmytro Vodianytskyi and Oleksandr Lukashov and Alexander Yavorskyi and Mykyta Yaroshenko},
4 year={2025},
5 eprint={2508.07662},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/2508.07662},
9}