recbole.utils.utils

recbole.utils.utils.calculate_valid_score(valid_result, valid_metric=None)[source]

return valid score from valid result

Parameters
  • valid_result (dict) – valid result

  • valid_metric (str, optional) – the selected metric in valid result for valid score

Returns

valid score

Return type

float

recbole.utils.utils.dict2str(result_dict)[source]

convert result dict to str

Parameters

result_dict (dict) – result dict

Returns

result str

Return type

str

recbole.utils.utils.early_stopping(value, best, cur_step, max_step, bigger=True)[source]

validation-based early stopping

Parameters
  • value (float) – current result

  • best (float) – best result

  • cur_step (int) – the number of consecutive steps that did not exceed the best result

  • max_step (int) – threshold steps for stopping

  • bigger (bool, optional) – whether the bigger the better

Returns

  • float, best result after this step

  • int, the number of consecutive steps that did not exceed the best result after this step

  • bool, whether to stop

  • bool, whether to update

Return type

tuple

recbole.utils.utils.ensure_dir(dir_path)[source]

Make sure the directory exists, if it does not exist, create it

Parameters

dir_path (str) – directory path

recbole.utils.utils.get_local_time()[source]

Get current time

Returns

current time

Return type

str

recbole.utils.utils.get_model(model_name)[source]

Automatically select model class based on model name

Parameters

model_name (str) – model name

Returns

model class

Return type

Recommender

recbole.utils.utils.get_trainer(model_type, model_name)[source]

Automatically select trainer class based on model type and model name

Parameters
  • model_type (ModelType) – model type

  • model_name (str) – model name

Returns

trainer class

Return type

Trainer

recbole.utils.utils.init_seed(seed, reproducibility)[source]

init random seed for random functions in numpy, torch, cuda and cudnn

Parameters
  • seed (int) – random seed

  • reproducibility (bool) – Whether to require reproducibility