---
source: https://iinventedlight.com/library/notes/hf-datasets-pytorch.md
title: "Use Hugging Face Datasets with PyTorch"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (huggingface/datasets docs); restated in our own words"
attribution: "Summary by iinventedlight (AI-assisted). Sources: Hugging Face (Datasets docs), Use with PyTorch · Hugging Face, Apache-2.0 (huggingface/datasets docs); Hugging Face, Use with TensorFlow, Apache-2.0 (huggingface/datasets docs)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-05
as_of: 2026-11-05
confidence: medium
untested: "No code was run; only the fetched Hugging Face documentation pages were read."
category: huggingface-datasets
topic_area: "datasets: pytorch"
tags: huggingface, datasets, pytorch, dataloader
sources:
  - id: S1
    title: "Use with PyTorch · Hugging Face"
    publisher: Hugging Face (Datasets docs)
    url: https://huggingface.co/docs/datasets/use_with_pytorch
    accessed: 2026-11-05
    license: "Apache-2.0 (huggingface/datasets docs)"
  - id: S2
    title: "Use with TensorFlow"
    publisher: Hugging Face
    url: https://huggingface.co/docs/datasets/use_with_tensorflow
    accessed: 2026-11-05
    license: "Apache-2.0 (huggingface/datasets docs)"
    license: "Apache-2.0 (huggingface/datasets docs)"
---
# Hugging Face Datasets with PyTorch (and TensorFlow)

## Short answer
Datasets return Python objects by default. Call `with_format("torch")` (or `"tf"`) to get framework tensors, optionally on a chosen device. [S1][S2]

## Points
- A Dataset wraps an Arrow table. [S1]
- `device` can place tensors on a GPU. [S1]
- The TensorFlow guide shows `with_format("tf")` yielding `tf.Tensor` values. [S2]

## Claims
- id: C1
  claim: Datasets return regular Python objects by default.
  source: S1
  evidence: "By default, datasets return regular python objects"
- id: C2
  claim: with_format switches the dataset to pytorch tensors.
  source: S1
  evidence: "set the format of the dataset to pytorch using Dataset.with_format()"
- id: C3
  claim: A Dataset wraps an Arrow table.
  source: S1
  evidence: "A Dataset object is a wrapper of an Arrow table"
- id: C4
  claim: with_format tf yields TensorFlow tensors.
  source: S2
  evidence: "with_format( "tf" )"

## Sources
- [S1] Use with PyTorch · Hugging Face. Hugging Face (Datasets docs). https://huggingface.co/docs/datasets/use_with_pytorch . License: Apache-2.0 (huggingface/datasets docs). Accessed 2026-11-05.
- [S2] Use with TensorFlow. Hugging Face. https://huggingface.co/docs/datasets/use_with_tensorflow . License: Apache-2.0 (huggingface/datasets docs). Accessed 2026-11-05.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

Source notice: Hugging Face Datasets documentation, Apache License 2.0 (https://github.com/huggingface/datasets/blob/main/LICENSE).
