我正在运行Bi-LSTM模型,该模型将输入作为2D嵌入层,因为BiLSTM采用3D,所以我正在使用tf.keras.Shashape将其重塑为3D,但显示以下错误
x = tf.keras.layers.Reshape((max_seq_length,768))(x)
x = tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(1024,return_sequences=True,activation='relu'))(x)
x = tf.keras.layers.MaxPool1D()(x)
print(x.shape)
x = tf.keras.layers.Flatten()(x)
print(x.shape)
x = tf.keras.layers.Dense(256,kernel_regularizer=regularizers.l2(0.001))(x)
print(x.shape)
x = tf.keras.layers.LeakyReLU(alpha=0.1)(x)
print(x.shape)
x = tf.keras.layers.Dropout(0.5)(x)
print(x.shape)
pred = tf.keras.layers.Dense(2, activation='softmax')(x)
model = tf.keras.models.Model(inputs=bert_inputs, outputs=pred)
model.compile(loss='categorical_crossentropy', optimizer=tf.keras.optimizers.Adam(epsilon=0.001), metrics=['accuracy'])
model.summary()
InvalidArgumentError: Input to reshape is a tensor with 24576 values, but the requested shape has 3145728
[[{{node reshape_6/Reshape}}]]
[[{{node loss_3/add}}]]