

Note that in the code sample above, you need to pass the tokenizer to prepare_tf_dataset so it can correctly pad batches as they're loaded.
If all the samples in your dataset are the same length and no padding is necessary, you can skip this argument.
If you need to do something more complex than just padding samples (e.g. corrupting tokens for masked language
modelling), you can use the collate_fn argument instead to pass a function that will be called to transform the
list of samples into a batch and apply any preprocessing you want. See our
examples or
notebooks to see this approach in action.
Once you've created a tf.data.Dataset, you can compile and fit the model as before: