I have a code for running Gradient Descent on mnist dataset, but after creating my network and loading the data, when i’m going to do training , i get this error
grads['dl/df2'][label] -= 1
IndexError: index 5 is out of bounds for dimension 0 with size 1

here is my code:
dataset = MNIST(root='root', download=True )
images, labels =  dataset.data ,dataset.targets
images, labels = images[:n_examples], labels[:n_examples]
images, labels = iter(images.view(-1, 784) / 255), iter(labels)

grads={}
start = t()

for i, (image, label) in enumerate(zip(images, labels)):

    label = torch.Tensor([label]).long()

    # Run simulation for single datum.

    inpts = {
        'X': image.repeat(time, 1), 'Y_b': torch.ones(time, 1)
    }
    network.run(inpts=inpts, time=time)

    # Compute softmax of output spiking activity and get predicted label.
    output = summed_inputs['Y'].softmax(0).view(1, -1)
    predicted = output.argmax(1).item()
    correct[i % update_interval] = int(predicted == label[0].item())
    predictions.append(predicted)
    ground_truth.append(label)

    # Compute cross-entropy loss between output and true label.
    losses[i % update_interval] = criterion(output, label)

    if train:
        # Compute gradient of the loss WRT average firing rates.
        grads['dl/df'] = summed_inputs['Y'].softmax(0)
        grads['dl/df'][label] -= 1

        # Compute gradient of the summed voltages of connection weights.
        grads['dl/dw'] = torch.ger(summed_inputs['X'], grads['dl/df'])
        grads['dl/db'] = grads['dl/df']

        # Do stochastic gradient descent calculation.
        network.connections['X', 'Y'].w -= lr * grads['dl/dw']
        network.connections['Y_b', 'Y'].w -= lr * grads['dl/db']

what’s wrong with my code?