Intentclassification AI in python, easy to use intentclassifier package.
Project description
Intentclassification
Install
pip install intentclassification
About
Intentclassification AI in python, easy to use intentclassifier package.
How to use
Import:
from intentclassification import IntentClassifier, handleTriggers
Intents Structure:
{
"intents": [
{
"tag": "lights_on",
"patterns": ["Turn the light on", "Turn on the light", "Lights on"]
},
{
"tag": "lights_off",
"patterns": ["Turn the light off", "Turn off the light", "Lights off"]
},
{
"tag": "fan_on",
"patterns": ["Turn the fan on", "Turn on the fan", "Fan on"]
},
{
"tag": "fan_off",
"patterns": ["Turn the fan off", "Turn off the fan", "Fan off"]
}
]
}
Example:
from intentclassification import IntentClassifier, handleTriggers
#Initialise intentclassifier (Intents path being the path to the intents.json file) (Output path being the path to the folder the model will be saved in)
IC = IntentClassifier(intents_path="./intents.json", output_path="./intentclassification")
#Fit the model Aka. train the model on the data in intents.json
IC.fit_model()
#Save the model after fitting
IC.save_model()
#Loading a previously fitted/trained model
#When you have a trained model you dont have to retrain everytime you run the program, just simply load the model like so
IC.load_model()
#Using the model is as simple as parsing a sentence to the predict function
result = IC.predict(input_text="Turn the lights on!")
#The predict function will return a json object including the name of the intent and the probability of that intent
print(result) # Example: {"intent": "lights_on", "probability": "0.999256"}
#Now how about we use this intent for something useful?
#We can define a function that will run whenever the lights_on intent reaches a certain probability
#Remember to give the functions and the intents the same name otherwise the triggerhandler wont work
def lights_on():
print("Turning lights on!")
#Run code for turning on your light here!
#If anything in here is returned it will be parsed through the handleTriggers() function
return "Lights have been turned on!"
def lights_off():
print("Turning lights off!")
#Run code for turning on your light here!
#If anything in here is returned it will be parsed through the handleTriggers() function
return "Lights have been turned off!"
def fan_on():
print("Turning fan on!")
#Run code for turning on your light here!
#If anything in here is returned it will be parsed through the handleTriggers() function
return "Fan has been turned on!"
def fan_off():
print("Turning fan off!")
#Run code for turning on your light here!
#If anything in here is returned it will be parsed through the handleTriggers() function
return "Fan has been turned off!"
#Create an array with all the trigger functions, this is how the handleTriggers() function accesses them.
trigger_functions = [lights_on, lights_off, fan_on, fan_off]
#Handletriggers takes 2 arguments, the result from the IC.predict() function and a probability threshold value for activating the trigger functions
#The probability_threshold can be changed to accomodate any missfires, the threshold might have to be changed depending on the size of intents.json
returned_value = handleTriggers(prediction=result, probability_threshold=0.75, trigger_functions=trigger_functions)
#The returned value will be None by default depending on if the triggered trigger function returns anything, otherwise it will be the returned value
print(returned_value)
# The printed results of this full program will be the following:
# {'intent': 'lights_on', 'probability': '0.9999784'}
# Turning lights on!
# Lights have been turned on!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file intentclassification-0.0.8.tar.gz.
File metadata
- Download URL: intentclassification-0.0.8.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8397b6266d1acf6633f8cf6808a3326edde67f470437fd077f1a8a684d64f949
|
|
| MD5 |
2412c21c7cf0c1aeaab5fb1b41d35c16
|
|
| BLAKE2b-256 |
583f00b949232edeae7319ce1c5ab7c2caf0a7674d3e2e1a882dd08a199718f1
|
File details
Details for the file intentclassification-0.0.8-py3-none-any.whl.
File metadata
- Download URL: intentclassification-0.0.8-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
742d18f9f34c6f3f471441d12409b6480fb884252c144883789efc6b824e372e
|
|
| MD5 |
8ac85530d72220e2a4bcdbb2556860cc
|
|
| BLAKE2b-256 |
29ae3d493dd935268afd7901e486a0895358b22472c6ead6119a9f87054b1f39
|