|
import torch |
|
import torch.nn as nn |
|
import numpy as np |
|
|
|
|
|
|
|
class MLP(torch.nn.Module): |
|
def __init__(self, input_size, xcol="emb", ycol="avg_rating"): |
|
super().__init__() |
|
self.input_size = input_size |
|
self.xcol = xcol |
|
self.ycol = ycol |
|
self.layers = nn.Sequential( |
|
nn.Linear(self.input_size, 1024), |
|
|
|
nn.Dropout(0.2), |
|
nn.Linear(1024, 128), |
|
|
|
nn.Dropout(0.2), |
|
nn.Linear(128, 64), |
|
|
|
nn.Dropout(0.1), |
|
nn.Linear(64, 16), |
|
|
|
nn.Linear(16, 1), |
|
) |
|
|
|
def forward(self, x): |
|
return self.layers(x) |
|
|
|
|
|
def normalized(a, axis=-1, order=2): |
|
l2 = np.atleast_1d(np.linalg.norm(a, order, axis)) |
|
l2[l2 == 0] = 1 |
|
return a / np.expand_dims(l2, axis) |
|
|