Update.
authorFrançois Fleuret <francois@fleuret.org>
Wed, 19 Jul 2023 13:43:01 +0000 (15:43 +0200)
committerFrançois Fleuret <francois@fleuret.org>
Wed, 19 Jul 2023 13:43:01 +0000 (15:43 +0200)
main.py
rpl.py
tasks.py

diff --git a/main.py b/main.py
index 63e6668..d1f82cf 100755 (executable)
--- 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 (executable)
--- 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 + ["<input>"] + stack + ["<output>"] + result_stack
 
index 75cd35e..e14ceb7 100755 (executable)
--- 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