Dataset features
Last updated
Last updated
defines the internal structure of a dataset. It is used to specify the underlying serialization format. Whatβs more interesting to you though is that contains high-level information about everything from the column names and types, to the . You can think of as the backbone of a dataset.
The format is simple: dict[column_name, column_type]
. It is a dictionary of column name and column type pairs. The column type provides a wide range of options for describing the type of data you have.
Letβs have a look at the features of the MRPC dataset from the GLUE benchmark:
Copied
The feature tells π Datasets:
The idx
data type is int32
.
The sentence1
and sentence2
data types are string
.
π Datasets supports many other data types such as bool
, float32
and binary
to name just a few.
Refer to for a full list of supported data types.
Copied
Copied
The array type also allows the first dimension of the array to be dynamic. This is useful for handling sequences with variable lengths such as sentences, without having to pad or truncate the input to a uniform shape.
Copied
array
: the decoded audio data represented as a 1-dimensional array.
path
: the path to the downloaded audio file.
sampling_rate
: the sampling rate of the audio data.
Copied
Index into an audio dataset using the row index first and then the audio
column - dataset[0]["audio"]
- to avoid decoding and resampling all the audio files in the dataset. Otherwise, this can be a slow and time-consuming process if you have a large dataset.
Copied
Copied
Index into an image dataset using the row index first and then the image
column - dataset[0]["image"]
- to avoid decoding all the image files in the dataset. Otherwise, this can be a slow and time-consuming process if you have a large dataset.
Copied
Depending on the dataset, you may get the path to the local downloaded image, or the content of the image as bytes if the dataset is not made of individual files.
You can also define a dataset of images from numpy arrays:
Copied
And in this case the numpy arrays are encoded into PNG (or TIFF if the pixels values precision is important).
For multi-channels arrays like RGB or RGBA, only uint8 is supported. If you use a larger precision, you get a warning and the array is downcasted to uint8. For gray-scale images you can use the integer or float precision you want as long as it is compatible with Pillow
. A warning is shown if your image integer or float precision is too high, and in this case the array is downcated: an int64 array is downcasted to int32, and a float64 array is downcasted to float32.
The feature informs π Datasets the label
column contains two classes. The classes are labeled not_equivalent
and equivalent
. Labels are stored as integers in the dataset. When you retrieve the labels, and carries out the conversion from integer value to label name, and vice versa.
If your data type contains a list of objects, then you want to use the feature. Remember the SQuAD dataset?
The answers
field is constructed using the feature because it contains two subfields, text
and answer_start
, which are lists of string
and int32
, respectively.
See the section to learn how you can extract the nested subfields as their own independent columns.
The array feature type is useful for creating arrays of various sizes. You can create arrays with two dimensions using , and even arrays with five dimensions using .
Audio datasets have a column with type , which contains three important fields:
When you load an audio dataset and call the audio column, the feature automatically decodes and resamples the audio file:
With decode=False
, the type simply gives you the path or the bytes of the audio file, without decoding it into an array
,
Image datasets have a column with type , which loads PIL.Image
objects from images stored as bytes:
When you load an image dataset and call the image column, the feature automatically decodes the image file:
With decode=False
, the type simply gives you the path or the bytes of the image file, without decoding it into an PIL.Image
,