0

I'm making a neural network with a not very obvious connection architecture. I comes down to 4 chunks of inputs, each of them having their own path towards the final outputlayer, merging them in between in several steps. I'm using mxnet on R. I defined 4 mx.symbol.Variable("data"), each being the input of the 'chunks' of input. Only 1 is shown on the graph (graph.viz(out)). I can understand that, it makes sense that I should provide only 1 large input-vector. However... how do I split that inputvector? (Oh, and to be sure, state.size of a lstm in mxnet, that points to the number of memory blocks, equal to the # input and outputs, right?)

Code (minimal example):

in1 <- mx.symbol.Variable("data1") # 7 values
in2 <- mx.symbol.Variable("data2") # 7 values

l1.1 <- mx.symbol.RNN(in1, name="lstm1.1", mode="lstm", num.layers=1, state.size=7) # first nn on the first 7 inputs 
l1.2 <- mx.symbol.RNN(in2, name="lstm1.2", mode="lstm", num.layers=1, state.size=7) # second nn on the last 7 inputs
l2 <- mx.symbol.RNN(data=l1.1+l1.2, name="lstml2", mode="lstm", num.layers=1, state.size=14)  # state.size must be 14, since each input separate has 7

out.dens <- mx.symbol.FullyConnected(c.lstm, name="out-dens", num.hidden=4) # 

pred <- mx.symbol.LinearRegressionOutput(out, name="pred")

graph.viz(pred) # only lstm1.1 has a data input

So the question is: How to provide 2 inputs, or how to split 1 input-vector in 2? (in1 and in2 doesn't seem to work out fine)

-- EDIT 1

One could imagine that the name of the symbolic variable first two lines in1 <- mx.symbol.Variable("data") # 7 values in2 <- mx.symbol.Variable("data") # 7 values should be different. I'm pretty sure they should, more like: in1 <- mx.symbol.Variable("data1") # 7 values in2 <- mx.symbol.Variable("data2") # 7 values

However, changing them doesn't change the visual computation graph. Well, it does: now again only 1 input is shown, but not as input (green circle), but as an actual layer (pink rectangle). This doesn't seem to help me out...

Kurt Sys
  • 11
  • 4

1 Answers1

1

Changing the first lines to:

input <- mx.symbol.Variable("data")

in1 <- mx.symbol.slice(input, begin=0, end=6)
in2 <- mx.symbol.slice(input, begin=7, end=13)

and not adding but using concat

l2 <- mx.symbol.concat(c(l1.1, 1.2), num.args=14)
l2 <- mx.symbol.RNN(data=l2, name="lstml2", mode="lstm", num.layers=1, state.size=14)  # state.size must be 14, since each input separate has 7

seems to be ok

Kurt Sys
  • 11
  • 4