Skip to main content

Open Intent Classification

Closed intent classification uses a set of predefined labels to identify an intent. In comparison, open intent classification allows you to define as many labels you want, without fine tuning the model.

This project implements different components that support open intent classification such as an embedder, a T5 based fine tuned model for intent classification and a verbalizer. If you are interested in finer detailes you can read my blog post.

The goal of this library is to enable you test your assumptions about your data as fast as possible and to be a one stop shop for everything "classification like", similarly to how Bertopic is for clustering.

Why should you use this?

  1. You are researching nlp classification problems and want to test different embeddings, verbalizers and components with plug-and-play feel
  2. You want to detect semantically user intents in text but either don't want to commit to pre-defined classes OR just want to test out the fastest way to classify text other than through an LLM

[!IMPORTANT]

open-intent-classification project is in Alpha stage.

  1. Expect API changes
  2. Milage may vary. Quality of classifiers have been tested on Atis and Banking77

Installation

$ pip install open-intent-classifier

Usage

A full example is under Atis Notebook

T5 Based Intent Classification

from open_intent_classifier.model import IntentClassifier
model = IntentClassifier()
labels = ["Cancel Subscription", "Refund Requests", "Broken Item", "And More..."]
text = "I don't want to continue this subscription"
predicted_label = model.predict(text, labels)

By default, the IntentClassifier is loading a small model with 80M parameters.

For higher accuracy you can initialize the model with:

from open_intent_classifier.model import IntentClassifier
from open_intent_classifier.consts import INTENT_CLASSIFIER_248M_FLAN_T5_BASE
model = IntentClassifier(INTENT_CLASSIFIER_248M_FLAN_T5_BASE)

This will increase model latency as well.

Embeddings Based Classification

from open_intent_classifier.embedder import StaticLabelsEmbeddingClassifier
labels = ["Cancel Subscription", "Refund Requests", "Broken Item", "And More..."]
text = "I don't want to continue this subscription"
embeddings_classifier = StaticLabelsEmbeddingClassifier(labels)
predicted_label = embeddings_classifier.predict(text)

LLM Based Classification

Using LLM for classification is a viable option that sometimes provides the highest quality. Currently we have implemented only Open AI based LLMs.

from open_intent_classifier.model import OpenAiIntentClassifier
labels = ["Cancel Subscription", "Refund Requests", "Broken Item", "And More..."]
text = "I don't want to continue this subscription"
model_name = "gpt-4o-mini"
classifier = OpenAiIntentClassifier(model_name)
result = classifier.predict(text=text, labels=labels)

LLM Few Shot Based Classification

from open_intent_classifier.model import OpenAiIntentClassifier, ClassificationExample
labels = ["Cancel Subscription", "Refund Requests", "Broken Item", "And More..."]
text = "I don't want to continue this subscription"
model_name = "gpt-4o-mini"
example = ClassificationExample(text="I want to abort my account", intent_labels=labels, intent="Cancel Subscription") 
classifier = OpenAiIntentClassifier(model_name, few_shot_examples=[example])
result = classifier.predict(text=text, labels=labels)

DSPy based classification

Here's an example of using DSPy based classifier for both educational purposes and potential increase in quality.

from open_intent_classifier.model import DSPyClassifier
classifier = DSPyClassifier()
labels = ["Cancel subscription", "Refund request"]
text = "I want to cancel my subscription"
result = classifier.predict(text, labels)

SmolLM2 based classification

Here's an example of using SmolLM2 based classifier

from open_intent_classifier.model import SmolLm2Classifier
classifier = SmolLm2Classifier()
labels = ["Cancel subscription", "Refund request"]
text = "I want to cancel my subscription"
result = classifier.predict(text, labels)

SmolLM2 Few Shot Based Classification

from open_intent_classifier.model import SmolLm2Classifier

from open_intent_classifier.model import SmolLm2Classifier, ClassificationExample
labels = ["Cancel subscription", "Refund request"]
example = ClassificationExample(text="I want to abort my account", intent_labels=labels, intent="Cancel Subscription")
classifier = SmolLm2Classifier(few_shot_examples=[example])
text = "I want to cancel my subscription"
result = classifier.predict(text, labels)

Training the T5 base classifier

The details of training of the classifier is in another repository. I have separated training from inference in order to allow each repository to be focused and extended.

You can read about the training in the training repo: https://github.com/SerjSmor/intent_classification

Roadmap

  • Add LLM based classification
  • Add DSPy based classification
  • Add small language models as classifiers
  • Add few shot interface
  • Add Atis and Banking77 comparisons with all classifiers
  • Add embeddings filtering stage for classifiers
  • Add multithreading for LLM based classifiers
  • Add an option to ensemble embeddings and T5 (and additional models)
  • Create a recommender for fine-tuning

Metadata

Release files for open-intent-classifier 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for open-intent-classifier 0.0.8
File Size Uploaded
open_intent_classifier-0.0.8.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for open-intent-classifier 0.0.8
File Interpreter ABI Platform
open_intent_classifier-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / open_intent_classifier-0.0.8.tar.gz

Download URL open_intent_classifier-0.0.8.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
51cfbc0e5cba553a12aa54eeda6f5971bd7fa55ac961d3cc341afc6bcb779cf2
BLAKE2b-256 checksum
How to use checksums
2a103a01f915cd4cc06e21b5bab4998788e685b9192a5e14f4b6035a6ab75ffd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / open_intent_classifier-0.0.8-py3-none-any.whl

Download URL open_intent_classifier-0.0.8-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab3e6e5f2c7571d590989601e3f58aba5dff4e40371df406f55c9ebce12ff4d8
BLAKE2b-256 checksum
How to use checksums
f74bf39120fd8a19cecf27744f089121520559939f4f84547fe7aee4ade552d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page