Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small updates to to_tf_dataset documentation #3215

Merged
merged 4 commits into from
Nov 4, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/source/use_dataset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ After you set the format, wrap the dataset with ``torch.utils.data.DataLoader``.
TensorFlow
^^^^^^^^^^

If you are using TensorFlow, set the format with ``to_tf_dataset``, which accepts several arguments:
If you are using TensorFlow, you can use ``to_tf_dataset`` to wrap the dataset with a `tf.data.Dataset`.
`tf.data.Dataset` objects can be iterated over to yield batches of data, and are natively understood by Keras, which
Rocketknight1 marked this conversation as resolved.
Show resolved Hide resolved
means they can be passed directly to methods like `model.fit()`. `to_tf_dataset()` accepts several arguments:

1. ``columns`` specify which columns should be formatted (includes the inputs and labels).

Expand All @@ -110,7 +112,8 @@ If you are using TensorFlow, set the format with ``to_tf_dataset``, which accept
... batch_size=16,
... collate_fn=data_collator,
... )
>>> next(iter(train_dataset))
>>> model.fit(train_dataset) # The output tf.data.Dataset is ready for training immediately
>>> next(iter(train_dataset)) # You can also iterate over the dataset manually to get batches
{'attention_mask': <tf.Tensor: shape=(16, 512), dtype=int64, numpy=
array([[1, 1, 1, ..., 0, 0, 0],
...,
Expand All @@ -129,6 +132,6 @@ If you are using TensorFlow, set the format with ``to_tf_dataset``, which accept

.. tip::

``to_tf_dataset`` is the easiest way to create a TensorFlow compatible dataset. If you are looking for additional options for constructing a TensorFlow dataset, take a look at the :ref:`format` section!
``to_tf_dataset`` is the easiest way to create a TensorFlow compatible dataset. If, however, you don't want a `tf.data.Dataset`, but you would like the dataset to emit `tf.Tensor` objects, take a look at the :ref:`format` section instead!
Rocketknight1 marked this conversation as resolved.
Show resolved Hide resolved

Your dataset is now ready for use in a training loop!