I have trained a tensorflow model to predict the next word for an input text. I saved it as an .h5 file.
I can use that model in another python code to predict word as follows:
import numpy as np
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from keras.models import load_model
model = load_model('model.h5')
model.compile(
loss = "categorical_crossentropy",
optimizer = "adam",
metrics = ["accuracy"]
)
data = open("dataset.txt").read()
corpus = data.lower().split("\n")
tokenizer = Tokenizer()
tokenizer.fit_on_texts(corpus)
seed_text = input()
sequence_text = tokenizer.texts_to_sequences([seed_text])[0]
padded_sequence = np.array(pad_sequences([sequence_text], maxlen = 11 -1))
predicted = np.argmax(model.predict(padded_sequence))
Is there a way through which I can directly use that model inside flutter, where I can take input from TextField() and by pressing the button, display the predicted word??