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 inbluefrom 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
tensorflow==2.4
numpy