File size: 1,556 Bytes
8a4416a 4b23e69 8a4416a 4b23e69 8a4416a 4b23e69 8a4416a |
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 |
import torch
import torch.nn as nn
from transformers import PreTrainedModel, PretrainedConfig
class FingerNetConfig(PretrainedConfig):
model_type = "fingernet"
def __init__(
self,
x_dim=[6],
y_dim=[6, 1800],
h1_dim=[100, 1000],
h2_dim=[100, 1000],
**kwargs,
):
super().__init__(**kwargs)
self.x_dim = x_dim
self.y_dim = y_dim
self.h1_dim = h1_dim
self.h2_dim = h2_dim
class FingerNetSurf(PreTrainedModel):
config_class = FingerNetConfig
def __init__(self, config):
super().__init__(config)
self.x_dim = config.x_dim
self.y_dim = config.y_dim
self.h1_dim = config.h1_dim
self.h2_dim = config.h2_dim
self.model = nn.ModuleDict()
# Define the model architecture
for i in range(len(self.y_dim)):
self.model[f"estimator_{i}"] = nn.Sequential(
nn.Linear(self.x_dim[0], self.h1_dim[i]),
nn.ReLU(),
nn.Linear(self.h1_dim[i], self.h2_dim[i]),
nn.ReLU(),
nn.Linear(self.h2_dim[i], self.y_dim[i]),
)
# initialize weights
self.post_init()
def forward(self, x):
outputs = []
for i in range(len(self.y_dim)):
# Get the estimator for the i-th output
estimator = self.model[f"estimator_{i}"]
y = estimator(x)
outputs.append(y)
return outputs
|