deepctr.layers.interaction module¶
 Authors:
 Weichen Shen,wcshen1994@163.com, Harshit Pande

class
deepctr.layers.interaction.
AFMLayer
(attention_factor=4, l2_reg_w=0, dropout_rate=0, seed=1024, **kwargs)[source]¶ Attentonal Factorization Machine models pairwise (order2) feature interactions without linear term and bias.
 Input shape
 A list of 3D tensor with shape:
(batch_size,1,embedding_size)
.
 A list of 3D tensor with shape:
 Output shape
 2D tensor with shape:
(batch_size, 1)
.
 2D tensor with shape:
 Arguments
 attention_factor : Positive integer, dimensionality of the
attention network output space. l2_reg_w : float between 0 and 1. L2 regularizer strength
applied to attention network. dropout_rate : float between in [0,1). Fraction of the attention net output units to dropout.
 seed : A Python integer to use as random seed.
 References
 [Attentional Factorization Machines : Learning the Weight of Feature
Interactions via Attention Networks](https://arxiv.org/pdf/1708.04617.pdf)

call
(inputs, training=None, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
BiInteractionPooling
(**kwargs)[source]¶ BiInteraction Layer used in Neural FM,compress the pairwise elementwise product of features into one single vector.
 Input shape
 A 3D tensor with shape:
(batch_size,field_size,embedding_size)
.
 A 3D tensor with shape:
 Output shape
 3D tensor with shape:
(batch_size,1,embedding_size)
.
 3D tensor with shape:
 References
 [He X, Chua T S. Neural factorization machines for sparse predictive analytics[C]//Proceedings of the 40th International ACM SIGIR conference on Research and Development in Information Retrieval. ACM, 2017: 355364.](http://arxiv.org/abs/1708.05027)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

class
deepctr.layers.interaction.
BilinearInteraction
(bilinear_type='interaction', seed=1024, **kwargs)[source]¶ BilinearInteraction Layer used in FiBiNET.
 Input shape
 A list of 3D tensor with shape:
(batch_size,1,embedding_size)
.
 A list of 3D tensor with shape:
 Output shape
 3D tensor with shape:
(batch_size,1,embedding_size)
.
 3D tensor with shape:
 Arguments
 str : String, types of bilinear functions used in this layer.
 seed : A Python integer to use as random seed.
 References
 [FiBiNET: Combining Feature Importance and Bilinear feature Interaction for ClickThrough Rate Prediction](https://arxiv.org/pdf/1905.09433.pdf)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
CIN
(layer_size=(128, 128), activation='relu', split_half=True, l2_reg=1e05, seed=1024, **kwargs)[source]¶ Compressed Interaction Network used in xDeepFM.This implemention is adapted from code that the author of the paper published on https://github.com/Leavingseason/xDeepFM.
 Input shape
 3D tensor with shape:
(batch_size,field_size,embedding_size)
.
 3D tensor with shape:
 Output shape
 2D tensor with shape:
(batch_size, featuremap_num)
featuremap_num = sum(self.layer_size[:1]) // 2 + self.layer_size[1]
ifsplit_half=True
,elsesum(layer_size)
.
 2D tensor with shape:
 Arguments
 layer_size : list of int.Feature maps in each layer.
 activation : activation function used on feature maps.
 split_half : bool.if set to False, half of the feature maps in each hidden will connect to output unit.
 seed : A Python integer to use as random seed.
 References
 [Lian J, Zhou X, Zhang F, et al. xDeepFM: Combining Explicit and Implicit Feature Interactions for Recommender Systems[J]. arXiv preprint arXiv:1803.05170, 2018.] (https://arxiv.org/pdf/1803.05170.pdf)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
CrossNet
(layer_num=2, l2_reg=0, seed=1024, **kwargs)[source]¶ The Cross Network part of Deep&Cross Network model, which leans both low and high degree cross feature.
 Input shape
 2D tensor with shape:
(batch_size, units)
.
 2D tensor with shape:
 Output shape
 2D tensor with shape:
(batch_size, units)
.
 2D tensor with shape:
 Arguments
 layer_num: Positive integer, the cross layer number
 l2_reg: float between 0 and 1. L2 regularizer strength applied to the kernel weights matrix
 seed: A Python integer to use as random seed.
 References
 [Wang R, Fu B, Fu G, et al. Deep & cross network for ad click predictions[C]//Proceedings of the ADKDD‘17. ACM, 2017: 12.](https://arxiv.org/abs/1708.05123)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
FGCNNLayer
(filters=(14, 16), kernel_width=(7, 7), new_maps=(3, 3), pooling_width=(2, 2), **kwargs)[source]¶ Feature Generation Layer used in FGCNN,including Convolution,MaxPooling and Recombination.
 Input shape
 A 3D tensor with shape:
(batch_size,field_size,embedding_size)
.
 A 3D tensor with shape:
 Output shape
 3D tensor with shape:
(batch_size,new_feture_num,embedding_size)
.
 3D tensor with shape:
 References
 [Liu B, Tang R, Chen Y, et al. Feature Generation by Convolutional Neural Network for ClickThrough Rate Prediction[J]. arXiv preprint arXiv:1904.04447, 2019.](https://arxiv.org/pdf/1904.04447)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
FM
(**kwargs)[source]¶ Factorization Machine models pairwise (order2) feature interactions without linear term and bias.
 Input shape
 3D tensor with shape:
(batch_size,field_size,embedding_size)
.
 3D tensor with shape:
 Output shape
 2D tensor with shape:
(batch_size, 1)
.
 2D tensor with shape:
 References
 [Factorization Machines](https://www.csie.ntu.edu.tw/~b97053/paper/Rendle2010FM.pdf)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

class
deepctr.layers.interaction.
FieldWiseBiInteraction
(use_bias=True, seed=1024, **kwargs)[source]¶ FieldWise BiInteraction Layer used in FLEN,compress the pairwise elementwise product of features into one single vector.
 Input shape
 A list of 3D tensor with shape:
(batch_size,field_size,embedding_size)
.
 A list of 3D tensor with shape:
 Output shape
 2D tensor with shape:
(batch_size,embedding_size)
.
 2D tensor with shape:
 Arguments
 use_bias : Boolean, if use bias.
 seed : A Python integer to use as random seed.
 References
 [FLEN: Leveraging Field for Scalable CTR Prediction](https://arxiv.org/pdf/1911.04690)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
FwFMLayer
(num_fields=4, regularizer=1e06, **kwargs)[source]¶ Fieldweighted Factorization Machines
 Input shape
 3D tensor with shape:
(batch_size,field_size,embedding_size)
.
 3D tensor with shape:
 Output shape
 2D tensor with shape:
(batch_size, 1)
.
 2D tensor with shape:
 Arguments
 num_fields : integer for number of fields
 regularizer : L2 regularizer weight for the field strength parameters of FwFM
 References
 [Fieldweighted Factorization Machines for ClickThrough Rate Prediction in Display Advertising]

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
InnerProductLayer
(reduce_sum=True, **kwargs)[source]¶ InnerProduct Layer used in PNN that compute the elementwise product or inner product between feature vectors.
 Input shape
 a list of 3D tensor with shape:
(batch_size,1,embedding_size)
.
 a list of 3D tensor with shape:
 Output shape
 3D tensor with shape:
(batch_size, N*(N1)/2 ,1)
if use reduce_sum. or 3D tensor with shape:(batch_size, N*(N1)/2, embedding_size )
if not use reduce_sum.
 3D tensor with shape:
 Arguments
 reduce_sum: bool. Whether return inner product or elementwise product
 References
 [Qu Y, Cai H, Ren K, et al. Productbased neural networks for user response prediction[C]//Data Mining (ICDM), 2016 IEEE 16th International Conference on. IEEE, 2016: 11491154.](https://arxiv.org/pdf/1611.00144.pdf)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
InteractingLayer
(att_embedding_size=8, head_num=2, use_res=True, seed=1024, **kwargs)[source]¶ A Layer used in AutoInt that model the correlations between different feature fields by multihead selfattention mechanism.
 Input shape
 A 3D tensor with shape:
(batch_size,field_size,embedding_size)
.
 A 3D tensor with shape:
 Output shape
 3D tensor with shape:
(batch_size,field_size,att_embedding_size * head_num)
.
 3D tensor with shape:
 Arguments
 att_embedding_size: int.The embedding size in multihead selfattention network.
 head_num: int.The head number in multihead selfattention network.
 use_res: bool.Whether or not use standard residual connections before output.
 seed: A Python integer to use as random seed.
 References
 [Song W, Shi C, Xiao Z, et al. AutoInt: Automatic Feature Interaction Learning via SelfAttentive Neural Networks[J]. arXiv preprint arXiv:1810.11921, 2018.](https://arxiv.org/abs/1810.11921)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
OutterProductLayer
(kernel_type='mat', seed=1024, **kwargs)[source]¶ OutterProduct Layer used in PNN.This implemention is adapted from code that the author of the paper published on https://github.com/Atomu2014/productnets.
 Input shape
 A list of N 3D tensor with shape:
(batch_size,1,embedding_size)
.
 A list of N 3D tensor with shape:
 Output shape
 2D tensor with shape:
(batch_size,N*(N1)/2 )
.
 2D tensor with shape:
 Arguments
 kernel_type: str. The kernel weight matrix type to use,can be mat,vec or num
 seed: A Python integer to use as random seed.
 References
 [Qu Y, Cai H, Ren K, et al. Productbased neural networks for user response prediction[C]//Data Mining (ICDM), 2016 IEEE 16th International Conference on. IEEE, 2016: 11491154.](https://arxiv.org/pdf/1611.00144.pdf)

call
(inputs, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.

class
deepctr.layers.interaction.
SENETLayer
(reduction_ratio=3, seed=1024, **kwargs)[source]¶ SENETLayer used in FiBiNET.
 Input shape
 A list of 3D tensor with shape:
(batch_size,1,embedding_size)
.
 A list of 3D tensor with shape:
 Output shape
 A list of 3D tensor with shape:
(batch_size,1,embedding_size)
.
 A list of 3D tensor with shape:
 Arguments
 reduction_ratio : Positive integer, dimensionality of the
attention network output space. seed : A Python integer to use as random seed.
 References
 [FiBiNET: Combining Feature Importance and Bilinear feature Interaction for ClickThrough Rate Prediction](https://arxiv.org/pdf/1905.09433.pdf)

call
(inputs, training=None, **kwargs)[source]¶ This is where the layer’s logic lives.
 Arguments:
 inputs: Input tensor, or list/tuple of input tensors. **kwargs: Additional keyword arguments.
 Returns:
 A tensor or list/tuple of tensors.

compute_mask
(inputs, mask=None)[source]¶ Computes an output mask tensor.
 Arguments:
 inputs: Tensor or list of tensors. mask: Tensor or list of tensors.
 Returns:
 None or a tensor (or list of tensors,
 one per output tensor of the layer).

compute_output_shape
(input_shape)[source]¶ Computes the output shape of the layer.
Assumes that the layer will be built to match that input shape provided.
 Arguments:
 input_shape: Shape tuple (tuple of integers)
 or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.
 Returns:
 An input shape tuple.

get_config
()[source]¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
 Returns:
 Python dictionary.