recbole.data.utils

class recbole.data.utils.DLFriendlyAPI[source]

Bases: object

A Decorator class, which helps copying Dataset methods to DataLoader.

These methods are called DataLoader Friendly APIs.

E.g. if train_data is an object of DataLoader, and num() is a method of Dataset, Cause it has been decorated, num() can be called directly by train_data.

See the example of set() for details.

dataloader_apis

Register table that saves all the method names of DataLoader Friendly APIs.

Type

set

set()[source]

Example

from recbole.data.utils import dlapi

@dlapi.set()
def dataset_meth():
    ...
recbole.data.utils.create_dataset(config)[source]

Create dataset according to config['model'] and config['MODEL_TYPE'].

Parameters

config (Config) – An instance object of Config, used to record parameter information.

Returns

Constructed dataset.

Return type

Dataset

recbole.data.utils.data_preparation(config, dataset, save=False)[source]

Split the dataset by config['eval_setting'] and call dataloader_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 call save_datasets() to save split dataset. Defaults to False.

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_sampler and neg_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 config and eval_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 config and eval_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.