<jupyter_start><jupyter_text>ModelA MLP model with BatchNorm<jupyter_code>from model import MLP
model = MLP()
model.cuda() # CUDA!
optimizer = optim.Adam(model.parameters(), lr=0.001)<jupyter_output><empty_output><jupyter_text>Train<jupyter_code>model.train()

losses = []
for epoch in range(15):
    for batch_idx, (data, target) in enumerate(train_loader):
        # Get Samples
        data, target = Variable(data.cuda()), Variable(target.cuda())
        
        # Init
        optimizer.zero_grad()

        # Predict
        y_pred = model(data) 

        # Calculate loss
        loss = F.cross_entropy(y_pred, target)
        losses.append(loss.data[0])
        # Backpropagation
        loss.backward()
        optimizer.step()
        
        
        # Display
        if batch_idx % 100 == 1:
            print('\r Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format(
                epoch, 
                batch_idx * len(data), 
                len(train_loader.dataset),
                100. * batch_idx / len(train_loader), 
                loss.data[0]), 
                end='')
            
    print()
plot(losses)<jupyter_output><empty_output><jupyter_text>Evaluate<jupyter_code>evaluate_x = Variable(test_loader.dataset.test_data.type_as(torch.FloatTensor())).cuda()
evaluate_y = Variable(test_loader.dataset.test_labels).cuda()


output = model(evaluate_x)
pred = output.data.max(1)[1]
d = pred.eq(evaluate_y.data).cpu()
accuracy = d.sum()/d.size()[0]

print('Accuracy:', accuracy)<jupyter_output>Accuracy: 0.9764
{'fraction_non_alphanumeric': 0.14193130265716136, 'fraction_numerical': 0.016202203499675955, 'mean_word_length': 2.6159250585480094, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '662773', 'license': 'MIT', 'n_tokens_mistral': 562, 'n_tokens_neox': 515, 'n_words': 81, 'path': 'models/torch_fn/mlp_mnist_test.ipynb', 'repo_name': 'AI-Huang/models', 'size': '1543'}