Implementation:Huggingface Datasets Split
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, NLP |
| Last Updated | 2026-02-14 18:00 GMT |
Overview
Concrete tool for defining standard dataset split names provided by the HuggingFace Datasets library.
Description
Split is an enum-like class that defines the standard dataset split names: TRAIN, TEST, VALIDATION, and ALL. Each constant is a NamedSplit instance (a string subclass). Custom split names can be created by calling Split("custom_name"), which returns a NamedSplit for any name or a NamedSplitAll for "all". Split objects are used throughout the library for split identification in dataset construction, loading, and publishing.
Usage
Use Split constants to reference standard splits in dataset builders, generators, and loading functions. Use Split("name") to create custom split names.
Code Reference
Source Location
- Repository: datasets
- File:
src/datasets/splits.py - Lines: 407-453
Signature
class Split:
TRAIN = NamedSplit("train")
TEST = NamedSplit("test")
VALIDATION = NamedSplit("validation")
ALL = NamedSplitAll()
def __new__(cls, name):
"""Create a custom split with datasets.Split('custom_name')."""
return NamedSplitAll() if name == "all" else NamedSplit(name)
Import
from datasets import Split
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str |
Yes (for custom splits) | Name of the custom split. Not needed when using predefined constants. |
Outputs
| Name | Type | Description |
|---|---|---|
| instance | NamedSplit or NamedSplitAll |
A split identifier usable throughout the Datasets library. |
Usage Examples
Basic Usage
from datasets import Split, Dataset
# Use predefined constants
ds = Dataset.from_dict({"text": ["Hello"]}, split=Split.TRAIN)
# Create custom split
custom_split = Split("my_custom_split")
# Use in load_dataset
from datasets import load_dataset
ds = load_dataset("squad", split=Split.VALIDATION)