Complete the code to create a simple neural network model using TensorFlow Keras.
import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Dense(10, activation=[1]) ])
The activation function "relu" is commonly used in the first layer of a neural network to introduce non-linearity.
Complete the code to compile the model with an optimizer.
model.compile(optimizer=[1], loss='sparse_categorical_crossentropy', metrics=['accuracy'])
"adam" is a widely used optimizer that adapts the learning rate during training for better performance.
Fix the error in the code to train the model on data.
history = model.fit(x_train, y_train, epochs=[1])The epochs parameter must be an integer specifying how many times the model sees the entire dataset.
Fill both blanks to create a dictionary of training accuracy and loss from the history object.
metrics = { 'accuracy': history.history[[1]], 'loss': history.history[[2]] }The keys 'accuracy' and 'loss' in history.history store the training accuracy and loss values respectively.
Fill all three blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.
lengths = { [1]: [2] for [3] in words if len([3]) > 3 }This dictionary comprehension creates keys as words and values as their lengths, filtering words longer than 3 characters.