Categories:

Social Share

Sample Text Analytics model deployment for reference

The following files can be used as a reference for text classification inference - Sample Text Classification Inference - Cluzters Vault and Google Docs - Cluzter Model Guidelines


Guidelines

Inference.zip Folder structure:

requirements.txt

Trained Model file

inference.py

Other files and folders used


Inference.py file format:

Import Statements

Onetime executable operations

{Ex: Loading the Model, label encoding  etc.}

def predict(Input arguments as per the use-case)

{

Data Preprocessing

Inference

Return output based on the use-case

}

*Do not change the naming convention for the entities marked inblue
  • inference.py and requirements.txt are mandatory files
  • inference.py should contain a function predict which takes one argument - a string (an input text). The return value should be also be a string (the output/prediction text).


Sample inference.py
from tensorflow.keras.models import load_model import numpy as np labels = ["positive", "negative", "neutral"] model = load_model("model.h5") def predict(input_text): #preprocessing yhat = model.predict(input_text) yhat = np.array(yhat) indices = np.argmax(yhat, axis=1) scores = yhat[np.arange(len(yhat)), indices] predicted_categories = [labels[i] for i in indices] output = predicted_categories[0] return output​​

requirements.txt
tensorflow==2.4 numpy ​ ​