https://github.com/hetpandya/intent-classifier
https://github.com/hetpandya/intent-classifier
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/hetpandya/intent-classifier
- Owner: hetpandya
- License: mit
- Created: 2020-10-19T11:33:40.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-25T07:21:50.000Z (about 4 years ago)
- Last Synced: 2025-03-26T18:43:44.192Z (about 2 months ago)
- Language: Jupyter Notebook
- Size: 18.3 MB
- Stars: 4
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Intent Classifier
Code for Medium blog post [Creating Your own Intent Classifier](https://medium.com/analytics-vidhya/creating-your-own-intent-classifier-b86e000a4926).
### Requirements
`pip install wget tensorflow==1.5 pandas numpy keras`### Training
For training, check: [intent_classification.ipynb](https://github.com/thehetpandya/intent-classifier/blob/main/intent_classification.ipynb)### Inference
```
import pickle
from tensorflow.python.keras.models import load_model
from tensorflow.python.keras.preprocessing.sequence import pad_sequences
import numpy as npclass IntentClassifier:
def __init__(self,classes,model,tokenizer,label_encoder):
self.classes = classes
self.classifier = model
self.tokenizer = tokenizer
self.label_encoder = label_encoderdef get_intent(self,text):
self.text = [text]
self.test_keras = self.tokenizer.texts_to_sequences(self.text)
self.test_keras_sequence = pad_sequences(self.test_keras, maxlen=16, padding='post')
self.pred = self.classifier.predict(self.test_keras_sequence)
return self.label_encoder.inverse_transform(np.argmax(self.pred,1))[0]
model = load_model('models/intents.h5')with open('utils/classes.pkl','rb') as file:
classes = pickle.load(file)with open('utils/tokenizer.pkl','rb') as file:
tokenizer = pickle.load(file)with open('utils/label_encoder.pkl','rb') as file:
label_encoder = pickle.load(file)
nlu = IntentClassifier(classes,model,tokenizer,label_encoder)
print(nlu.get_intent("is it cold in India right now"))
```