Unit II Laboratory: Train Your First Custom Model

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/47

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:22 AM on 9/15/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

48 Terms

1
New cards

What is the shape of a batch of 50 RGB images of size 64×64?

a) [50, 64, 64, 3] b) [50, 64, 64, 1] c) [64, 64, 3] d) [50, 64, 64]

a

2
New cards

Complete the code so a rank-1 tensor is created: tf.\_\_\_\_([10, 20, 30]).print();

a) tensor2d b) tensor1d c) tensor3d d) tensor

b

3
New cards

What is the shape of the tensor created by tf.tensor2d([[1,2,3],[4,5,6]])?

a) [6] b) [3,2] c) [2,3] d) [2,2]

c

4
New cards

Complete the code so a 3×3 tensor of zeros is created: tf.\_\_\_\_([3,3]).print();

a) ones b) empty c) fill d) zeros

d

5
New cards

What does the line b.div(b.max()) accomplish, in one word?

a) Normalization b) Scaling c) Encoding d) Shuffling

a

6
New cards

What is the result of a.add(b) where a = tf.tensor1d([1,2,3]) and b = tf.tensor1d([10,20,30])?

a) [1,2,3] b) [11,22,33] c) [10,20,30] d) [5,10,15]

b

7
New cards

What is the result of a.mul(5) where a = tf.tensor1d([1,2,3])?

a) [11,22,33] b) [10,20,30] c) [5,10,15] d) [1,2,3]

c

8
New cards

What does tf.tidy() do?

a) Shuffles tensors b) Trains a model c) Encodes categories d) Automatically disposes tensors created inside the callback

d

9
New cards

Complete the code so features and labels are shuffled together: tf.util.\_\_\_\_(xsRaw, ysRaw);

a) shuffleCombo b) shuffle c) shuffleBoth d) mix

a

10
New cards

Why is shuffling before splitting essential for the Iris dataset?

a) It reduces file size b) The file is sorted by species, so without shuffling the test set would be 100% virginica c) It increases the number of features d) It converts labels to one-hot

b

11
New cards

Complete the code so the fetched iris.json is parsed into an object: const data = await (await fetch('iris.json')).\_\_\_\_();

a) text() b) parse() c) json() d) data()

c

12
New cards

What is the shape of the ys tensor after tf.tensor2d(ysRaw) in Activity 2, where ysRaw has 150 one-hot labels for 3 species?

a) [150, 4] b) [150, 1] c) [3, 150] d) [150, 3]

d

13
New cards

Complete the normalization so the tensor is scaled to 0–1: xs.sub(min).div(max.\_\_\_\_(min));

a) sub b) div c) add d) mul

a

14
New cards

What does xs.min(0) return in Activity 2?

a) The global minimum of all values b) The per-column minimum c) The first element d) The index of the minimum

b

15
New cards

Complete the code so the split index is an integer: const split = Math.\_\_\_\_(150 * 0.8);

a) round b) ceil c) floor d) trunc

c

16
New cards

What is the expected shape of trainXs after the 80/20 split in Activity 2?

a) [30, 4] b) [150, 4] c) [4, 120] d) [120, 4]

d

17
New cards

Complete the code so the tensor is split into two equal halves: const [trainXs, testXs] = tf.\_\_\_\_(xsNorm, [split, 150 - split]);

a) split b) cut c) partition d) divide

a

18
New cards

Which activation function is used in the final layer of the Iris multi-class classifier?

a) relu b) softmax c) sigmoid d) tanh

b

19
New cards

Which loss function is used to compile the Iris multi-class classifier?

a) binaryCrossentropy b) meanSquaredError c) categoricalCrossentropy d) hinge

c

20
New cards

Complete the compile call so accuracy is tracked: model.compile({ optimizer: 'adam', loss: 'categoricalCrossentropy', metrics: ['\_\_\_\_'] });

a) score b) precision c) loss d) accuracy

d

21
New cards

What does tfvis.show.fitCallbacks provide during training?

a) Live loss/accuracy curves drawn in the visor b) A model summary c) A scatterplot of the data d) A saved copy of the model

a

22
New cards

Complete the fit call so 20% of training data is reserved for validation: await model.fit(trainXs, trainYs, { epochs: 60, batchSize: 16, \_\_\_\_: 0.2, ... });

a) testSplit b) validationSplit c) holdout d) trainSplit

b

23
New cards

