From: François Fleuret Date: Tue, 4 Jul 2023 21:43:00 +0000 (+0200) Subject: Update. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=02b0a7bb770f07f2e91f1c77b899815516087b6a;p=picoclvr.git Update. --- diff --git a/expr.py b/expr.py index baee502..723022c 100755 --- a/expr.py +++ b/expr.py @@ -60,7 +60,7 @@ def generate_sequences(nb, nb_variables=5, length=20, randomize_length=False): while result == None or max(result.values()) > 100: l = length if l > 5 and randomize_length: - l = 5 + torch.randint(l-5, (1,)).item() + l = 5 + torch.randint(l - 5, (1,)).item() p, v = generate_program(nb_variables, l) v = ", ".join(['"' + v + '": ' + v for v in v]) ldict = {} diff --git a/main.py b/main.py index c52881b..35bf02c 100755 --- a/main.py +++ b/main.py @@ -1028,10 +1028,15 @@ class TaskExpr(Task): self.device = device train_sequences = expr.generate_sequences( - nb_train_samples, nb_variables=nb_variables, length=2*sequence_length, randomize_length=True, + nb_train_samples, + nb_variables=nb_variables, + length=2 * sequence_length, + randomize_length=True, ) test_sequences = expr.generate_sequences( - nb_test_samples, nb_variables=nb_variables, length=sequence_length, + nb_test_samples, + nb_variables=nb_variables, + length=sequence_length, ) self.char2id = dict( [ @@ -1084,8 +1089,8 @@ class TaskExpr(Task): input.split(self.batch_size), dynamic_ncols=True, desc=desc ): if split == "train": - last=(batch!=self.filler).max(0).values.nonzero().max()+1 - batch=batch[:,:last] + last = (batch != self.filler).max(0).values.nonzero().max() + 1 + batch = batch[:, :last] yield batch def vocabulary_size(self): @@ -1131,7 +1136,7 @@ class TaskExpr(Task): ) correct = (1 - ar_mask) * self.space + ar_mask * input for n in range(result.size(0)): - comment="GOOD" if (result[n]-input[n]).abs().max()==0 else "" + comment = "GOOD" if (result[n] - input[n]).abs().max() == 0 else "" log_string(f"test_after {self.seq2str(result[n])} {comment}") log_string(f"correct {self.seq2str(correct[n])}") ##############################################################