lenskit.graphs.lightgcn#
LightGCN recommendation.
Classes#
Configuration for |
|
Scorer using |
|
Protocol implemented by iterative trainers for models. Models that |
|
Protocol implemented by iterative trainers for models. Models that |
|
Protocol implemented by iterative trainers for models. Models that |
Module Contents#
- class lenskit.graphs.lightgcn.LightGCNConfig#
Bases:
lenskit.config.common.EmbeddingSizeMixin,pydantic.BaseModelConfiguration for
LightGCNScorer.- Stability:
Experimental
- embedding_size: pydantic.PositiveInt = 16#
The dimension of the embedding space (number of latent features). Seems to work best as a power of 2.
- layer_count: pydantic.PositiveInt = 2#
The number of layers to use.
- layer_blend: pydantic.PositiveFloat | list[pydantic.PositiveFloat] | None = None#
The blending coefficient(s) for layer blending. This is equivalent to
alphainLightGCN.
- batch_size: pydantic.PositiveInt = 4096#
The training batch size.
- learning_rate: pydantic.PositiveFloat = 0.01#
The learning rate for training.
- epochs: pydantic.PositiveInt = 10#
The number of training epochs.
- loss: Literal['logistic', 'pairwise'] = 'pairwise'#
The loss to use for model training.
pairwiseBPR pairwise ranking loss, using
LightGCN.recommend_loss().logisticLogistic link prediction loss, using
LightGCN.link_pred_loss().
- check_layer_blending()#
- Return type:
Self
- class lenskit.graphs.lightgcn.LightGCNScorer(config=None, **kwargs)#
Bases:
lenskit.training.UsesTrainer,lenskit.pipeline.components.Component[lenskit.data.ItemList]Scorer using
LightGCN[].- Stability:
Experimental
- Parameters:
config (object | None)
kwargs (Any)
- config: LightGCNConfig#
The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.
- users: lenskit.data.Vocabulary#
- items: lenskit.data.Vocabulary#
- model: torch_geometric.nn.LightGCN#
- to(device)#
Move the model to a different device.
- __call__(query, items)#
Generate item scores for a user.
Note that user and items are both user and item IDs, not positions.
- Parameters:
query (lenskit.data.QueryInput)
items (lenskit.data.ItemList)
- Return type:
- create_trainer(data, options)#
Create a model trainer to train this model.
- class lenskit.graphs.lightgcn.LightGCNTrainer(scorer, data, options)#
Bases:
lenskit.training.ModelTrainerProtocol implemented by iterative trainers for models. Models that implement
UsesTrainerwill return an object implementing this protocol from theircreate_trainer()method.This protocol only defines the core aspects of training a model. Trainers should also implement
ParameterContainerto allow training to be checkpointed and resumed.It is also a good idea for the trainer to be pickleable, but the parameter container interface is the primary mechanism for checkpointing.
- Stability:
- Full (see Stability Levels).
- Parameters:
scorer (LightGCNScorer)
data (lenskit.data.Dataset)
options (lenskit.training.TrainingOptions)
- scorer: LightGCNScorer#
- data: lenskit.data.Dataset#
- options: lenskit.training.TrainingOptions#
- model: torch_geometric.nn.LightGCN#
- edges: torch.Tensor#
- optimizer: torch.optim.Optimizer#
- train_epoch()#
Perform one epoch of the training process, optionally returning metrics on the training behavior. After each training iteration, the mmodel must be usable.
- finalize()#
Finish the training process, cleaning up any unneeded data structures and doing any finalization steps to the model.
The default implementation does nothing.
- abstractmethod batch_loss(mb_edges, scores)#
- Parameters:
mb_edges (torch.Tensor)
scores (torch.Tensor)
- Return type:
- class lenskit.graphs.lightgcn.LogisticLightGCNTrainer(scorer, data, options)#
Bases:
LightGCNTrainerProtocol implemented by iterative trainers for models. Models that implement
UsesTrainerwill return an object implementing this protocol from theircreate_trainer()method.This protocol only defines the core aspects of training a model. Trainers should also implement
ParameterContainerto allow training to be checkpointed and resumed.It is also a good idea for the trainer to be pickleable, but the parameter container interface is the primary mechanism for checkpointing.
- Stability:
- Full (see Stability Levels).
- Parameters:
scorer (LightGCNScorer)
data (lenskit.data.Dataset)
options (lenskit.training.TrainingOptions)
- batch_loss(mb_edges, scores)#
- Parameters:
mb_edges (torch.Tensor)
scores (torch.Tensor)
- class lenskit.graphs.lightgcn.PairwiseLightGCNTrainer(scorer, data, options)#
Bases:
LightGCNTrainerProtocol implemented by iterative trainers for models. Models that implement
UsesTrainerwill return an object implementing this protocol from theircreate_trainer()method.This protocol only defines the core aspects of training a model. Trainers should also implement
ParameterContainerto allow training to be checkpointed and resumed.It is also a good idea for the trainer to be pickleable, but the parameter container interface is the primary mechanism for checkpointing.
- Stability:
- Full (see Stability Levels).
- Parameters:
scorer (LightGCNScorer)
data (lenskit.data.Dataset)
options (lenskit.training.TrainingOptions)
- batch_loss(mb_edges, scores)#
- Parameters:
mb_edges (torch.Tensor)
scores (torch.Tensor)
Exported Aliases#
- class lenskit.graphs.lightgcn.EmbeddingSizeMixin#
Re-exported alias for
lenskit.config.common.EmbeddingSizeMixin.
- class lenskit.graphs.lightgcn.BatchedRange#
Re-exported alias for
lenskit.data.BatchedRange.
- class lenskit.graphs.lightgcn.Dataset#
Re-exported alias for
lenskit.data.Dataset.
- class lenskit.graphs.lightgcn.ItemList#
Re-exported alias for
lenskit.data.ItemList.
- class lenskit.graphs.lightgcn.MatrixRelationshipSet#
Re-exported alias for
lenskit.data.MatrixRelationshipSet.
- lenskit.graphs.lightgcn.QueryInput#
Re-exported alias for
lenskit.data.QueryInput.
- class lenskit.graphs.lightgcn.RecQuery#
Re-exported alias for
lenskit.data.RecQuery.
- class lenskit.graphs.lightgcn.Vocabulary#
Re-exported alias for
lenskit.data.Vocabulary.
- class lenskit.graphs.lightgcn.COOStructure#
Re-exported alias for
lenskit.data.matrix.COOStructure.
- lenskit.graphs.lightgcn.item_progress()#
Re-exported alias for
lenskit.logging.progress._dispatch.item_progress().
- class lenskit.graphs.lightgcn.Component#
Re-exported alias for
lenskit.pipeline.components.Component.
- lenskit.graphs.lightgcn.inference_mode()#
Re-exported alias for
lenskit.torch.inference_mode().
- class lenskit.graphs.lightgcn.ModelTrainer#
Re-exported alias for
lenskit.training.ModelTrainer.
- class lenskit.graphs.lightgcn.TrainingOptions#
Re-exported alias for
lenskit.training.TrainingOptions.
- class lenskit.graphs.lightgcn.UsesTrainer#
Re-exported alias for
lenskit.training.UsesTrainer.