--- title: DCN keywords: fastai sidebar: home_sidebar summary: "A pytorch implementation of Deep & Cross Network." description: "A pytorch implementation of Deep & Cross Network." nb_path: "nbs/models/models.dcn.ipynb" ---
{% raw %}
{% endraw %}

## v1

{% raw %}

## `class` `CrossNetwork`[source]

> `CrossNetwork`(`input_dim`, `num_layers`) :: `Module`

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

    import torch.nn as nn
    import torch.nn.functional as F

    class Model(nn.Module):
        def __init__(self):
            super(Model, self).__init__()
            self.conv1 = nn.Conv2d(1, 20, 5)
            self.conv2 = nn.Conv2d(20, 20, 5)

        def forward(self, x):
            x = F.relu(self.conv1(x))
            return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:`to`, etc.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool

{% endraw %} {% raw %}

## `class` `DCN`[source]

> `DCN`(`field_dims`, `embed_dim`, `num_layers`, `mlp_dims`, `dropout`) :: `Module`

A pytorch implementation of Deep & Cross Network. Reference: R Wang, et al. Deep & Cross Network for Ad Click Predictions, 2017.

{% endraw %} {% raw %}
{% endraw %}

## v2

{% raw %}

## `class` `DNN`[source]

> `DNN`(`inputs_dim`, `hidden_units`, `dropout_rate`) :: `Module`

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

    import torch.nn as nn
    import torch.nn.functional as F

    class Model(nn.Module):
        def __init__(self):
            super(Model, self).__init__()
            self.conv1 = nn.Conv2d(1, 20, 5)
            self.conv2 = nn.Conv2d(20, 20, 5)

        def forward(self, x):
            x = F.relu(self.conv1(x))
            return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:`to`, etc.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool

{% endraw %} {% raw %}

## `class` `CrossNet`[source]

> `CrossNet`(`in_features`, `layer_num`=`2`, `parameterization`=`'vector'`, `seed`=`2022`) :: `Module`

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

    import torch.nn as nn
    import torch.nn.functional as F

    class Model(nn.Module):
        def __init__(self):
            super(Model, self).__init__()
            self.conv1 = nn.Conv2d(1, 20, 5)
            self.conv2 = nn.Conv2d(20, 20, 5)

        def forward(self, x):
            x = F.relu(self.conv1(x))
            return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:`to`, etc.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool

{% endraw %} {% raw %}

## `class` `DCNv2`[source]

> `DCNv2`(`feat_size`, `embedding_size`, `linear_feature_columns`, `dnn_feature_columns`, `cross_num`=`2`, `cross_param`=`'vector'`, `dnn_hidden_units`=`(128, 128)`, `init_std`=`0.0001`, `seed`=`2022`, `l2_reg`=`1e-05`, `drop_rate`=`0.5`) :: `Module`

DCN model implementation in pytorch

Reference:

    1. https://github.com/huangjunheng/recommendation_model/blob/master/DCN/dcn.py

{% endraw %} {% raw %}
{% endraw %}

> References:-- R Wang, et al. Deep & Cross Network for Ad Click Predictions, 2017.

> - https://github.com/rixwew/pytorch-fm/blob/master/torchfm/model/dcn.py
> - https://github.com/huangjunheng/recommendation_model/blob/master/DCN/dcn.py