parser.add_argument("--rpl-nb_runs", type=int, default=8)
+parser.add_argument("--rpl-no-prog", action="store_true", default=False)
+
##############################
# sandbox options
max_input=args.rpl_max_input,
prog_len=args.rpl_prog_len,
nb_runs=args.rpl_nb_runs,
+ no_prog=args.rpl_no_prog,
logger=log_string,
device=device,
)
max_input=9,
prog_len=6,
nb_runs=5,
+ no_prog=False,
logger=None,
device=torch.device("cpu"),
):
self.batch_size = batch_size
self.device = device
+ self.no_prog = no_prog
train_sequences = [
rpl.generate(
self.id2token = dict([(n, c) for c, n in self.token2id.items()])
self.t_nul = self.token2id["<nul>"]
- self.t_prog = self.token2id["<prog>"]
self.t_input = self.token2id["<input>"]
self.t_output = self.token2id["<output>"]
+ self.t_prog = self.token2id["<prog>"]
+ self.t_end = self.token2id["<end>"]
self.train_input = self.tensorize(train_sequences)
self.test_input = self.tensorize(test_sequences)
+ if no_prog:
+ k = torch.arange(self.train_input.size(1), device=self.train_input.device)[
+ None, :
+ ]
+ p = (
+ ((self.train_input == self.t_prog).long() * k)
+ .max(1, keepdim=True)
+ .values
+ )
+ self.train_input = (
+ self.train_input * (k <= p).long()
+ + self.t_end * (k == p + 1).long()
+ + self.t_nul * (k > p + 1).long()
+ )
+ k = torch.arange(self.test_input.size(1), device=self.test_input.device)[
+ None, :
+ ]
+ p = (
+ ((self.test_input == self.t_prog).long() * k)
+ .max(1, keepdim=True)
+ .values
+ )
+ self.test_input = (
+ self.test_input * (k <= p).long()
+ + self.t_end * (k == p + 1).long()
+ + self.t_nul * (k > p + 1).long()
+ )
+
if logger is not None:
logger(f"value_max {val_max}")
for x in self.train_input[:25]:
# --------------------------------------------------------------------
- test_nb_total, test_nb_errors = compute_nb_errors_prog(
- self.test_input[:1000].to(self.device), nb_to_log=10
- )
+ if not self.no_prog:
+ test_nb_total, test_nb_errors = compute_nb_errors_prog(
+ self.test_input[:1000].to(self.device), nb_to_log=10
+ )
- logger(
- f"accuracy_prog_test {n_epoch} nb_total {test_nb_total} nb_errors {test_nb_errors} accuracy {100.0*(1-test_nb_errors/test_nb_total):.02f}%"
- )
+ logger(
+ f"accuracy_prog_test {n_epoch} nb_total {test_nb_total} nb_errors {test_nb_errors} accuracy {100.0*(1-test_nb_errors/test_nb_total):.02f}%"
+ )
test_nb_total, test_nb_errors = compute_nb_errors_output(
self.test_input[:1000].to(self.device), nb_to_log=10