recbole.data.utils¶
-
class
recbole.data.utils.DLFriendlyAPI[source]¶ Bases:
objectA Decorator class, which helps copying
Datasetmethods toDataLoader.These methods are called DataLoader Friendly APIs.
E.g. if
train_datais an object ofDataLoader, andnum()is a method ofDataset, Cause it has been decorated,num()can be called directly bytrain_data.See the example of
set()for details.-
dataloader_apis¶ Register table that saves all the method names of DataLoader Friendly APIs.
- Type
set
-
-
recbole.data.utils.create_dataset(config)[source]¶ Create dataset according to
config['model']andconfig['MODEL_TYPE'].
-
recbole.data.utils.data_preparation(config, dataset, save=False)[source]¶ Split the dataset by
config['eval_setting']and calldataloader_construct()to create corresponding dataloader.- Parameters
config (Config) – An instance object of Config, used to record parameter information.
dataset (Dataset) – An instance object of Dataset, which contains all interaction records.
save (bool, optional) – If
True, it will callsave_datasets()to save split dataset. Defaults toFalse.
- Returns
train_data (AbstractDataLoader): The dataloader for training.
valid_data (AbstractDataLoader): The dataloader for validation.
test_data (AbstractDataLoader): The dataloader for testing.
- Return type
tuple
-
recbole.data.utils.dataloader_construct(name, config, eval_setting, dataset, dl_format=<InputType.POINTWISE: 1>, batch_size=1, shuffle=False, **kwargs)[source]¶ Get a correct dataloader class by calling
get_data_loader()to construct dataloader.- Parameters
name (str) – The stage of dataloader. It can only take two values: ‘train’ or ‘evaluation’.
config (Config) – An instance object of Config, used to record parameter information.
eval_setting (EvalSetting) – An instance object of EvalSetting, used to record evaluation settings.
dataset (Dataset or list of Dataset) – The split dataset for constructing dataloader.
dl_format (InputType, optional) – The input type of dataloader. Defaults to
POINTWISE.batch_size (int, optional) – The batch_size of dataloader. Defaults to
1.shuffle (bool, optional) – Whether the dataloader will be shuffle after a round. Defaults to
False.**kwargs – Other input args of dataloader, such as
sampler,kg_samplerandneg_sample_args. The meaning of these args is the same as these args in some dataloaders.
- Returns
Constructed dataloader in split dataset.
- Return type
AbstractDataLoader or list of AbstractDataLoader
-
recbole.data.utils.get_data_loader(name, config, eval_setting)[source]¶ Return a dataloader class according to
configandeval_setting.- Parameters
name (str) – The stage of dataloader. It can only take two values: ‘train’ or ‘evaluation’.
config (Config) – An instance object of Config, used to record parameter information.
eval_setting (EvalSetting) – An instance object of EvalSetting, used to record evaluation settings.
- Returns
The dataloader class that meets the requirements in
configandeval_setting.- Return type
type
-
recbole.data.utils.save_datasets(save_path, name, dataset)[source]¶ Save split datasets.
- Parameters
save_path (str) – The path of directory for saving.
name (str or list of str) – The stage of dataloader. It can only take two values: ‘train’ or ‘evaluation’.
dataset (Dataset or list of Dataset) – The split datasets.