A training dataset is the collection of examples a model learns from. For handwritten-digit recognition, each example pairs an image with a label from 0 to 9. The model learns to associate the images with their labels, then makes predictions on images it has not trained on. section 2.1
Listing 2.1 Loading the MNIST dataset in Keras
library(keras3) .[.[train_images, train_labels], .[test_images, test_labels]] <- dataset_mnist()
Load MNIST as separate training and test image–label arrays. The training arrays supply the examples used to fit the model; the test arrays are held back for evaluation. section 2.1
In Keras, `fit(model, train_images, train_labels, epochs = 5, batch_size = 128)` trains on those paired arrays. Before fitting the digit model, reshape each 28 × 28 image into a vector and divide its values by 255. Keep the test images separate: accuracy on training examples alone does not show how well the model handles new ones. section 2.1
Decide what belongs in the training dataset before fitting a model:
- Start with the prediction task. Sentiment classification, for example, needs movie reviews and sentiment annotations; if the required data is unavailable, it may need to be collected and labeled. section 6.1.1
- Split available data into training, validation, and test sets. Fit on training data, use validation results to choose a configuration, and reserve the test set for a final check on unseen data. section 5.2.1
- Prevent validation and test information from leaking into training. For predictions over time, validation and test examples should occur after the training examples. section 20.1.5
A small dogs-versus-cats training set
From 25,000 dog and cat images, make a smaller dataset with 1,000 training images per class, 500 validation images per class, and 1,000 test images per class. This deliberately creates a small-data exercise while keeping each split balanced. section 8.2.2
A larger training dataset is not a guarantee of broad understanding. Models can use shortcuts that fit their examples and fail when inputs depart from familiar patterns. At a different scale, language-model pretraining faces a shortage of high-quality public human-written text. section 19.1.4 section 16.5



































