Hugging Face Datasets features: column types, ClassLabel and cast
Short answer
dataset.features is a dict of column name to column type. It tells you, for example, that a label column is a ClassLabel with named classes stored as integers. Change types with cast() or cast_column(), which return a new dataset. [S1][S2]
Example
from datasets import ClassLabel, Value
ds = ds.cast_column("label", ClassLabel(names=["neg", "pos"]))
print(ds.features)
Use List for list-valued columns and nested dicts for structured fields. [S1]
Claims
- id: C1 claim: Features defines a dataset's internal structure. source: S1 evidence: "Features defines the internal structure of a dataset."
- id: C2 claim: The Features format is a dict of column name to type. source: S1 evidence: "It is a dictionary of column name and column type pairs."
- id: C3 claim: ClassLabel labels are stored as integers. source: S1 evidence: "Labels are stored as integers in the dataset."
- id: C4 claim: cast transforms the feature type of columns. source: S2 evidence: "function transforms the feature type of one or more columns"
- id: C5 claim: Processing methods return a new Dataset, not in-place. source: S2 evidence: "Modification is not done in-place."
Sources
- [S1] Dataset features · Hugging Face. Hugging Face (Datasets docs). https://huggingface.co/docs/datasets/about_dataset_features . License: Apache-2.0 (huggingface/datasets docs). Accessed 2026-11-04.
- [S2] Process · Hugging Face. Hugging Face (Datasets docs). https://huggingface.co/docs/datasets/process . 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).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Hugging Face (Datasets docs), Dataset features · Hugging Face, Apache-2.0 (huggingface/datasets docs); Hugging Face (Datasets docs), Process · Hugging Face, Apache-2.0 (huggingface/datasets docs).
Cite this
iinventedlight. 2026. "Hugging Face Datasets features: column types, ClassLabel and cast." iinventedlight Library, iil:note:wfb7hcd8, version of 2026-11-04. https://iinventedlight.com/library/notes/hf-datasets-features-casting/. License: CC-BY-4.0.
@misc{iil_note_wfb7hcd8,
author = {{iinventedlight}},
title = {{Hugging Face Datasets features: column types, ClassLabel and cast}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/hf-datasets-features-casting/},
note = {Permanent ID iil:note:wfb7hcd8. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/hf-datasets-features-casting.md.