我正在尝试修改现有模型(此处为TF教程:https://www.tensorflow.org/alpha/tutorials/text/text_generation),以接受3D批处理输入而不是2D批处理输入,但是收到以下错误:
“ transpose需要一个大小为4的向量。但是input(1)是一个大小为3的向量[Op:Transpose]名称:serial_65 / cu_dnngru_66 / transpose /”
我的批次形状为(64,100,9)
batch_size = 64
vocab_size = 42
embedding_dim = 256
rnn_units = 1024
model = tf.keras.Sequential([
tf.keras.layers.Embedding(vocab_size, embedding_dim,
batch_input_shape=[batch_size, None]),
rnn(rnn_units,
return_sequences=True,
recurrent_initializer='glorot_uniform',
stateful=True),
tf.keras.layers.Dense(vocab_size)
])
截断的批量打印:
[[[9 1 0 ... 0 0 0]
[31 0 0 ... 0 0 0]
[28 1 0 ... 1 0 0]
...
[ 9 1 0 ... 0 0 0]
[15 1 0 ... 0 1 0]
[25 0 0 ... 0 0 0]]
[[31 0 0 ... 0 0 0]
[6 0 0 ... 0 0 0]
[22 1 1 ... 0 0 0]
...
[15 1 0 ... 0 1 0]
[28 1 0 ... 1 0 0]
[2 0 0 ... 0 0 0]]
[[31 0 0 ... 0 0 0]
[11 0 0 ... 0 0 0]
[9 1 0 ... 0 0 0]
...
[6 0 0 ... 0 0 0]
[36 1 0 ... 0 0 0]
[17 0 0 ... 0 0 0]]
...
[[27 0 1 ... 0 0 0]
[27 0 1 ... 0 0 0]
[2 0 0 ... 0 0 0]
...
[9 1 0 ... 0 0 0]
[12 0 0 ... 0 0 0]
[36 1 0 ... 0 0 0]]
[[37 1 0 ... 0 0 0]
[34 0 0 ... 0 0 0]
[16 0 0 ... 0 0 1]
...
[1 0 0 ... 0 0 0]
[23 1 0 ... 0 0 0]
[22 1 1 ... 0 0 0]]
[[3 0 0 ... 0 0 0]
[10 1 0 ... 0 0 0]
[12 0 0 ... 0 0 0]
...
[27 0 1 ... 0 0 0]
[12 0 0 ... 0 0 0]
[31 0 0 ... 0 0 0]]], shape=(64, 100, 9), dtype=int32)
我最初的想法是,batch_input_shape需要更改,但是由于反复试验,我无法解决。
任何帮助将不胜感激,谢谢