--- title: DSSM keywords: fastai sidebar: home_sidebar summary: "An implementation of DSSM, Deep Structured Semantic Model." description: "An implementation of DSSM, Deep Structured Semantic Model." nb_path: "nbs/models/models.dssm.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

## `class` `DSSM`[source]

> `DSSM`(`main_embed_size`, `feat_embed_size`, `n_users`, `n_items`, `hidden_size`, `feat_map`, `static_feat`, `dynamic_feat`, `use_bn`=`True`) :: `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 %}
{% endraw %} {% raw %}

    model = DSSM(main_embed_size=2, feat_embed_size=2, n_users=5, n_items=5, hidden_size=[5,3], feat_map={'a_vocab':2,'b_vocab':2}, static_feat=['a'], dynamic_feat=['b'], use_bn=True)
    model

    DSSM(
      (embed_user): Embedding(6, 2, padding_idx=5)
      (embed_item): Embedding(6, 2, padding_idx=5)
      (embed_feat): ModuleDict(
        (a): Embedding(3, 2, padding_idx=2)
        (b): Embedding(3, 2, padding_idx=2)
      )
      (fcu1): Linear(in_features=4, out_features=5, bias=True)
      (fcu2): Linear(in_features=5, out_features=3, bias=True)
      (fcu3): Linear(in_features=3, out_features=2, bias=True)
      (fci1): Linear(in_features=4, out_features=5, bias=True)
      (fci2): Linear(in_features=5, out_features=3, bias=True)
      (fci3): Linear(in_features=3, out_features=2, bias=True)
      (bnu1): BatchNorm1d(5, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (bnu2): BatchNorm1d(3, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (bni1): BatchNorm1d(5, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (bni2): BatchNorm1d(3, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )

{% endraw %}