AdaptiveClassifier.NET 1.0.0

dotnet add package AdaptiveClassifier.NET --version 1.0.0
                    
NuGet\Install-Package AdaptiveClassifier.NET -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AdaptiveClassifier.NET" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AdaptiveClassifier.NET" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AdaptiveClassifier.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AdaptiveClassifier.NET --version 1.0.0
                    
#r "nuget: AdaptiveClassifier.NET, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AdaptiveClassifier.NET@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AdaptiveClassifier.NET&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AdaptiveClassifier.NET&version=1.0.0
                    
Install as a Cake Tool

AdaptiveClassifier.NET

A .NET inference-only implementation of adaptive text classification concepts inspired by the Adaptive Classifier project .

This library allows you to run Adaptive Classifier–style models in .NET using ONNX Runtime, combining prototype-based memory with a neural adaptive head for robust few-shot classification.


Origin (READ FIRST)

This project is NOT an original work.

It is a .NET inference implementation designed to consume models trained with the original Adaptive Classifier project.

Original Project

  • Name: Adaptive Classifier
  • Authors: Original Adaptive Classifier research team
  • Repository: Adaptive classifier
  • License: Apache License 2.0

All research, algorithms, training logic, and model design belong to the original authors.


Ownership & Scope Disclaimer

  • This repository does not claim ownership of the Adaptive Classifier algorithm
  • This is not the official Adaptive Classifier implementation
  • This library does not support training
  • This project provides ONLY inference for models exported from the original project
  • Intended for production usage in .NET environments

If you are looking to train models, you must use the original Python project.


What This Project IS

  • A .NET library for adaptive text classification (inference only)
  • Implements a dual prediction system:
    • Prototype memory (instance-based similarity)
    • Neural adaptive head
  • Uses ONNX Runtime for embedding inference
  • Supports CUDA with automatic CPU fallback
  • Integrates with Hugging Face Hub for automatic model download
  • Thread-safe after initialization

What This Project IS NOT

  • Not a training framework
  • Not a reimplementation of the original Python code
  • Not responsible for dataset preparation
  • Not responsible for model correctness or quality

Problem This Solves

Adaptive Classifier models are powerful but Python-centric.

This library enables:

  • Running Adaptive Classifier models in .NET / C#
  • Deploying adaptive classifiers in enterprise .NET systems
  • Using prototype-based few-shot classification without Python

High-Level Architecture

Input Text
    ↓
ONNX Embedding Model
    ↓
┌─────────────────┬─────────────────┐
│  Prototype      │  Adaptive Head  │
│  Memory         │  (Neural Net)   │
│  (Similarity)   │                │
└─────────────────┴─────────────────┘
    ↓                 ↓
Similarity Scores   Neural Scores
    ↓                 ↓
    └─────┬───────────┘
          ↓
   Weighted Combination
          ↓
      Final Prediction

Model Compatibility Requirements

This library requires models exported from the original Adaptive Classifier project.

You MUST export all components listed below.
Partial exports will not work.

Required Files

File Purpose
model.onnx Embedding model
tokenizer.json Hugging Face tokenizer
examples.json Prototype memory
weights.json Adaptive head weights

Python Training & Export (REQUIRED)

Models must be trained and exported using the original project.

Below is a real export example based directly on the Adaptive Classifier training workflow.

Training & Export Example (Python)

import json
import torch
import shutil
from adaptive_classifier import AdaptiveClassifier

# creation of the classifier
classifier = AdaptiveClassifier(
    "distilbert/distilbert-base-multilingual-cased",
    device="cuda"
)

# training
classifier.add_examples(texts, labels)

# export
classifier.save(
    "./adaptive_classifier_model",
    include_onnx=True,
    quantize_onnx=True
)

def export_adaptive_head(classifier, file_path):
    head_data = {
        "id_to_label": classifier.id_to_label,
        "layers": []
    }

    for layer in classifier.adaptive_head.modules():
        if isinstance(layer, torch.nn.Linear):
            head_data["layers"].append({
                "weights": layer.weight.detach().cpu().numpy().tolist(),
                "bias": layer.bias.detach().cpu().numpy().tolist()
            })

    with open(file_path, "w") as f:
        json.dump(head_data, f)

export_adaptive_head(
    classifier,
    "./adaptive_classifier_model/output/weights.json"
)

Expected File Layout

Models/Classifier/
├── model.onnx
├── tokenizer.json
├── examples.json
└── weights.json

Usage Example (.NET)

using AdaptiveClassifier.NET;
using AdaptiveClassifier.NET.Configuration;

var config = new ClassifierConfiguration
{
    HuggingFaceModelId = "your-org/your-model",
    ModelFolder = "Models/MyClassifier",
    UseCUDA = true,
    ProtoWeight = 0.7,
    AdaptiveHeadWeight = 0.3
};

using var classifier = new Classifier(config);
await classifier.InitializeAsync(CancellationToken.None);

var predictions = classifier.Predict("Your text here", topK: 5);

Important Runtime Notes

  • InitializeAsync() must be called once
  • Safe for concurrent inference after initialization
  • CUDA is attempted first when enabled
  • If using CUDA:
    • Reference ONLY Microsoft.ML.OnnxRuntime.Gpu
    • Referencing CPU runtime will disable GPU usage

Limitations

Not Supported

  • Training or fine-tuning
  • Runtime updates to prototypes or weights
  • Batch inference
  • Custom architectures

Online vs Offline Usage

Online

  • Downloads models from Hugging Face
  • Cached locally after first run

Offline

  • All files must exist locally
  • No internet required

Final Disclaimer

This project exists solely to enable inference in .NET.

For:

  • Theory
  • Training
  • Dataset preparation
  • Model architecture

Refer to the original Adaptive classifier


License & Attribution

This project is released under the MIT License.

It is an independent .NET inference implementation inspired by the research and reference implementation from the Adaptive Classifier project.

The original Adaptive Classifier project is licensed under the Apache License 2.0.

This repository:

  • Does not include original Adaptive Classifier source code
  • Does not relicense Apache-licensed material
  • Consumes only exported model artifacts (ONNX + JSON weights)

All rights to the original research, algorithms, and training implementation remain with the original authors.


Citation

@software{adaptive-classifier,
  title = {Adaptive Classifier: Dynamic Text Classification with Continuous Learning},
  author = {Asankhaya Sharma},
  year = {2025},
  publisher = {GitHub},
  url = {https://github.com/codelion/adaptive-classifier}
}
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 104 1/26/2026