From: François Fleuret Date: Sun, 19 Mar 2023 08:05:09 +0000 (+0100) Subject: Update X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=71a5d04a1decec9d71be93cb816a15a8c0de83a2;p=beaver.git Update --- diff --git a/beaver.py b/beaver.py index e22fc7b..afec61d 100755 --- a/beaver.py +++ b/beaver.py @@ -191,12 +191,11 @@ def one_shot(gpt, task): output = model(output_gpt) targets = targets * (input.unsqueeze(-1) == maze.v_empty) output = output * (input.unsqueeze(-1) == maze.v_empty) - loss = (output.softmax(-1) - targets).abs().max(-1).values.mean() - # loss = ( - # -(output.log_softmax(-1) * targets).sum() - # / (input == maze.v_empty).sum() - # + targets.xlogy(targets).sum() / (input == maze.v_empty).sum() - # ) + # loss = (output.softmax(-1) - targets).abs().max(-1).values.mean() + loss = ( + -(output.log_softmax(-1) * targets).sum() + / (input == maze.v_empty).sum() + ) acc_train_loss += loss.item() * input.size(0) nb_train_samples += input.size(0) @@ -210,12 +209,11 @@ def one_shot(gpt, task): output = model(output_gpt) targets = targets * (input.unsqueeze(-1) == maze.v_empty) output = output * (input.unsqueeze(-1) == maze.v_empty) - loss = (output.softmax(-1) - targets).abs().max(-1).values.mean() - # loss = ( - # -(output.log_softmax(-1) * targets).sum() - # / (input == maze.v_empty).sum() - # + targets.xlogy(targets).sum() / (input == maze.v_empty).sum() - # ) + # loss = (output.softmax(-1) - targets).abs().max(-1).values.mean() + loss = ( + -(output.log_softmax(-1) * targets).sum() + / (input == maze.v_empty).sum() + ) acc_test_loss += loss.item() * input.size(0) nb_test_samples += input.size(0) @@ -231,8 +229,11 @@ def one_shot(gpt, task): # losses = (-output.log_softmax(-1) * targets + targets.xlogy(targets)).sum(-1) # losses = losses * (input == maze.v_empty) # losses = losses / losses.max() - losses = (output.softmax(-1) - targets).abs().max(-1).values - losses = (losses >= 0.05).float() + # losses = (output.softmax(-1) - targets).abs().max(-1).values + # losses = (losses >= 0.05).float() + losses = ( + (F.one_hot(output.argmax(-1), num_classes=4) * targets).sum(-1) == 0 + ).float() losses = losses.reshape(-1, args.maze_height, args.maze_width) input = input.reshape(-1, args.maze_height, args.maze_width) maze.save_image(