recbole.data.dataloader.knowledge_dataloader

class recbole.data.dataloader.knowledge_dataloader.KGDataLoader(config, dataset, sampler, batch_size=1, dl_format=<InputType.PAIRWISE: 2>, shuffle=False)[source]

Bases: recbole.data.dataloader.abstract_dataloader.AbstractDataLoader

KGDataLoader is a dataloader which would return the triplets with negative examples in a knowledge graph.

Parameters
  • config (Config) – The config of dataloader.

  • dataset (Dataset) – The dataset of dataloader.

  • sampler (KGSampler) – The knowledge graph sampler of dataloader.

  • batch_size (int, optional) – The batch_size of dataloader. Defaults to 1.

  • dl_format (InputType, optional) – The input type of dataloader. Defaults to PAIRWISE.

  • shuffle (bool, optional) – Whether the dataloader will be shuffle after a round. Defaults to False.

shuffle

Whether the dataloader will be shuffle after a round. However, in KGDataLoader, it’s guaranteed to be True.

Type

bool

data_preprocess()[source]

Do neg-sampling before training/evaluation.

property pr_end

This property marks the end of dataloader.pr which is used in __next__().

setup()[source]

Make sure that the shuffle is True. If shuffle is False, it will be changed to True and give a warning to user.

class recbole.data.dataloader.knowledge_dataloader.KnowledgeBasedDataLoader(config, dataset, sampler, kg_sampler, neg_sample_args, batch_size=1, dl_format=<InputType.POINTWISE: 1>, shuffle=False)[source]

Bases: recbole.data.dataloader.abstract_dataloader.AbstractDataLoader

KnowledgeBasedDataLoader is used for knowledge based model.

It has three states, which is saved in state. In different states, _next_batch_data() will return different Interaction. Detailed, please see state.

Parameters
  • config (Config) – The config of dataloader.

  • dataset (Dataset) – The dataset of dataloader.

  • sampler (Sampler) – The sampler of dataloader.

  • kg_sampler (KGSampler) – The knowledge graph sampler of dataloader.

  • neg_sample_args (dict) – The neg_sample_args of dataloader.

  • batch_size (int, optional) – The batch_size of dataloader. Defaults to 1.

  • dl_format (InputType, optional) – The input type of dataloader. Defaults to POINTWISE.

  • shuffle (bool, optional) – Whether the dataloader will be shuffle after a round. Defaults to False.

state

This dataloader has three states:

In the first state, this dataloader would only return the triplets with negative examples in a knowledge graph.

In the second state, this dataloader would only return the user-item interaction.

In the last state, this dataloader would return both knowledge graph information and user-item interaction information.

Type

KGDataLoaderState

property pr

Pointer of KnowledgeBasedDataLoader. It would be affect by self.state.

property pr_end

This property marks the end of dataloader.pr which is used in __next__().

set_mode(state)[source]

Set the mode of KnowledgeBasedDataLoader, it can be set to three states:

  • KGDataLoaderState.RS

  • KGDataLoaderState.KG

  • KGDataLoaderState.RSKG

The state of KnowledgeBasedDataLoader would affect the result of _next_batch_data().

Parameters

state (KGDataLoaderState) – the state of KnowledgeBasedDataLoader.