Skip to content
Snippets Groups Projects
Commit 82fa5a33 authored by umlauf's avatar umlauf
Browse files

CEL

parent 5e4b9ea9
No related branches found
No related tags found
No related merge requests found
......@@ -141,10 +141,10 @@ def train(model, name, seed,gradient_accumulation_steps,mixup, threshold, lambda
# return -(target * logprobs).sum() / input.shape[0]
#gives average #2
def cross_entropy(preds, target):
log_preds = torch.log(preds)
loss = -torch.sum(target * log_preds) / preds.shape[0]
return loss
# def cross_entropy(preds, target):
# log_preds = torch.log(preds)
# loss = -torch.sum(target * log_preds) / preds.shape[0]
# return loss
#1
# def cross_entropy(preds, target):
......@@ -160,6 +160,14 @@ def cross_entropy(preds, target):
# return loss
def cross_entropy(preds, target):
device = preds.device
target = torch.eye(preds.shape[1], device=device)[target.long()]
log_preds = torch.log(preds)
loss = -torch.mean(target * log_preds)
return loss
def mixup_function(batch_of_matrices, batch_of_labels, l, t):
runs = math.floor(batch_of_matrices.size()[0]/2)
counter=0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment