forked from Enzo-Damico/projet_MODIA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
27 lines (20 loc) · 832 Bytes
/
Copy pathmodel.py
File metadata and controls
27 lines (20 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from tqdm.notebook import tqdm
import torch
import torch.nn as nn
class NCF(nn.Module):
def __init__(self, n_users, n_items, n_factors=8):
super().__init__()
self.user_embeddings = torch.nn.Embedding(n_users, n_factors)
self.item_embeddings = torch.nn.Embedding(n_items, n_factors)
self.predictor = torch.nn.Sequential(
nn.Linear(in_features=n_factors*2, out_features=64),
nn.Linear(in_features=64, out_features=32),
nn.Linear(in_features=32, out_features=1),
nn.Sigmoid()
)
def forward(self, user, item):
u = self.user_embeddings(user)
i = self.item_embeddings(item)
# Concat the two embedding layers
z = torch.cat([u, i], dim=-1)
return self.predictor(z)