Curse of Dimensionality - Week 2: Model Resource Management Techniques |

Hi , I am attempting to recreate the code from this lecture(Week 2, MLOps Course 3) and I keep getting the following error shown in the screenshot. Is there any part of the code that is not shown in the video that could fix this error. I get the same error for the 1000 dimensional setup as well as the 6 dimensional setup.
Please let me know how i can fix, thanks!
Model setup:

1000 dimension build:

6 dimension build:

Please fix the validation_data parameter of model.fit call.
You are passing in reuters_test_x with reuters_train_y. You should use reuters_test_y instead.

Also, model.fit returns a history object and not a model.

1 Like

I have just done that but am still getting the same error, shown below:

I have also fixed the typo in my setup to model to reuters_test_y as was uploaded in the screenshots before.

Is there anywhere else that might have an issue causing this?

It’s possible that you made another error in the code.

Here’s an example of a code that works:

import tensorflow as tf
from tensorflow import keras
from keras.datasets import reuters
from keras.utils import pad_sequences
num_words = 1000

(reuters_train_x, reuters_train_y), (reuters_test_x, reuters_test_y) = reuters.load_data(num_words=num_words)
reuters_train_x = pad_sequences(reuters_train_x, maxlen=20)
reuters_test_x = pad_sequences(reuters_test_x, maxlen=20)

model = tf.keras.Sequential([
    keras.layers.Embedding(num_words, 100, input_length=20),
    keras.layers.Flatten(),
    keras.layers.Dense(256, activation='relu'),
    keras.layers.Dense(46, activation='softmax')
])

model.compile(loss='sparse_categorical_crossentropy',
              metrics=['accuracy'],
              optimizer='rmsprop')
              
model.fit(reuters_train_x,
          reuters_train_y,
          validation_data=(reuters_test_x, reuters_test_y),
          epochs=1)

this worked
thank you so much!

Even though this worked, shouldn’t the second param in keras.layers.Embedding be 1000?

In the 1000 dim example he uses 1000 as well as num_words, for the second and first args respectively.
In the subsequent example when Prof is working with 6 dimensions, he passes keras.layers.Embedding(num_words, 6, input_length = 20)
and the second var is 6, while the first is num_words which is still the same as before , 1000.

Basically, im asking why this second value not 1000 but 100?

It was just an example. Please tune the model architecture to your liking.