MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / MLP

Class MLP

models/aios/utils.py:154–166  ·  view source on GitHub ↗

Very simple multi-layer perceptron (also called FFN)

Source from the content-addressed store, hash-verified

152
153
154class MLP(nn.Module):
155 """Very simple multi-layer perceptron (also called FFN)"""
156 def __init__(self, input_dim, hidden_dim, output_dim, num_layers):
157 super().__init__()
158 self.num_layers = num_layers
159 h = [hidden_dim] * (num_layers - 1)
160 self.layers = nn.ModuleList(
161 nn.Linear(n, k) for n, k in zip([input_dim] + h, h + [output_dim]))
162
163 def forward(self, x):
164 for i, layer in enumerate(self.layers):
165 x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
166 return x
167
168
169def _get_activation_fn(activation, d_model=256, batch_dim=0):

Callers 5

__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected