Use 🤗 Datasets [~datasets.Dataset.set_transform] to apply the transformations on the fly:
py
food["train"].set_transform(preprocess_train)
food["test"].set_transform(preprocess_val)
As a final preprocessing step, create a batch of examples using DefaultDataCollator. Unlike other data collators in 🤗 Transformers, the
DefaultDataCollator does not apply additional preprocessing, such as padding.

from transformers import DefaultDataCollator
data_collator = DefaultDataCollator(return_tensors="tf")