← All notes

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

Sources

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

Permanent ID: iil:note:wfb7hcd8

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.},
}

Markdown

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.