From 5703df4c32a0856c8fa4b1ff97810cdc1fb76253 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Fleuret?= Date: Wed, 19 Jul 2023 15:43:01 +0200 Subject: [PATCH] Update. --- main.py | 2 +- rpl.py | 6 +++--- tasks.py | 24 ++++++++++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 63e6668..d1f82cf 100755 --- a/main.py +++ b/main.py @@ -209,7 +209,7 @@ default_task_args = { "rpl": { "nb_epochs": 40, "batch_size": 25, - "nb_train_samples": 1000000, + "nb_train_samples": 100000, "nb_test_samples": 10000, }, "world": { diff --git a/rpl.py b/rpl.py index 155bc69..7f7dcfc 100755 --- a/rpl.py +++ b/rpl.py @@ -53,13 +53,13 @@ rpl_ops = ["add", "min", "max", "swp", "rep", "dup", "del"] ###################################################################### -def generate(nb_values=3, max_input=9, prog_len=6, nb_runs=5): - prog_len = 1 + torch.randint(prog_len - 1, (1,)).item() +def generate(nb_starting_values=3, max_input=9, prog_len=6, nb_runs=5): + prog_len = (1 + torch.randint(2 * prog_len, (1,))).clamp(max=prog_len).item() prog = [rpl_ops[k] for k in torch.randint(len(rpl_ops), (prog_len,))] result = [] for _ in range(nb_runs): - stack = [x.item() for x in torch.randint(max_input + 1, (nb_values,))] + stack = [x.item() for x in torch.randint(max_input + 1, (nb_starting_values,))] result_stack = rpl_exec(prog, stack) result = result + [""] + stack + [""] + result_stack diff --git a/tasks.py b/tasks.py index 75cd35e..e14ceb7 100755 --- a/tasks.py +++ b/tasks.py @@ -1052,6 +1052,10 @@ class RPL(Task): nb_train_samples, nb_test_samples, batch_size, + nb_starting_values=3, + max_input=9, + prog_len=6, + nb_runs=5, device=torch.device("cpu"), ): super().__init__() @@ -1060,11 +1064,23 @@ class RPL(Task): self.device = device train_sequences = [ - rpl.generate() + rpl.generate( + nb_starting_values=nb_starting_values, + max_input=max_input, + prog_len=prog_len, + nb_runs=nb_runs, + ) for _ in tqdm.tqdm(range(nb_train_samples), desc="train-data") ] + test_sequences = [ - rpl.generate() for _ in tqdm.tqdm(range(nb_test_samples), desc="test-data") + rpl.generate( + nb_starting_values=nb_starting_values, + max_input=max_input, + prog_len=prog_len, + nb_runs=nb_runs, + ) + for _ in tqdm.tqdm(range(nb_test_samples), desc="test-data") ] symbols = list( @@ -1131,14 +1147,14 @@ class RPL(Task): _, _, gt_prog, _ = rpl.compute_nb_errors(gt_seq) gt_prog = " ".join([str(x) for x in gt_prog]) prog = " ".join([str(x) for x in prog]) - logger(f"GROUND-TRUTH PROG [{gt_prog}] PREDICTED PROG [{prog}]") + logger(f"PROG [{gt_prog}] PREDICTED [{prog}]") for start_stack, target_stack, result_stack, correct in stacks: comment = " CORRECT" if correct else "" start_stack = " ".join([str(x) for x in start_stack]) target_stack = " ".join([str(x) for x in target_stack]) result_stack = " ".join([str(x) for x in result_stack]) logger( - f" [{start_stack}] -> [{result_stack}] TARGET [{target_stack}]{comment}" + f" [{start_stack}] -> [{target_stack}] PREDICTED [{result_stack}]{comment}" ) nb_to_log -= 1 -- 2.39.5