transformers4rec.torch.model package

Submodules

transformers4rec.torch.model.head module

transformers4rec.torch.model.model module

transformers4rec.torch.model.prediction_task module

class transformers4rec.torch.model.prediction_task.BinaryClassificationPrepareBlock[source]

Bases: transformers4rec.torch.block.base.BuildableBlock

build(input_size)transformers4rec.torch.block.base.SequentialBlock[source]
class transformers4rec.torch.model.prediction_task.BinaryClassificationTask(target_name: Optional[str] = None, task_name: Optional[str] = None, task_block: Optional[Union[transformers4rec.torch.block.base.BlockBase, transformers4rec.torch.block.base.BuildableBlock]] = None, loss=BCELoss(), metrics=(Precision(), Recall(), Accuracy()), summary_type='first')[source]

Bases: transformers4rec.torch.model.base.PredictionTask

DEFAULT_LOSS = BCELoss()
DEFAULT_METRICS = (Precision(), Recall(), Accuracy())
training: bool
class transformers4rec.torch.model.prediction_task.RegressionPrepareBlock[source]

Bases: transformers4rec.torch.block.base.BuildableBlock

build(input_size)transformers4rec.torch.block.base.SequentialBlock[source]
class transformers4rec.torch.model.prediction_task.RegressionTask(target_name: Optional[str] = None, task_name: Optional[str] = None, task_block: Optional[Union[transformers4rec.torch.block.base.BlockBase, transformers4rec.torch.block.base.BuildableBlock]] = None, loss=MSELoss(), metrics=(MeanSquaredError()), summary_type='first')[source]

Bases: transformers4rec.torch.model.base.PredictionTask

DEFAULT_LOSS = MSELoss()
DEFAULT_METRICS = (MeanSquaredError(),)
training: bool
class transformers4rec.torch.model.prediction_task.NextItemPredictionTask(loss: torch.nn.modules.module.Module = NLLLoss(), metrics: Iterable[torchmetrics.metric.Metric] = (NDCGAt(), AvgPrecisionAt(), RecallAt()), task_block: Optional[Union[transformers4rec.torch.block.base.BlockBase, transformers4rec.torch.block.base.BuildableBlock]] = None, task_name: str = 'next-item', weight_tying: bool = False, softmax_temperature: float = 1, padding_idx: int = 0, target_dim: Optional[int] = None, hf_format=False)[source]

Bases: transformers4rec.torch.model.base.PredictionTask

Next-item prediction task.

Parameters
  • loss (torch.nn.Module) – Loss function to use. Defaults to NLLLos.

  • metrics (Iterable[torchmetrics.Metric]) – List of ranking metrics to use for evaluation.

  • task_block – Module to transform input tensor before computing predictions.

  • task_name (str, optional) – Name of the prediction task, if not provided a name will be automatically constructed based on the target-name & class-name.

  • weight_tying (bool) – The item id embedding table weights are shared with the prediction network layer.

  • softmax_temperature (float) – Softmax temperature, used to reduce model overconfidence, so that softmax(logits / T). Value 1.0 reduces to regular softmax.

  • padding_idx (int) – pad token id.

  • target_dim (int) – vocabulary size of item ids

  • hf_format (bool) – Output the dictionary of outputs needed by RecSysTrainer, if set to False, return the predictions tensor.

DEFAULT_METRICS = (NDCGAt(), AvgPrecisionAt(), RecallAt())
build(body, input_size, device=None, inputs=None, task_block=None, pre=None)[source]

Build method, this is called by the Head.

forward(inputs: torch.Tensor, **kwargs)[source]
remove_pad_3d(inp_tensor, non_pad_mask)[source]
calculate_metrics(predictions, targets, mode='val', forward=True, **kwargs)Dict[str, torch.Tensor][source]
compute_metrics()[source]
training: bool
class transformers4rec.torch.model.prediction_task.NextItemPredictionPrepareBlock(target_dim: int, weight_tying: bool = False, item_embedding_table: Optional[torch.nn.modules.module.Module] = None, softmax_temperature: float = 0)[source]

Bases: transformers4rec.torch.block.base.BuildableBlock

build(input_size)transformers4rec.torch.block.base.Block[source]

Module contents