Skip to main content

This library has two purposes: 1. allow to easily test semantic classification with open labels (not pre defined) for intent recognition. 2. allow to experiment with different n-shot classification components.

Project description

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 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)

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)

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 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open_intent_classifier-0.0.7.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

open_intent_classifier-0.0.7-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file open_intent_classifier-0.0.7.tar.gz.

File metadata

  • Download URL: open_intent_classifier-0.0.7.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for open_intent_classifier-0.0.7.tar.gz
Algorithm Hash digest
SHA256 d6cc8a97b5faa649a58e6b4ef2c51526cf5924e3c5ef5f0711bee7b12fae2030
MD5 11f7c1123c06743b564799ce2d3d7bf0
BLAKE2b-256 528c0f110e1aa95f48920c2f662a2057e0f1ff9cc064999ba3758225511e2932

See more details on using hashes here.

File details

Details for the file open_intent_classifier-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for open_intent_classifier-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 60ac84bb4badecc895fdeda1c213606d065dd32c0dfb122ffaba04c1c8b9dd3e
MD5 0fa21ea0cd8a801f46f441948627585b
BLAKE2b-256 c97ca7950a476c01ab27781c234e172044c706dc8940acc243345d60ff3b6a94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page