human
2. 사전 설정
* model
* loss
* opimizer
assistant
#Here is the Python code you requested.
##################
# option variables 
##################
learning_rate = 1e-2
training_epoch = 2
batch_size = 100
# neural network properties 
n_hidden = 128  # number of latent 
n_layers = 2  # number of latent 
n_sequence = 28   # Image pixel number in row

class MnistModel(nn.Module):
    def __init__(self):
        super(MnistModel, self).__init__()
        # input is 28x28
        self.rnn = nn.LSTM(n_sequence, n_hidden, n_layers, batch_first=True)
        self.fc = nn.Linear(n_hidden, 10)
        
    def forward(self, x):
        # Set initial states 
        h0 = Variable(torch.zeros(n_layers, x.size(0), n_hidden))
        c0 = Variable(torch.zeros(n_layers, x.size(0), n_hidden))
        if is_cuda :  h0, c0 = h0.cuda(), c0.cuda()
        x, _ = self.rnn(x, (h0, c0))
        x = self.fc(x[:, -1 ,:])
        return F.log_softmax(x)
    
model = MnistModel()
if is_cuda :  model.cuda()
loss_fn = nn.NLLLoss() 
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)