This is an older tutorial using the symbol API that comes with a few limitations. For example the batch_size is fixed.
Here is how you can run inference, you need the latest mxnet (
pip install mxnet --pre):
There is a dependency on the
clean_str function, and the
vocabulary object from the tutorial code.
net = mx.gluon.nn.SymbolBlock.imports('cnn-symbol.json', input_names=['data'])
def predict(net, test_sentence, padding_word="</s>", batch_size=50, sentence_size=56):
x_test = clean_str(test_sentence).split(" ")
x_test = x_test + ([padding_word] * (sentence_size - len(x_test)))
x, y = build_input_data([x_test], , vocabulary)
return net(mx.nd.array(x).repeat(batch_size, axis=0)).asnumpy().argmax()
predict(net, "This is terrible")
predict(net, "This is amazing")
However, if you want to do CNN text classification using MXNet Gluon at the character level, I would also recommend this tutorial I wrote :
It comes with an example of how to do inference and is not constrained by the batch size.
You can have a look here at an example of how to deploy it as web app: