-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lecture #234 - fails with 'ValueError: logits
and labels
must have the same shape, received ((None, 15, 1) vs (None,)'
#514
Comments
Can also confirm the error received as well.
Code Before Changefrom tensorflow.keras import layers
inputs = layers.Input(shape=(1,), dtype="string")
x = text_vectorizer(inputs) # string -> number
x = embedding(x) # number -> dense vector
outputs = layers.Dense(1, activation="sigmoid")(x)
#compile the model
model_1 = tf.keras.Model(inputs, outputs)
model_1.compile(loss="binary_crossentropy",
optimizer=tf.keras.optimizers.Adam(),
metrics=["accuracy"])
# fit the model
history_1 = model_1.fit(x=train_sentences, y=train_labels, epochs=5, validation_data=(val_sentences, val_labels)) Working Code with Changefrom tensorflow.keras import layers
inputs = layers.Input(shape=(1,), dtype="string")
x = text_vectorizer(inputs) # string -> number
x = embedding(x) # number -> dense vector
x = layers.GlobalAveragePooling1D()(x)
outputs = layers.Dense(1, activation="sigmoid")(x)
#compile the model
model_1 = tf.keras.Model(inputs, outputs)
model_1.compile(loss="binary_crossentropy",
optimizer=tf.keras.optimizers.Adam(),
metrics=["accuracy"])
# fit the model
history_1 = model_1.fit(x=train_sentences, y=train_labels, epochs=5, validation_data=(val_sentences, val_labels)) Error you receive from colab
|
my working solution: I used a flatten layer before the Dense layer and it worked
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using tensorflow 2.11.0
the lecture titled " Model 1: Building, fitting and evaluating our first deep model on text data"
fitting the 'feed forward neural network' fails with error
ValueError:
logitsand
labelsmust have the same shape, received ((None, 15, 1) vs (None,)
if appears you now must have the following line (as per your notes but not shown in lecture)
x = layers.GlobalAveragePooling1D()(x)
The text was updated successfully, but these errors were encountered: