Skip to main content

Pretrained Models

This page provides detailed information about pre-trained GLiClass models

GLiClass V3 Models (Latest)

GLiClass V3 represents the latest generation of zero-shot text classification models, offering significant improvements in both accuracy and efficiency. These models are trained with logic-based reasoning tasks using LoRA (Low-Rank Adaptation) to preserve knowledge while achieving cross-encoder-level performance with 8-10x faster inference speeds.

Key Features of V3

  • Logic-Enhanced Training: Pre-trained on logical reasoning tasks to induce reasoning capabilities
  • LoRA Fine-tuning: Preserves previous knowledge while adapting through efficient Low-Rank adapters
  • Superior Performance: Achieves cross-encoder quality (up to 0.70 avg F1) with single forward-pass efficiency
  • Multi-Label Support: Native support for multi-label classification tasks
  • Production-Ready: Up to 50x faster than traditional cross-encoders
  • Versatile Applications: Topic classification, sentiment analysis, RAG reranking, NLI tasks

DeBERTa-based V3 Models

NameEncoderParametersSize (GB)Avg F1 ScoreSpeed (ex/s)
gliclass-large-v3.0deberta-v3-large439M1.750.700125.22
gliclass-base-v3.0deberta-v3-base187M0.7460.655651.61
gliclass-edge-v3.0deberta-v3-xsmall32.7M0.1310.487397.29

Basic Usage

from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer
import torch

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# Load model and tokenizer
model = GLiClassModel.from_pretrained("knowledgator/gliclass-base-v3.0")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-base-v3.0")

# Initialize pipeline for multi-label classification
pipeline = ZeroShotClassificationPipeline(
model,
tokenizer,
classification_type='multi-label',
device=device
)

# Classify text
text = "One day I will see the world!"
labels = ["travel", "dreams", "sport", "science", "politics"]
results = pipeline(text, labels, threshold=0.5)[0]

for result in results:
print(f"{result['label']} => {result['score']:.3f}")
Expected Output
travel => 0.892
dreams => 0.756

ModernBERT-based V3 Models

NameEncoderParametersSize (GB)Avg F1 ScoreSpeed (ex/s)
gliclass-modern-large-v3.0ModernBERT-large399M1.60.608243.8
gliclass-modern-base-v3.0ModernBERT-base151M0.6060.557154.46
tip

For ModernBERT-based V3 models, initialize the tokenizer with add_prefix_space=True for optimal performance:

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"knowledgator/gliclass-modern-base-v3.0",
add_prefix_space=True
)
tip

ModernBERT-based V3 models show the best performance using flash-attention. Install it with pip install flash-attn --no-build-isolation

NLI Task Example

GLiClass V3 models can be used for Natural Language Inference tasks by using the premise as text and hypothesis as label:

text = "The cat slept on the windowsill all afternoon"
labels = ["The cat was awake and playing outside."]
results = pipeline(text, labels, threshold=0.0)[0]
print(results)

Performance Highlights

Benchmark Comparison (Average F1 Across 13 Datasets)

ModelAvg F1 ScoreSpeed (ex/s)Parameters
gliclass-large-v3.00.700125.22439M
gliclass-base-v3.00.655651.61187M
DeBERTa-v3-large (cross-encoder)0.68216.03-
DeBERTa-v3-base (cross-encoder)0.655910.63-
gliclass-modern-large-v3.00.608243.80399M
gliclass-modern-base-v3.00.557154.46151M
gliclass-edge-v3.00.487397.2932.7M

GLiClass V3 models achieve competitive or superior performance compared to cross-encoders while being significantly faster and more efficient for production deployments.


DeBERTa based models (V1/V2)

NameEncoderSize (GB)Zero-Shot F1 Score
gliclass-base-v1.0-lwdeberta-v3-base0.7490.6183
gliclass-large-v1.0-lwdeberta-v3-large1.760.6165
gliclass-large-v1.0deberta-v3-large1.750.6078
gliclass-small-v1.0-lwdeberta-v3-small0.5780.5732
gliclass-base-v2.0-rac-initdeberta-v3-base0.7450.5598
gliclass-base-v1.0deberta-v3-base0.7450.5571
gliclass-small-v1.0deberta-v3-small0.5740.5401

LLM based models (Experimental)

NameEncoderSize (GB)Zero-Shot F1 Score
gliclass-qwen-1.5B-v1.0Qwen-encoder-1.5B6.210.6956
gliclass-llama-1.3B-v1.0Sheared-LLaMA-encoder-1.3B5.1820.6927
gliclass-qwen-0.5B-v1.0Qwen-encoder-0.5B1.990.6445
important

To use these models make sure you have llm2vec framework installed. You can install it as follows:

pip install llm2vec
pip install flash-attn --no-build-isolation

For more information please visit the official repository

ModernBERT based models (V2)

NameEncoderSize (GB)Zero-Shot F1 Score
gliclass-modern-large-v2.0ModernBERT-large1.60.6045
gliclass-modern-base-v2.0ModernBERT-base0.6940.5563
gliclass-modern-large-v2.0-initModernBERT-large1.60.5447
gliclass-modern-base-v2.0-initModernBERT-base0.6060.5129
tip

To achive better performance for ModerBERT based models its reccomended to initialize tokenizer as follows:

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-modern-base-v2.0", add_prefix_space=True)
tip

ModernBERT based models show the best performance using flash-attention.
Install it with pip install flash-attn --no-build-isolation

Zero-Shot Classification

Any of the above models can be used in a ZeroShotClassificationPipeline as shown in the example below. For best performance, we recommend using the V3 models.

import torch
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

model = GLiClassModel.from_pretrained("knowledgator/gliclass-base-v3.0")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-base-v3.0")

pipeline = ZeroShotClassificationPipeline(
model,
tokenizer,
classification_type='single-label',
device=device
)
text = """
Apple Inc. is an American multinational technology company headquartered in Cupertino, California. Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue. As of March 2023, Apple is the world's biggest company by market capitalization. As of June 2022, Apple is the fourth-largest personal computer vendor by unit sales and the second-largest mobile phone manufacturer in the world. It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Meta Platforms, and Microsoft.
Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.
Apple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955–2011) and Ronald Wayne to develop and sell Wozniak's Apple I personal computer. It was incorporated by Jobs and Wozniak as Apple Computer, Inc. in 1977. The company's second computer, the Apple II, became a best seller and one of the first mass-produced microcomputers. Apple went public in 1980 to instant financial success. The company developed computers featuring innovative graphical user interfaces, including the 1984 original Macintosh, announced that year in a critically acclaimed advertisement called "1984". By 1985, the high cost of its products, and power struggles between executives, caused problems. Wozniak stepped back from Apple and pursued other ventures, while Jobs resigned and founded NeXT, taking some Apple employees with him.
"""
labels = ["business", "computers", "sport", "politics", "science"]
results = pipeline(
text,
labels,
threshold=0.5,
batch_size=8
)[0] # Select 1st as we only have one text

for result in results:
print(f"{result['label']} => {result['score']:.3f}")
Expected Output
business => 0.519
tip

If you need to classify large amount of labels, it is recommended to use this ZeroShotClassificationWithLabelsChunkingPipeline instead.
See more about usage here