# xDeepFM¶

Reference:

Jianxun Lian at al. “xDeepFM: Combining Explicit and Implicit Feature Interactions for Recommender Systems.” in SIGKDD 2018.

Reference code:
class recbole.model.context_aware_recommender.xdeepfm.xDeepFM(config, dataset)[source]

xDeepFM combines a CIN (Compressed Interaction Network) with a classical DNN. The model is able to learn certain bounded-degree feature interactions explicitly; Besides, it can also learn arbitrary low- and high-order feature interactions implicitly.

calculate_loss(interaction)[source]

Calculate the training loss for a batch data.

Parameters

interaction (Interaction) – Interaction class of the batch.

Returns

Training loss, shape: []

Return type

torch.Tensor

calculate_reg_loss()[source]

Calculate the final L2 normalization loss of model parameters. Including weight matrices of mlp layers, linear layer and convolutional layers.

Returns

The L2 Loss tensor. shape of [1,]

Return type

loss(torch.FloatTensor)

compressed_interaction_network(input_features, activation='identity')[source]

For k-th CIN layer, the output $$X_k$$ is calculated via

$x_{h,*}^{k} = \sum_{i=1}^{H_k-1} \sum_{j=1}^{m}W_{i,j}^{k,h}(X_{i,*}^{k-1} \circ x_{j,*}^0)$

$$H_k$$ donates the number of feature vectors in the k-th layer, $$1 \le h \le H_k$$. $$\circ$$ donates the Hadamard product.

And Then, We apply sum pooling on each feature map of the hidden layer. Finally, All pooling vectors from hidden layers are concatenated.

Parameters
• input_features (torch.Tensor) – [batch_size, field_num, embed_dim]. Embedding vectors of all features.

• activation (str) – name of activation function.

Returns

[batch_size, num_feature_field * embedding_size]. output of CIN layer.

Return type

torch.Tensor

forward(interaction)[source]

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)[source]

Predict the scores between users and items.

Parameters

interaction (Interaction) – Interaction class of the batch.

Returns

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

Return type

torch.Tensor

reg_loss(parameters)[source]

Calculate the L2 normalization loss of parameters in a certain layer.

Returns

The L2 Loss tensor. shape of [1,]

Return type

loss(torch.FloatTensor)

training: bool