-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_encoders.py
38 lines (27 loc) · 1.05 KB
/
feature_encoders.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
import torch
from ogb.graphproppred.mol_encoder import AtomEncoder
class Identity(torch.nn.Identity):
def __init__(self, in_dim, emb_dim, k):
super().__init__()
self.k = k
class ZincAtomEncoder(torch.nn.Module):
def __init__(self, in_dim, emb_dim, k):
super().__init__()
self.k = k
self.enc = torch.nn.Embedding(in_dim, emb_dim - k)
def forward(self, x):
return torch.hstack((x[:, : self.k], self.enc(x[:, self.k :].long().squeeze())))
class MyAtomEncoder(torch.nn.Module):
def __init__(self, in_dim, emb_dim, k):
super().__init__()
self.k = k
self.enc = AtomEncoder(emb_dim - k)
def forward(self, x):
return torch.hstack((x[:, : self.k], self.enc(x[:, self.k :].long().squeeze())))
class LinearEncoder(torch.nn.Module):
def __init__(self, in_dim, emb_dim, k):
super().__init__()
self.k = k
self.enc = torch.nn.Linear(in_dim, emb_dim - k)
def forward(self, x):
return torch.hstack((x[:, : self.k], self.enc(x[:, self.k :])))