{"id":35126936,"url":"https://github.com/kamenialexnea/zero-shot-classification","last_synced_at":"2026-04-16T15:02:14.481Z","repository":{"id":329422064,"uuid":"872997340","full_name":"KameniAlexNea/zero-shot-classification","owner":"KameniAlexNea","description":"gliznet: generalized ligthweight zero shot classification network","archived":false,"fork":false,"pushed_at":"2025-12-26T06:56:47.000Z","size":473,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-30T06:02:09.414Z","etag":null,"topics":["classification","deep-learning","machine-learning","zero-shot-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KameniAlexNea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-15T12:38:48.000Z","updated_at":"2025-12-24T18:42:15.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/KameniAlexNea/zero-shot-classification","commit_stats":null,"previous_names":["kamenialexnea/zero-shot-classification"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KameniAlexNea/zero-shot-classification","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KameniAlexNea%2Fzero-shot-classification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KameniAlexNea%2Fzero-shot-classification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KameniAlexNea%2Fzero-shot-classification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KameniAlexNea%2Fzero-shot-classification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KameniAlexNea","download_url":"https://codeload.github.com/KameniAlexNea/zero-shot-classification/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KameniAlexNea%2Fzero-shot-classification/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31891038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classification","deep-learning","machine-learning","zero-shot-learning"],"created_at":"2025-12-28T03:24:56.298Z","updated_at":"2026-04-16T15:02:14.476Z","avatar_url":"https://github.com/KameniAlexNea.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GliZNet: Zero-Shot Text Classification\n\nGliZNet is a generalist and lightweight model for zero-shot sequence classification, inspired by [GLiNER](https://github.com/urchade/GLiNER) and [GLiClass](https://github.com/Knowledgator/GLiClass). It achieves efficient classification by encoding both text and labels in a single forward pass.\n\n## ✨ Features\n\n- **Zero-Shot Classification**: Works out-of-the-box with pretrained transformers (no task-specific training required)\n- **Efficient Architecture**: Single forward pass for all labels (10x faster than cross-encoders)\n- **Flexible Design**: Supports multi-label and multi-class classification\n- **Multiple Similarity Metrics**: Cosine, dot product, or bilinear similarity\n- **Configurable**: Optional projection layers, multiple loss functions for training\n- **Production Ready**: Clean pipeline interface inspired by GLiClass\n\n## 🚀 Quick Start\n\n### Installation\n\n```bash\npip install -e .\n```\n\n### Basic Usage\n\n```python\nfrom gliznet import GliZNetForSequenceClassification, ZeroShotClassificationPipeline\nfrom gliznet.tokenizer import GliZNETTokenizer\n\n# Load model and tokenizer\nmodel_name = \"alexneakameni/gliznet-ModernBERT-base\"\nmodel = GliZNetForSequenceClassification.from_pretrained(model_name)\ntokenizer = GliZNETTokenizer.from_pretrained(model_name)\n\n# Create pipeline\npipeline = ZeroShotClassificationPipeline(\n    model, tokenizer, \n    classification_type='multi-label',\n    device='cuda:0'\n)\n\n# Classify text\ntext = \"One day I will see the world!\"\nlabels = [\"travel\", \"dreams\", \"sport\", \"science\", \"politics\"]\nresults = pipeline(text, labels, threshold=0.5)\n\nfor result in results[0]:\n    print(f\"{result['label']} =\u003e {result['score']:.3f}\")\n```\n\n### Zero-Shot with Pretrained Backbone\n\nGliZNet works immediately with any pretrained transformer:\n\n```python\nfrom gliznet import GliZNetConfig, GliZNetForSequenceClassification\nfrom gliznet.tokenizer import GliZNETTokenizer\n\n# Default config: no projection, cosine similarity, mean pooling\nconfig = GliZNetConfig(backbone_model=\"microsoft/deberta-v3-small\")\ntokenizer = GliZNETTokenizer.from_backbone_pretrained(config.backbone_model)\nmodel = GliZNetForSequenceClassification.from_backbone_pretrained(config, tokenizer)\n\n# Use immediately for zero-shot!\npipeline = ZeroShotClassificationPipeline(model, tokenizer)\nresults = pipeline(\"I love this movie!\", [\"positive\", \"negative\", \"neutral\"])\n```\n\n## 📊 Architecture\n\n- **Backbone**: Any HuggingFace transformer (DeBERTa, RoBERTa, BERT, etc.)\n- **Text Encoding**: [CLS] token representation\n- **Label Encoding**: Mean pooling over label tokens\n- **Similarity**: Configurable (cosine, dot product, bilinear)\n- **Projection**: Optional (default: identity, uses raw embeddings)\n\n### Input Format\n\n```\n[CLS] text tokens [SEP] label1 [LAB] label2 [LAB] label3 [SEP]\n```\n\n## 🎯 Use Cases\n\n- **Sentiment Analysis**: Classify text as positive/negative/neutral\n- **Topic Classification**: Categorize documents into topics\n- **Intent Detection**: Identify user intent in conversations\n- **Content Moderation**: Flag inappropriate content\n- **News Categorization**: Organize articles by category\n- **Document Organization**: Tag and organize large document collections\n\n## 🛠️ Training\n\nTrain on your own data:\n\n```bash\n# Single GPU training\npython train_gliznet.py \\\n    --config configs/your_config.yaml \\\n    --output_dir models/your-model\n\n# Multi-GPU training\nbash train_gliznet.sh\n```\n\n### Training Data Format\n\n```json\n[\n  {\n    \"text\": \"Sample text here\",\n    \"all_labels\": [\"label1\", \"label2\", \"label3\"],\n    \"true_labels\": [\"label1\", \"label3\"]\n  }\n]\n```\n\nSee `train_gliznet.py` for detailed training configuration.\n\n## 📁 Repository Structure\n\n```\ngliznet/                  # Main model package\n├── model.py             # GliZNet model implementation\n├── tokenizer.py         # Custom tokenizer with label masking\n├── predictor.py         # Pipeline interface\n├── config.py            # Configuration classes\n└── data.py              # Data loading utilities\n\n\ntrain_gliznet.py        # Training script\ntrain_gliznet.sh        # Multi-GPU training script\n```\n\n## 🔧 Configuration\n\n```python\nfrom gliznet import GliZNetConfig\n\nconfig = GliZNetConfig(\n    backbone_model=\"microsoft/deberta-v3-small\",\n    projected_dim=None,              # None = no projection\n    similarity_metric=\"cosine\",      # \"cosine\", \"dot\", \"bilinear\"\n    use_projection_layernorm=False,  # LayerNorm after projection\n    \n    # Training loss weights\n    bce_loss_weight=1.0,\n    supcon_loss_weight=1.0,\n    label_repulsion_weight=0.1,\n    \n    # Temperature scaling\n    logit_scale_init=2.0,\n    learn_temperature=True,\n)\n```\n\n## 🤝 Citation\n\nIf you use GliZNet in your research, please cite:\n\n```bibtex\n@software{gliznet2025,\n  title = {GliZNet: Generalized Ligthweights Zero-Shot Text Classification},\n  author = {Alex Kameni},\n  year = {2025},\n  url = {https://github.com/KameniAlexNea/zero-shot-classification}\n}\n```\n\n## 📝 License\n\nMIT License\n\n## 🙏 Acknowledgments\n\n- Inspired by [GLiNER](https://github.com/urchade/GLiNER) and [GLiClass](https://github.com/Knowledgator/GLiClass)\n- Built on [HuggingFace Transformers](https://github.com/huggingface/transformers)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamenialexnea%2Fzero-shot-classification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkamenialexnea%2Fzero-shot-classification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamenialexnea%2Fzero-shot-classification/lists"}