I have two inputs of same size and then applied word embeddings of vector size 128 and then reshape it giving both inputs shape of (none,1,128), another input which is context has dimension (none,1,18), I want to concatenate these three inputs and then feed the combined output to an LSTM layer. But I am unable to concatenate the inputs as dimensions are different with this error:
A Concatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 1, 128), (None, 1, 128), (None, 1, 18)]
combined= Concatenate(axis=-2)([input_1,input_2, input_3])
The two inputs of shape (none,1,128) are word embeddings while third input of shape(none,1,18) is one hot encoding of some categorial variable.
Does anyone know how to do concatenate this? Any help would be greatly appreciated!
Advertisement
Answer
concatenate them on the last dimension
input_1 = Input((1,128)) input_2 = Input((1,128)) input_3 = Input((1,18)) combined = Concatenate(axis=-1)([input_1,input_2, input_3])
this produces a combined tensor of shape (batch_dim, 1, 274)