From cbafd7e4bf1566fad3e8f1a075f51c74dd0f7fcd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Fleuret?= Date: Sat, 18 Mar 2023 14:08:20 +0100 Subject: [PATCH] Update --- beaver.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/beaver.py b/beaver.py index c3b7e09..e22fc7b 100755 --- a/beaver.py +++ b/beaver.py @@ -172,6 +172,7 @@ def compute_perplexity(model, split="train"): def one_shot(gpt, task): t = gpt.training gpt.eval() + model = nn.Sequential( nn.Linear(args.dim_model, args.dim_model), nn.ReLU(), @@ -190,11 +191,12 @@ 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.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() + # + targets.xlogy(targets).sum() / (input == maze.v_empty).sum() + # ) acc_train_loss += loss.item() * input.size(0) nb_train_samples += input.size(0) @@ -208,11 +210,12 @@ 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.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() + # + targets.xlogy(targets).sum() / (input == maze.v_empty).sum() + # ) acc_test_loss += loss.item() * input.size(0) nb_test_samples += input.size(0) @@ -225,9 +228,11 @@ def one_shot(gpt, task): targets = task.test_policies[:32] output_gpt = gpt(mygpt.BracketedSequence(input), with_readout=False).x output = model(output_gpt) - losses = (-output.log_softmax(-1) * targets + targets.xlogy(targets)).sum(-1) - losses = losses * (input == maze.v_empty) - losses = losses / losses.max() + # 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 = losses.reshape(-1, args.maze_height, args.maze_width) input = input.reshape(-1, args.maze_height, args.maze_width) maze.save_image( -- 2.39.5