Spaces:
Sleeping
Sleeping
Upload models_arch.py with huggingface_hub
Browse files- models_arch.py +34 -0
models_arch.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
GNN architectures for AntioxFP: AttentiveFP (primary model).
|
| 3 |
+
Copied from the research codebase and trimmed to inference-only.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import torch
|
| 7 |
+
import torch.nn as nn
|
| 8 |
+
import torch.nn.functional as F
|
| 9 |
+
from torch_geometric.nn import AttentiveFP
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
NODE_DIM = 40 # atom feature dimension
|
| 13 |
+
EDGE_DIM = 6 # bond feature dimension
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class AttentiveFPModel(nn.Module):
|
| 17 |
+
def __init__(self, hidden=200, num_layers=2, num_timesteps=2, dropout=0.2):
|
| 18 |
+
super().__init__()
|
| 19 |
+
self.gnn = AttentiveFP(
|
| 20 |
+
in_channels=NODE_DIM,
|
| 21 |
+
hidden_channels=hidden,
|
| 22 |
+
out_channels=1,
|
| 23 |
+
edge_dim=EDGE_DIM,
|
| 24 |
+
num_layers=num_layers,
|
| 25 |
+
num_timesteps=num_timesteps,
|
| 26 |
+
dropout=dropout,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
def forward(self, x, edge_index=None, edge_attr=None, batch=None, **kwargs):
|
| 30 |
+
if hasattr(x, 'edge_index'):
|
| 31 |
+
data = x
|
| 32 |
+
x, edge_index, edge_attr, batch = (
|
| 33 |
+
data.x, data.edge_index, data.edge_attr, data.batch)
|
| 34 |
+
return self.gnn(x, edge_index, edge_attr, batch).squeeze(-1)
|