-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
93 lines (82 loc) · 2.75 KB
/
models.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import torch
from torch.utils.data import Dataset
import torch.nn as nn
import torch.nn.functional as F
# from torchvision import datasets
# from torchvision.transforms import ToTensor
class ContrastiveNet(nn.Module):
def __init__(self, input_dim, output_dim):
super(ContrastiveNet, self).__init__()
self.layers = nn.Sequential(
nn.Linear(input_dim, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, output_dim),
)
def forward(self, x):
x = self.layers(x)
return x / torch.linalg.norm(x, dim=1, keepdim=True)
class FeedforwardNet_GPTJ(nn.Module):
def __init__(self, input_dim, output_dim):
super(FeedforwardNet_GPTJ, self).__init__()
""" self.layers = nn.Sequential(
nn.Linear(input_dim, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, 256),
nn.BatchNorm1d(256),
nn.ReLU(inplace=True),
nn.Linear(256, output_dim),
) """
self.layers = nn.Sequential(
nn.Linear(input_dim, 2048),
nn.BatchNorm1d(2048),
nn.ReLU(inplace=True),
nn.Linear(2048, 2048),
nn.BatchNorm1d(2048),
nn.ReLU(inplace=True),
nn.Linear(2048, 1024),
nn.BatchNorm1d(1024),
nn.ReLU(inplace=True),
nn.Linear(1024, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, 256),
nn.BatchNorm1d(256),
nn.ReLU(inplace=True),
nn.Linear(256, output_dim),
)
def forward(self, x):
return self.layers(x)
class FeedforwardNet(nn.Module):
def __init__(self, input_dim, output_dim):
super(FeedforwardNet, self).__init__()
""" self.layers = nn.Sequential(
nn.Linear(input_dim, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, 256),
nn.BatchNorm1d(256),
nn.ReLU(inplace=True),
nn.Linear(256, output_dim),
) """
self.layers = nn.Sequential(
nn.Linear(input_dim, 512),
nn.BatchNorm1d(512),
nn.ReLU(inplace=True),
nn.Linear(512, 256),
nn.BatchNorm1d(256),
nn.ReLU(inplace=True),
nn.Linear(256, output_dim),
)
def forward(self, x):
return self.layers(x)