Upload 4 files
Browse files- modeling_jetoncount.py +26 -5
modeling_jetoncount.py
CHANGED
|
@@ -79,20 +79,41 @@ def _engineer_features_tensor(base: torch.Tensor) -> torch.Tensor:
|
|
| 79 |
|
| 80 |
|
| 81 |
class JetonCountMLP(nn.Module):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
def __init__(self, input_dim: int, hidden_dim: int, num_layers: int, dropout: float, activation: str):
|
| 83 |
super().__init__()
|
| 84 |
if num_layers < 1:
|
| 85 |
raise ValueError("num_layers must be >= 1")
|
| 86 |
|
| 87 |
layers = []
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
layers.append(nn.Linear(
|
|
|
|
|
|
|
| 91 |
layers.append(_get_activation(activation))
|
| 92 |
if dropout > 0:
|
| 93 |
layers.append(nn.Dropout(dropout))
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
self.net = nn.Sequential(*layers)
|
| 97 |
|
| 98 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
class JetonCountMLP(nn.Module):
|
| 82 |
+
"""
|
| 83 |
+
IMPORTANT: num_layers means total Linear layers, exactly like the training script.
|
| 84 |
+
|
| 85 |
+
For num_layers == 1:
|
| 86 |
+
Linear(in_features -> 1)
|
| 87 |
+
|
| 88 |
+
For num_layers > 1:
|
| 89 |
+
Linear(in_features -> hidden_dim)
|
| 90 |
+
[num_layers - 2] x Linear(hidden_dim -> hidden_dim)
|
| 91 |
+
Linear(hidden_dim -> 1)
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
def __init__(self, input_dim: int, hidden_dim: int, num_layers: int, dropout: float, activation: str):
|
| 95 |
super().__init__()
|
| 96 |
if num_layers < 1:
|
| 97 |
raise ValueError("num_layers must be >= 1")
|
| 98 |
|
| 99 |
layers = []
|
| 100 |
+
|
| 101 |
+
if num_layers == 1:
|
| 102 |
+
layers.append(nn.Linear(input_dim, 1))
|
| 103 |
+
else:
|
| 104 |
+
layers.append(nn.Linear(input_dim, hidden_dim))
|
| 105 |
layers.append(_get_activation(activation))
|
| 106 |
if dropout > 0:
|
| 107 |
layers.append(nn.Dropout(dropout))
|
| 108 |
+
|
| 109 |
+
for _ in range(num_layers - 2):
|
| 110 |
+
layers.append(nn.Linear(hidden_dim, hidden_dim))
|
| 111 |
+
layers.append(_get_activation(activation))
|
| 112 |
+
if dropout > 0:
|
| 113 |
+
layers.append(nn.Dropout(dropout))
|
| 114 |
+
|
| 115 |
+
layers.append(nn.Linear(hidden_dim, 1))
|
| 116 |
+
|
| 117 |
self.net = nn.Sequential(*layers)
|
| 118 |
|
| 119 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
|