1
votes

I am trying to train my model to predict the next number in an integer sequence. The integer sequence that I created was generated in random. My X_train = [[1,2,3,4,5,6], [45,45,46,47,48,49], [203,204,205,206,207,208]...] and Y_train = [[7,8,9], [50,51,52], [209,210,211]] The shape of X_train = (10000,6,511) and Y_train = (10000,3,511) How should I set my input shape for my GRU/LSTM model?

def define_models(n_input = 6, n_output = 3):
    # define training encoder
    sequence = Input(shape=(n_input,), dtype="int32")
    embedded = Embedding(13, 300, mask_zero=True)(sequence)
    gru1 = GRU(1000, return_sequences=True)(embedded)
    after_dp = Dropout(0.5)(gru1)
    gru2 = GRU(1000, return_sequences=True)(after_dp)
    after_dp = Dropout(0.5)(gru2)
    output = TimeDistributed(Dense(13, activation="softmax"))(after_dp)

    model = Model(input=sequence, output=output)

    return model

i am getting the error :

ValueError: Error when checking input: expected input_1 to have 2 dimensions, but got array with shape (10000, 6, 511)

How should I fix it for my dataset?

1

1 Answers

0
votes

You are only giving one dimension as the input_shape, while you are giving a 3d array as input.For a n-d input array, the input_shape should be last n-1 dimension values. Hence the input shape should be (X_train.shape[1],X_train.shape[2]).

Replace this line

 sequence = Input(shape=(n_input,), dtype="int32")

with this

 sequence = Input(shape=(X_train.shape[1],X_train.shape[2]), dtype="int32")