deepcarskit.model.fms

DeepFM

References

Huifeng Guo et al. “DeepFM: A Factorization-Machine based Neural Network for CTR Prediction.” in IJCAI 2017.

Notes

context variables are treated as individual dimensions

class deepcarskit.model.fms.deepfm.DeepFM(config, dataset)

Bases: deepcarskit.model.context_recommender.ContextRecommender

DeepFM is a DNN enhanced FM which both use a DNN and a FM to calculate feature interaction. Also DeepFM can be seen as a combination of FNN and FM.

calculate_loss(interaction)

Calculate the training loss for a batch data.

Args:

interaction (Interaction): Interaction class of the batch.

Returns:

torch.Tensor: Training loss, shape: []

forward(interaction)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

predict(interaction)

Predict the scores between users and items.

Args:

interaction (Interaction): Interaction class of the batch.

Returns:

torch.Tensor: Predicted scores for given users and items, shape: [batch_size]

training: bool

FM

References

Steffen Rendle et al. “Factorization Machines.” in ICDM 2010.

Notes

context variables are treated as individual dimensions

class deepcarskit.model.fms.fm.FM(config, dataset)

Bases: deepcarskit.model.context_recommender.ContextRecommender

Factorization Machine considers the second-order interaction with features to predict the final score.

calculate_loss(interaction)

Calculate the training loss for a batch data.

Args:

interaction (Interaction): Interaction class of the batch.

Returns:

torch.Tensor: Training loss, shape: []

forward(interaction)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

predict(interaction)

Predict the scores between users and items.

Args:

interaction (Interaction): Interaction class of the batch.

Returns:

torch.Tensor: Predicted scores for given users and items, shape: [batch_size]

training: bool