cnn = NetChain[
{
EmbeddingLayer[16, 100],
ConvolutionLayer[64, 3, "Interleaving" -> True],
AggregationLayer[Mean, 1],
LinearLayer[2],
SoftmaxLayer[]
},
"Input" -> 10
] // NetInitialize
Export["Python\\cnn.json", cnn, "MXNet"]
import mxnet as mx
import numpy as np
cnn = mx.gluon.SymbolBlock.imports('cnn.json', ['Input'], 'cnn.params')
cnn(mx.nd.array([[1,2,3,4,5,6,7,8,9,10]]))
[[0.52003264 0.47996736]]
cnn@Range[1, 10]
{0.520033,0.479967}
Mathematica embeds integers between 1 and n.
And MXNet embeds integers between 0 and n-1. Integers equal or greater than n are for unknown tokens.
cnn(mx.nd.array([[0,1,2,3,4,5,6,7,8,9]]))
[[0.49799052 0.50200945]]
cnn(mx.nd.array([[90,91,92,93,94,95,96,97,98,99]]))
[[0.48555845 0.51444155]]
cnn(mx.nd.array([[91,92,93,94,95,96,97,98,99,100]]))
[[0.4880071 0.51199293]]
cnn(mx.nd.array([[91,92,93,94,95,96,97,98,99,101]]))
[[0.4880071 0.51199293]]
No difference in output between 100 and 101 at the end.
And Mathematica has the same output as for unknown token at the end.
cnn@Range[91, 100]
{0.488007, 0.511993}