Input 0 of layer "dense_80" is incompatible with the layer: expected axis -1 of input shape to have value 512, - Tensorflow

16 Views Asked by At

I am currently creating a text summary model, everything was going fine until I encountered an issue called ValueError: Dimensions must be equal but are 25 and 700 for '{{node Equal}} = Equal[T=DT_FLOAT, incompatible_shape_error =true ]( Cast_1, Cast_2)' with input shapes: [?,25], [?,700]. I know that the error is because I set a different max_length value in my two tokenizers, but I think it must be like that, because obviously the summarized text should have fewer letters. so to fix the error I used layers x=tf.keras.layers.Flatten(). now I got this error: Input 0 of layer "dense_80" is incompatible with the layer: expected axis -1 of input shape to have value 512, but received input with shape (None, 358400), someone know how to resolve that ? btw i use tensorflow and pretrained bart model with pretrained tokenizer (code is given in fragments):

x_train_tokenN = pre_trained_tokenizer(x_train_data,truncation=True,max_length=700,padding=True,return_tensors='tf')
y_train_tokenN = pre_trained_tokenizer(y_train_data,truncation=True,max_length=25,padding=True,return_tensors='tf')

input_ids= tf.keras.Input(shape=(None,),dtype=tf.int32,name='input_ids')
attention_mask= tf.keras.Input(shape=(None,),dtype=tf.int32,name='attention_mask')
outpott= tf.keras.Input(shape=(None,),dtype=tf.int32,name='outputs')
bert_output = pre_trained_model(input_ids, attention_mask=attention_mask,training=False)[0]
x = tf.keras.layers.Dense(512)(bert_output)
x=tf.keras.layers.Flatten()(x)
output_logits =  tf.keras.layers.Dense(25, activation=None)(x)
my_model = tf.keras.Model(inputs=[input_ids, attention_mask],outputs = output_logits)

optimizer = tf.keras.optimizers.Adam(learning_rate=3e-5)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
metrics = [tf.keras.metrics.SparseCategoricalAccuracy('accuracy')]
my_model.compile(optimizer=optimizer, loss=loss, metrics=metrics)

my_model.fit(x={'input_ids':x_train_tokenN['input_ids'],'attention_mask':x_train_tokenN['attention_mask']},y=y_train_tokenN,batch_size=32,epochs=5)
0

There are 0 best solutions below