--- title: SiReN keywords: fastai sidebar: home_sidebar summary: "Sign-Aware Recommendation Systems with Graph Neural Networks (SiReN)." description: "Sign-Aware Recommendation Systems with Graph Neural Networks (SiReN)." nb_path: "nbs/models/models.siren.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

## `class` `SiReN`[source]

> `SiReN`(`train`, `num_u`, `num_v`, `offset`, `num_layers`=`2`, `MLP_layers`=`2`, `dim`=`64`, `reg`=`0.0001`, `device`=`device(type='cpu')`, `graph_enc`=`'lightgcn'`, `user_col`=`'userId'`, `item_col`=`'itemId'`, `rating_col`=`'rating'`) :: `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 %}

    import pandas as pd

    train = pd.DataFrame(
        {'userId':[1,1,2,2,3,4,5],
         'itemId':[1,2,1,3,2,4,5],
         'rating':[4,5,2,5,3,2,4]}
    )

    train

| userId | itemId | rating
--- | --- | --- | ---
0 | 1 | 1 | 4
1 | 1 | 2 | 5
2 | 2 | 1 | 2
3 | 2 | 3 | 5
4 | 3 | 2 | 3
5 | 4 | 4 | 2
6 | 5 | 5 | 4

{% endraw %} {% raw %}

    model = SiReN(train,
                    num_u = 5,
                    num_v = 5,
                    offset = 3.5,
                    num_layers = 1,
                    MLP_layers = 1,
                    dim = 2,
                    reg = 1e-4,
                    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu"),
                    graph_enc = 'lightgcn',
                    user_col = 'userId',
                    item_col = 'itemId',
                    rating_col = 'rating')

{% endraw %} {% raw %}

    torch.random.manual_seed(0)
    model.aggregate()

    tensor([[ 0.3599, -0.6117],
            [ 0.0643,  0.1232],
            [-0.0828,  0.1913],
            [-0.3257, -0.1678],
            [ 0.2391, -0.0063],
            [-0.0721, -0.3664],
            [-0.0213, -0.1475],
            [ 0.1260, -0.0493],
            [-0.0176, -0.1874],
            [ 0.0924,  0.2289]], grad_fn=<AddBackward0>)

{% endraw %}