Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import TensorFlow library.
TensorFlow
import [1] as tf
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'torch' which is PyTorch's library name.
Using 'keras' which is a high-level API.
✗ Incorrect
TensorFlow is imported using the name 'tensorflow'.
2fill in blank
mediumComplete the code to create a tensor with PyTorch.
TensorFlow
import torch x = [1]([1, 2, 3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Tensor' which is incorrect capitalization.
Using 'Variable' which is deprecated.
✗ Incorrect
PyTorch creates tensors using torch.tensor() with a lowercase 't'.
3fill in blank
hardFix the error in the TensorFlow code to create a constant tensor.
TensorFlow
import tensorflow as tf x = tf.[1]([1, 2, 3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Variable' instead of 'constant'.
Using 'Tensor' which is not a TensorFlow function.
✗ Incorrect
TensorFlow creates constant tensors using tf.constant().
4fill in blank
hardFill both blanks to define a simple linear model in PyTorch.
TensorFlow
import torch.nn as nn model = nn.[1](in_features=10, [2]=1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Conv2d' which is a convolutional layer.
Using 'in_features' twice instead of 'out_features'.
✗ Incorrect
PyTorch linear layers are created with nn.Linear and require 'in_features' and 'out_features' parameters.
5fill in blank
hardFill all three blanks to compile and train a TensorFlow model.
TensorFlow
model.compile(optimizer='[1]', loss='[2]', metrics=['[3]']) model.fit(x_train, y_train, epochs=5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sgd' optimizer with incompatible loss.
Using 'categorical_crossentropy' instead of 'sparse_categorical_crossentropy' for integer labels.
✗ Incorrect
Common TensorFlow compile parameters include 'adam' optimizer, 'sparse_categorical_crossentropy' loss, and 'accuracy' metric.