peal.data.dataset_utils

Label-file parsers that turn csv/json annotations into tensors and split keys.

These helpers back the image and tabular datasets in peal.data: they read a label table, convert every row into a float tensor, optionally subsample the rows so that a target attribute and a confounder co-occur with a prescribed probability (the controlled “Clever Hans” datasets), optionally overwrite the confounder column with human “spray” labels, and finally return the keys that belong to the requested train/val/test partition. Splitting is made deterministic with random.seed(0).

Functions

parse_csv

Parse a csv label table into per-sample tensors and the keys of one split.

parse_json

Parse a json label file of a confounder-controlled dataset.

process_confounder_data_controlled

Subsample rows so that target and confounder co-occur at a fixed rate.