{"slug": "gliclass-open-source-jev", "title": "GLiClass: Open-Source JEV", "summary": "Knowledgator released GLiClass, an open-source zero-shot sequence classification model inspired by the GLiNER framework that performs classification in a single forward pass and runs approximately 10 times faster than traditional cross-encoder models while achieving comparable performance. The model is installable via pip and supports hierarchical label structures using dot notation, in-context examples through the <<EXAMPLE>> token, custom prompts, and automatic text chunking for long documents. GLiClass is available on GitHub and Hugging Face, with a small-v1.0 model checkpoint and an interactive demo.", "body_md": "**GLiClass** is an efficient, zero-shot sequence classification model inspired by the [GLiNER](https://github.com/urchade/GLiNER/tree/main) framework. It achieves comparable performance to traditional cross-encoder models while being significantly more computationally efficient, offering classification results approximately **10 times faster** by performing classification in a single forward pass.\n\n[📄 Blog](https://medium.com/@knowledgrator/pushing-zero-shot-classification-to-the-limit-696a2403032f)\n  •  \n[📢 Discord](https://discord.gg/dkyeAgs9DG)\n  •  \n[📺 Demo](https://huggingface.co/spaces/knowledgator/GLiClass_SandBox)\n  •  \n[🤗 Available models](https://huggingface.co/models?sort=trending&search=gliclass)\n  •  \n\nInstall GLiClass easily using pip:\n\n```\npip install gliclass\n```\n\nClone and install directly from GitHub:\n\n```\ngit clone https://github.com/Knowledgator/GLiClass\ncd GLiClass\n\npython -m venv venv\nsource venv/bin/activate  # Windows: venv\\Scripts\\activate\n\npip install -r requirements.txt\npip install .\n```\n\nVerify your installation:\n\n``` python\nimport gliclass\nprint(gliclass.__version__)\npython\nfrom gliclass import GLiClassModel, ZeroShotClassificationPipeline\nfrom transformers import AutoTokenizer\n\nmodel = GLiClassModel.from_pretrained(\"knowledgator/gliclass-small-v1.0\")\ntokenizer = AutoTokenizer.from_pretrained(\"knowledgator/gliclass-small-v1.0\")\n\npipeline = ZeroShotClassificationPipeline(\n    model, tokenizer, classification_type='multi-label', device='cuda:0'\n)\n\ntext = \"One day I will see the world!\"\nlabels = [\"travel\", \"dreams\", \"sport\", \"science\", \"politics\"]\nresults = pipeline(text, labels, threshold=0.5)[0]\n\nfor result in results:\n    print(f\"{result['label']} => {result['score']:.3f}\")\n```\n\nGLiClass now supports hierarchical label structures using dot notation:\n\n```\nhierarchical_labels = {\n    \"sentiment\": [\"positive\", \"negative\", \"neutral\"],\n    \"topic\": [\"product\", \"service\", \"shipping\"]\n}\n\ntext = \"The product quality is amazing but delivery was slow\"\nresults = pipeline(text, hierarchical_labels, threshold=0.5)[0]\n\nfor result in results:\n    print(f\"{result['label']} => {result['score']:.3f}\")\n# Output:\n# sentiment.positive => 0.892\n# topic.product => 0.921\n# topic.shipping => 0.763\n```\n\nGet hierarchical output matching your input structure:\n\n```\nresults = pipeline(text, hierarchical_labels, return_hierarchical=True)[0]\nprint(results)\n# Output:\n# {\n#     \"sentiment\": {\"positive\": 0.892, \"negative\": 0.051, \"neutral\": 0.124},\n#     \"topic\": {\"product\": 0.921, \"service\": 0.153, \"shipping\": 0.763}\n# }\n```\n\nImprove classification accuracy with in-context examples using the `<<EXAMPLE>>` token:\n\n```\nexamples = [\n    {\n        \"text\": \"Love this item, great quality!\",\n        \"labels\": [\"positive\", \"product\"]\n    },\n    {\n        \"text\": \"Customer support was unhelpful\",\n        \"labels\": [\"negative\", \"service\"]\n    }\n]\n\ntext = \"Fast delivery and the item works perfectly!\"\nlabels = [\"positive\", \"negative\", \"product\", \"service\", \"shipping\"]\n\nresults = pipeline(text, labels, examples=examples, threshold=0.5)[0]\n\nfor result in results:\n    print(f\"{result['label']} => {result['score']:.3f}\")\n```\n\nAdd custom prompts to guide the classification task:\n\n```\ntext = \"The battery life on this phone is incredible\"\nlabels = [\"positive\", \"negative\", \"neutral\"]\n\nresults = pipeline(\n    text,\n    labels,\n    prompt=\"Classify the sentiment of this product review:\",\n    threshold=0.5\n)[0]\n```\n\nUse per-text prompts for batch processing:\n\n```\ntexts = [\"Review about electronics\", \"Review about clothing\"]\nprompts = [\n    \"Analyze this electronics review:\",\n    \"Analyze this clothing review:\"\n]\n\nresults = pipeline(texts, labels, prompt=prompts)\n```\n\nProcess long documents with automatic text chunking:\n\n``` python\nfrom gliclass import ZeroShotClassificationWithChunkingPipeline\n\nchunking_pipeline = ZeroShotClassificationWithChunkingPipeline(\n    model,\n    tokenizer,\n    text_chunk_size=8192,\n    text_chunk_overlap=256,\n    labels_chunk_size=8\n)\n\nlong_document = \"...\" # Very long text\nlabels = [\"category1\", \"category2\", \"category3\"]\n\nresults = chunking_pipeline(long_document, labels, threshold=0.5)\n```\n\nWith new models trained with retrieval-agumented classification, such as [this model](https://huggingface.co/knowledgator/gliclass-base-v2.0-rac-init) you can specify examples to improve classification accuracy:\n\n```\nexample = {\n    \"text\": \"A new machine learning platform automates complex data workflows but faces integration issues.\",\n    \"all_labels\": [\"AI\", \"automation\", \"data_analysis\", \"usability\", \"integration\"],\n    \"true_labels\": [\"AI\", \"integration\", \"automation\"]\n}\n\ntext = \"The new AI-powered tool streamlines data analysis but has limited integration capabilities.\"\nlabels = [\"AI\", \"automation\", \"data_analysis\", \"usability\", \"integration\"]\n\nresults = pipeline(text, labels, threshold=0.1, rac_examples=[example])[0]\n\nfor predict in results:\n    print(f\"{predict['label']} => {predict['score']:.3f}\")\n```\n\nDeploy GLiClass with Ray Serve for production workloads with dynamic batching and memory-aware processing.\n\n```\npip install gliclass[serve]\n# Default model\npython -m gliclass.serve\n\n# Specify model and port\npython -m gliclass.serve --model knowledgator/gliclass-edge-v3.0 --port 8000\n\n# With config file\npython -m gliclass.serve --config serve_configs/serve_config.yaml\npython\nfrom gliclass.serve import GLiClassClient\n\nclient = GLiClassClient(url=\"http://localhost:8000/gliclass\")\n\nresult = client.classify(\n    text=\"This is a great product!\",\n    labels=[\"positive\", \"negative\", \"neutral\"],\n    threshold=0.3,\n)\nprint(result)  # [{\"label\": \"positive\", \"score\": 0.95}, ...]\n```\n\nThe HTTP endpoint processes one text per request.\n\n```\ncurl -X POST http://localhost:8000/gliclass \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"texts\": \"This is a great product!\",\n    \"labels\": [\"positive\", \"negative\", \"neutral\"],\n    \"threshold\": 0.3\n  }'\n\n# Response: [{\"label\": \"positive\", \"score\": 0.95}, ...]\n```\n\n**Note:** For batch processing multiple texts, use the `ZeroShotClassificationPipeline` directly instead of the serving API.\n\nSee `serve_configs/serve_config.yaml` for full configuration options.\n\n- **Sentiment Analysis:** Rapidly classify texts as positive, negative, or neutral.\n- **Document Classification:** Efficiently organize and categorize large document collections.\n- **Search Results Re-ranking:** Improve relevance and precision by reranking search outputs.\n- **News Categorization:** Automatically tag and organize news articles into predefined categories.\n- **Fact Checking:** Quickly validate and categorize statements based on factual accuracy.\n\nPrepare your training data as follows:\n\n```\n[\n  {\"text\": \"Sample text.\", \"all_labels\": [\"sports\", \"science\", \"business\"], \"true_labels\": [\"sports\"]},\n  ...\n]\n```\n\nOptionally, specify confidence scores explicitly:\n\n```\n[\n  {\"text\": \"Sample text.\", \"all_labels\": [\"sports\", \"science\"], \"true_labels\": {\"sports\": 0.9}},\n  ...\n]\n```\n\nPlease, refer to the `train.py` script to set up your training from scratch or fine-tune existing models.\n\nGLiClass supports multiple architecture types:\n\n- **uni-encoder** : Single encoder for both text and labels (default, most efficient)\n- **bi-encoder** : Separate encoders for text and labels\n- **bi-encoder-fused** : Bi-encoder with label embeddings fused into text encoding\n- **encoder-decoder** : Encoder-decoder architecture for sequence-to-sequence tasks\n\n``` python\nfrom gliclass import GLiClassBiEncoder\n\n# Load a bi-encoder model\nmodel = GLiClassBiEncoder.from_pretrained(\"knowledgator/gliclass-biencoder-v1.0\")\n```\n\nConfigure how token embeddings are pooled:\n\n- `first` : First token (CLS token)\n- `avg` : Average pooling\n- `max` : Max pooling\n- `last` : Last token\n- `sum` : Sum pooling\n- `rms` : Root mean square pooling\n- `abs_max` : Max of absolute values\n- `abs_avg` : Average of absolute values\n\n``` python\nfrom gliclass import GLiClassModelConfig\n\nconfig = GLiClassModelConfig(\n    pooling_strategy='avg',\n    class_token_pooling='average'  # or 'first'\n)\n```\n\nChoose different scoring mechanisms for classification:\n\n- `simple` : Dot product (fastest)\n- `weighted-dot` : Weighted dot product with learned projections\n- `mlp` : Multi-layer perceptron scorer\n- `hopfield` : Hopfield network-based scorer\n\n```\nconfig = GLiClassModelConfig(\n    scorer_type='mlp'\n)\n```\n\nGLiClass supports incremental, multi-session text classification over a decoder-KV model. Instead of re-encoding the full document on every update, it maintains a persistent KV cache per session and runs the scorer only when a pluggable strategy decides classification should fire.\n\n```\npip install gliclass[streaming]\npython\nfrom gliclass.streaming import StreamingPipeline, SessionInput, EveryNTokensStrategy\n\npipeline = StreamingPipeline(model, tokenizer, device=\"cuda\", max_cache_len=1024)\nstrategy = EveryNTokensStrategy(n=50)\n\nfor chunk in text_chunks:\n    outputs = pipeline([SessionInput(\n        session_id=\"doc_001\",\n        text=chunk,\n        labels=[\"science\", \"politics\", \"finance\"],\n        strategy=strategy,\n        classification_type=\"multi-label\",\n    )])\n    if outputs[0].triggered:\n        print(outputs[0].predictions)\n```\n\nBuilt-in strategies: `EveryChunkStrategy`, `EveryNTokensStrategy`, `OnDelimiterStrategy`, `SlidingWindowStrategy`, `ComposedStrategy`, `NeverStrategy`.\n\nFor full documentation on session management, KV cache internals, batching, CPU offloading, and custom strategies, see [docs/streaming.md](https://github.com/Knowledgator/GLiClass/blob/main/docs/streaming.md).\n\nGLiClass supports optional flash attention backends for faster inference.\n\n```\npip install flashdeberta   # DeBERTa v2\npip install turbot5        # T5 / mT5\n```\n\nEnable via environment variable:\n\n```\nexport USE_FLASHDEBERTA=1\n```\n\nIf `flashdeberta` is installed, DeBERTa v2 models will use `FlashDebertaV2Model`.\nOtherwise, GLiClass falls back to `DebertaV2Model`.\n\nEnable via environment variable:\n\n```\nexport TURBOT5_ATTN_TYPE=triton-basic\n```\n\nIf `turbot5` is installed, T5 / mT5 models will use `FlashT5EncoderModel`.\nOtherwise, GLiClass falls back to `T5EncoderModel`.\n\nNotes:\n\n- Flash backends are **optional**\n- Enabled automatically when available\n- No code changes required\n\nWant it even tighter (single block), or is this the sweet spot?\n\nIf you find GLiClass useful in your research or project, please cite our papers:\n\n```\n@misc{stepanov2025gliclassgeneralistlightweightmodel,\n      title={GLiClass: Generalist Lightweight Model for Sequence Classification Tasks}, \n      author={Ihor Stepanov and Mykhailo Shtopko and Dmytro Vodianytskyi and Oleksandr Lukashov and Alexander Yavorskyi and Mykyta Yaroshenko},\n      year={2025},\n      eprint={2508.07662},\n      archivePrefix={arXiv},\n      primaryClass={cs.LG},\n      url={https://arxiv.org/abs/2508.07662}, \n}\n```\n\n", "url": "https://wpnews.pro/news/gliclass-open-source-jev", "canonical_source": "https://github.com/knowledgator/gliclass", "published_at": "2026-09-16 04:47:07+00:00", "updated_at": "2026-09-16 05:08:04.128681+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "natural-language-processing", "ai-tools", "ai-research"], "entities": ["Knowledgator", "GLiClass", "GLiNER", "Hugging Face", "GitHub", "ZeroShotClassificationPipeline", "gliclass-small-v1.0", "ZeroShotClassificationWithChunkingPipeline"], "alternates": {"html": "https://wpnews.pro/news/gliclass-open-source-jev", "markdown": "https://wpnews.pro/news/gliclass-open-source-jev.md", "text": "https://wpnews.pro/news/gliclass-open-source-jev.txt", "jsonld": "https://wpnews.pro/news/gliclass-open-source-jev.jsonld"}}