How to get the multiple prediction for simpleRNN

Viewed 50

Basically my system is like this

  • 4 array input and return 1 array output
  • each array is consists of 12 numbers

my model is here below

n_hidden = 512
input_shape = 12
input_len = 4 
model = Sequential()

model.add(SimpleRNN(n_hidden, input_shape=(input_len, input_shape), return_sequences=False))
model.add(Dense(n_hidden, activation="linear")) 
model.add(Dense(input_shape, activation="linear"))
opt = Adam(lr=0.001)
model.compile(loss='mse', optimizer=opt)
model.summary()

prediction code.

in_ = basicdata[0].x[:1]
# in_.shape =  (1,4,12)

predicted = []
NUM_DATA = 100
cnt = 0
for i in range(NUM_DATA):
    out_ = model.predict(in_)  
    #it returns only 1 answer.
    #out_.shape = (1, 12) 

    in_ = np.concatenate((in_.reshape(input_shape, input_len)[1:], out_), axis=0).reshape(1, input_shape,input_len) 
    if cnt == 0:
        predicted = out_
    else:
        predicted = np.concatenate([predicted,out_],axis=0)
    cnt = cnt + 1

In this case , model.predict accepts (1,4,12) and returns the one array (1, 12) but, I want to get (10,12) multiple candidate to sample from.

I guess return_sequences and batch_size of simpleRNN are related but still in vague.

In my understanding.

  • return_sequences

return_sequences = False

A,B,C,D => (E)

return_sequences = True

A,B,C,D => (A,B,C,D,E)

I want to have like this below

A,B,C,D => (E1,E2,E3,E4,E5)

  • batch_size

batch_size affect the input shape though,

I want to change the output.

1 Answers

return_sequences = False (classifier of sequence):

A,B,C,D => (E)

return_sequences = True (classifier of sequence elements):

A,B,C,D => (A1,B1,C1,D1)

If your model was trained to predict the next symbol, then:

A,B,C,D => (B,C,D,E)

It is possible to create a model of this kind:

A,B,C,D => (E1,E2,E3,E4,E5)

It is seq2seq models (e.g. for translation, where the length of the input differs from the length of the output). You have to create two RNNs: encoder and decoder. As far as I understand it is not what you want.

batch_size is training parameter and used to implement stochastic gradient descent.

Related