Complete the code so the model is evaluated on the held-out test set: const [testLoss, testAcc] = model.\_\_\_\_(testXs, testYs);

a) fit b) predict c) evaluate d) compile

c

24
New cards

What does probs.argMax(1).dataSync()[0] return?

a) The probability value of the top class b) The total number of classes c) The sorted array of probabilities d) The index of the highest-probability class

d

25
New cards

In the Student Grade Predictor, what shape must the label tensor have?

a) [N, 1] b) [N, 3] c) [1, N] d) [N]

a

26
New cards

Why does the Student Grade Predictor's label need no one-hot encoding?

a) Because one-hot encoding is too slow in the browser b) Because the output is binary — a single 0/1 value is sufficient c) Because TensorFlow.js does not support one-hot d) Because the label is text-based

b

27
New cards

Which activation function is required in the final layer of the Student Grade Predictor?

a) relu b) softmax c) sigmoid d) tanh

c

28
New cards

Which loss function is required for the Student Grade Predictor?

a) categoricalCrossentropy b) meanSquaredError c) hinge d) binaryCrossentropy

d

29
New cards

Complete the code so the trained grade model is stored in the browser: await model.save('\_\_\_\_://grade-model');

a) indexeddb b) localstorage c) downloads d) browser

a

30
New cards

Complete the code so the saved grade model is reloaded: model = await tf.\_\_\_\_('indexeddb://grade-model');

a) loadModel b) loadLayersModel c) loadGraphModel d) restoreModel

b

31
New cards

On page load, what should happen if the model loads successfully from IndexedDB?

a) Retrain the model immediately b) Show an error to the user c) Skip training d) Save a fresh copy

c

32
New cards

When normalizing the user's typed input in the interface, which min/max should you use?

a) New min/max computed from the entered values b) Min/max from the iris dataset c) Min/max of 0 and 1 d) The same min/max used in training

d

33
New cards

What is the most likely cause of loss becoming NaN during training?

a) Unnormalized inputs or a learning-rate explosion b) Using tf.tidy() c) Splitting the data 80/20 d) Using softmax as the final activation

a

34
New cards

If accuracy is stuck at ~0.5 (binary) or ~0.33 (iris), what is the likely cause?

a) Batch size is too small b) Labels were not shuffled together with features c) The learning rate is too low d) The model has too many layers

b

35
New cards

Complete the fix for the "input shape mismatch" error when predicting: tf.\_\_\_\_([[h, a, q]])

a) tensor1d b) tensor3d c) tensor2d d) scalar

c

36
New cards

What causes the page to freeze over time in a repeated inference loop?

a) The browser cache filling up b) Too many epochs c) Small batch size d) A tensor leak (tensors not disposed)

d

37
New cards

How do you prevent a tensor leak in per-frame or per-click tensor code?

a) Wrap the code in tf.tidy() and dispose prediction tensors b) Increase the learning rate c) Reduce the number of layers d) Use tensor1d instead of tensor2d

a

38
New cards

Complete the call so tfjs-vis draws the training curves: callbacks: tfvis.show.\_\_\_\_({ name: 'Training Performance' }, ['loss', 'val_loss', 'acc', 'val_acc']);

a) show.callbacks b) fitCallbacks c) trainCallbacks d) render.callbacks

b

39
New cards

What does model.predict(sample) do?

a) Trains the model b) Evaluates the model c) Runs inference on the trained model d) Compiles the model

c

40
New cards

Why must the prediction tensor be 2-D (shape [1, 3]) rather than 1-D?

a) Because the model was compiled for regression b) Because softmax only works on 2-D tensors c) Because the model uses a sigmoid activation d) Because the model expects a batch dimension, even when predicting a single row

d

41
New cards

tf.tidy() automatically disposes any tensors created inside its callback.

True

42
New cards

The iris.json file is sorted randomly, so skipping the shuffle step is harmless.

False

43
New cards

For the Student Grade Predictor, the label needs one-hot encoding before training.

False

44
New cards

The recommended loss function for the binary grade predictor is categoricalCrossentropy.

False

45
New cards

If accuracy is stuck at ~0.5 for a binary problem, the likely cause is that labels were not shuffled together with features.

True

46
New cards

The "input shape mismatch" error is fixed by using tf.tensor1d(...) instead of tf.tensor2d(...).

False

47
New cards

If the model loads successfully from IndexedDB on page load, training should be skipped.

True

48
New cards

User input in the grade predictor interface should be normalized with a new min/max computed from the typed values.

False