I’m using a denoising autoencoder and wanted to use a weighted loss function to emphasise the loss for the corrupted components of the data. A batch size of 1 could work but the model would perform poorly.
The only solution I can think of is to do something like:
loss = []
for i, element in enumerate(batch):
    # calculate weights
    l = F.cross_entropy(y_pred[i], y_true[i], weight=weights[i])
    loss.append(l)