peal.data.custom_datasets.OnlySparseNumbersDataset

class peal.data.custom_datasets.OnlySparseNumbersDataset[source]

Bases: Image2MixedDataset

Synthetic images showing a 2x4 grid of numbers and nothing else.

OnlySparseNumbersDatasetGenerator writes the dataset on first use. Its data.csv stores one row of 8 slot columns per image, each holding the number drawn in that slot or -1; this class expands that row into a binary vector over all config.output_split (default 1000) possible numbers, so a classifier can be trained on “does number k appear”. Targets are therefore selected by attribute names of the form "Num<k>".

Parameters:
  • config (DataConfig) – Uses dataset_path, output_split, output_size and confounding_factors.

  • **kwargs – Forwarded to the generator and to Image2MixedDataset.

Variables:

attributes (list of str) – Num0 ... Num<output_split - 1>, the expanded label vector; attributes_positive/attributes_negative are its phrasings.

Notes

Since attributes is the expanded vector while data[key] is still the raw slot row, the base-class helpers that index the row by attribute position are overridden below.

Methods

enable_class_restriction

Restrict keys to the samples of one class of the selected number.

set_task_specific_keys

Subsample keys to the proportions in config.class_ratios.

Attributes

__init__(config, **kwargs)[source]

Generate the dataset if missing and build the expanded attribute names.

Parameters:

config (DataConfig)

enable_class_restriction(class_idx)[source]

Restrict keys to the samples of one class of the selected number.

Parameters:

class_idx (int) – 0 keeps the images without the selected number, 1 those with it.

set_task_specific_keys()[source]

Subsample keys to the proportions in config.class_ratios.

Labels are resolved with _expanded_label_value instead of by indexing the raw csv row (see the class notes); the unrestricted keys are kept in keys_backup.