-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwo_model.py
More file actions
29 lines (24 loc) · 993 Bytes
/
two_model.py
File metadata and controls
29 lines (24 loc) · 993 Bytes
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
import torch
import ast
import numpy as np
import pandas as pd
from torch import nn
#Class for each MLP
class impact_model(nn.Module):
def __init__(self, input_size, hidden_size, output_size=7):
super().__init__()
self.layers = nn.Sequential(nn.Linear(input_size, hidden_size),
nn.ReLU(),
nn.Dropout(0.7),
nn.Linear(hidden_size, hidden_size),
nn.ReLU(),
nn.Dropout(0.7),
nn.Linear(hidden_size, output_size))
def forward(self, x):
return self.layers(x)
#setup model function
def setup_model(input_size, hidden_size, output_size):
model = impact_model(input_size, hidden_size, output_size)
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(params=model.parameters(), lr=0.001, weight_decay=1e-4)
return (model, criterion, optimizer)