1
votes
for i in range(y_word_max_len):
    sub_decoder_input = gather(main_decoder,(i))
    # print(sub_decoder_input)
    sub_decoder_input_repeated = RepeatVector(y_char_max_len)(sub_decoder_input)
    sub_decoder = LSTM(256,return_sequences=True,name='sub_decoder')(sub_decoder_input_repeated)
    sub_decoder_output = TimeDistributed(Dense(58,activation='softmax'),name='sub_decoder_output')(sub_decoder)
    sub_decoder_output_reshaped = Reshape((1,y_char_max_len,58))(sub_decoder_output)
    print("Sub decoder output is ",sub_decoder_output_reshaped)

I have written the above snippet where y_word_max_len = 9

and main_decoder is a tensor of shape (None,9,256)

and y_char_max_len = 7

58 is the size of my output after the snippet was excecuted the output was

Sub decoder output is Tensor("reshape_2/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_3/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_4/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_5/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_6/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_7/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_8/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_9/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

Sub decoder output is Tensor("reshape_10/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)


Now I want to concatenate all the tensors (9) thus obtained into a single resultant tensor of

shape (?,9,7,58)

how can I achieve that in Keras. Thanks

1

1 Answers

0
votes

Add a Concatenate layer:

joined = Concatenate(axis=1)([sub1, sub2, sub3, sub4, sub5....])

For that, the best is to create a list of the subtensors and use the loop to append to this list:

subTensors = []
for ..... :
    #calculations
    subTensors.append(sub_decoder_output_reshaped)


joined = Concatenate(axis=1)(subTensors)