LSTM forecasting tensorflow use of batch, repeat and shuffle

I came across these two pages - page 1 and page 2 which use LSTM for forecasting.

the second link uses below code:

batch_size = 256
buffer_size = 150

train_data = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_data = train_data.cache().shuffle(buffer_size).batch(batch_size).repeat()

val_data = tf.data.Dataset.from_tensor_slices((x_vali, y_vali))
val_data = val_data.batch(batch_size).repeat()

while the first link doesn’t use similar code at all. I have relatively small dataset.

Please guide me regarding when I should use above code and when I shouldn’t. I saw stackoverflow posts regarding batch, repeat, shuffle but I am not clear. Please keep in mind I am building a forecasting model

batch , repeat , shuffle are generally called when working with tf.data dataset.

Basically tensorflow accept dataset in various format, e.g. numpy’s array, TF’s tensor, tf.data dataset.

For a small dataset, generally I prefer using numpy’s array.
But I tend to use tf.data only when i need a certain feature, e.g.:

  • Working with variable-length sequence data.
  • Your RAM is not sufficient to load the whole dataset from your disk. tf.data can help by loading only several batches of data from disk, using them for training, unloading them when not being used anymore, and then load another different batches of data from the disk.