def train(model, train_loader, epochs, criterion, optimizer, device):
    '\n    This is the training method that is called by the PyTorch training script. The parameters\n    passed are as follows:\n    model        - The PyTorch model that we wish to train.\n    train_loader - The PyTorch DataLoader that should be used during training.\n    epochs       - The total number of epochs to train for.\n    criterion    - The loss function used for training. \n    optimizer    - The optimizer to use during training.\n    device       - Where the model and data should be loaded (gpu or cpu).\n    '
    for epoch in range(1, (epochs + 1)):
        model.train()
        total_loss = 0
        for batch in train_loader:
            (batch_x, batch_y) = batch
            batch_x = batch_x.to(device)
            batch_y = batch_y.to(device)
            optimizer.zero_grad()
            y_pred = model(batch_x)
            loss = criterion(y_pred, batch_y)
            loss.backward()
            optimizer.step()
            total_loss += loss.data.item()
        print('Epoch: {}, Loss: {}'.format(epoch, (total_loss / len(train_loader))))
This is the training method that is called by the PyTorch training script. The parameters
passed are as follows:
model        - The PyTorch model that we wish to train.
train_loader - The PyTorch DataLoader that should be used during training.
epochs       - The total number of epochs to train for.
criterion    - The loss function used for training. 
optimizer    - The optimizer to use during training.
device       - Where the model and data should be loaded (gpu or cpu).
def train(model, train_loader, epochs, criterion, optimizer, device):
    '\n    This is the training method that is called by the PyTorch training script. The parameters\n    passed are as follows:\n    model        - The PyTorch model that we wish to train.\n    train_loader - The PyTorch DataLoader that should be used during training.\n    epochs       - The total number of epochs to train for.\n    criterion    - The loss function used for training. \n    optimizer    - The optimizer to use during training.\n    device       - Where the model and data should be loaded (gpu or cpu).\n    '
    for epoch in range(1, (epochs + 1)):
        model.train()
        total_loss = 0
        for batch in train_loader:
            (batch_x, batch_y) = batch
            batch_x = batch_x.to(device)
            batch_y = batch_y.to(device)
            optimizer.zero_grad()
            y_pred = model(batch_x)
            loss = criterion(y_pred, batch_y)
            loss.backward()
            optimizer.step()
            total_loss += loss.data.item()
        print('Epoch: {}, Loss: {}'.format(epoch, (total_loss / len(train_loader))))