Hey all,
the official API doc states on the page regarding tf.keras.layers.Dense that
Note: If the input to the layer has a rank greater than 2, then
Dense
computes the dot product between theinputs
and thekernel
along the last axis of theinputs
and axis 0 of thekernel
(usingtf.tensordot
). For example, if input has dimensions(batch_size, d0, d1)
, then we create akernel
with shape(d1, units)
, and thekernel
operates along axis 2 of theinput
, on every sub-tensor of shape(1, 1, d1)
(there arebatch_size * d0
such sub-tensors). The output in this case will have shape(batch_size, d0, units)
.
My understanding is that only one kernel is created for ranks larger than 2. That would mean that (in case of rank 3) the “middle” dimensions are acted upon by the same kernel and thus the outputs for different indeces of the “middle” dimension are not independent.
Is that understanding correct? And if it is, is there a simple way to get the Dense layer to use a stack of kernels? (The network currently has the tensor multiplication implemented manually.)
Thank you all in advance.
Fabian