---
source: https://iinventedlight.com/library/notes/hf-datasets-tensorflow.md
title: "Use Hugging Face Datasets with TensorFlow and Keras"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (huggingface/datasets docs); prose restates cited source lines"
attribution: "Summary by iinventedlight (AI-assisted). Sources: Hugging Face (datasets docs), Using Datasets with TensorFlow · Hugging Face, Apache-2.0 (huggingface/datasets docs); Hugging Face (datasets docs), Preprocess · Hugging Face, 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-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched Hugging Face datasets docs pages were read."
category: hf-datasets
topic_area: "code-ai-eng: Hugging Face datasets library"
tags: huggingface, datasets, tensorflow, keras
sources:
  - id: S1
    title: "Using Datasets with TensorFlow · Hugging Face"
    publisher: Hugging Face (datasets docs)
    url: https://huggingface.co/docs/datasets/use_with_tensorflow
    accessed: 2026-11-04
    license: "Apache-2.0 (huggingface/datasets docs)"
  - id: S2
    title: "Preprocess · Hugging Face"
    publisher: Hugging Face (datasets docs)
    url: https://huggingface.co/docs/datasets/use_dataset
    accessed: 2026-11-04
    license: "Apache-2.0 (huggingface/datasets docs)"
---
# Use Hugging Face Datasets with TensorFlow and Keras

## Short answer

```python
tf_ds = ds.to_tf_dataset(columns=["input_ids", "attention_mask"], label_cols="label", batch_size=16, shuffle=True)
model.fit(tf_ds, epochs=3)
```

## Claims
- id: C1
  claim: Set the format to tf to get TensorFlow tensors.
  source: S1
  evidence: "To get TensorFlow tensors instead, you can set the format of the dataset to tf:"
- id: C2
  claim: Models cannot process raw text and need numbers.
  source: S2
  evidence: "Models cannot process raw text, so you’ll need to convert the text into numbers."
- id: C3
  claim: Setting the format is usually the last preprocessing step.
  source: S2
  evidence: "The last preprocessing step is usually setting your dataset format"

## Sources
- [S1] Using Datasets with TensorFlow · Hugging Face. Hugging Face (datasets docs). https://huggingface.co/docs/datasets/use_with_tensorflow . License: Apache-2.0 (huggingface/datasets docs). Accessed 2026-11-04.
- [S2] Preprocess · Hugging Face. Hugging Face (datasets docs). https://huggingface.co/docs/datasets/use_dataset . License: Apache-2.0 (huggingface/datasets docs). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
