device
), self.test_ar_mask.to(device)
- self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
+ self.nb_codes = (max(self.train_input.max(), self.test_input.max()) + 1).item()
# A bit of paranoia never hurts
assert self.nb_codes <= max_nb_codes
# Make a list of strings from a tensor
def detensorize(self, x):
- return [" ".join([self.id2token[t.item()] for t in r]) for r in x]
+ def id2token(t):
+ try:
+ return self.id2token[t.item()]
+ except KeyError:
+ return "?"
+
+ return [" ".join([id2token(t) for t in r]) for r in x]
# trim all the tensors in the tuple z to remove as much token from
# left and right in the first tensor. If z is a tuple, all its
)
self.test_input = self.map2seq(test_mazes.to(device), test_paths.to(device))
- self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
+ self.nb_codes = (max(self.train_input.max(), self.test_input.max()) + 1).item()
def batches(self, split="train", nb_to_use=-1, desc=None):
assert split in {"train", "test"}
self.device,
)
- self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
+ self.nb_codes = (max(self.train_input.max(), self.test_input.max()) + 1).item()
def batches(self, split="train", nb_to_use=-1, desc=None):
assert split in {"train", "test"}
counts = F.one_hot(counts).sum(0)
logger(f"test_pop_stack_counts {counts}")
- self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
+ self.nb_codes = (max(self.train_input.max(), self.test_input.max()) + 1).item()
def batches(self, split="train", nb_to_use=-1, desc=None):
assert split in {"train", "test"}
def compute_nb_correct(input):
result = input.clone()
stack.remove_popped_values(result, self.nb_stacks, self.nb_digits)
+
ar_mask = (result != input).long()
+ result *= 1 - ar_mask
+
masked_inplace_autoregression(
model,
self.batch_size,
stack.remove_popped_values(result, self.nb_stacks, self.nb_digits)
ar_mask = (result != input).long()
- # for n in range(result.size(0)):
- # logger(
- # f"test_before {stack.seq_to_str(result[n],nb_stacks=self.nb_stacks,nb_digits=self.nb_digits)}"
- # )
+ for n in range(result.size(0)):
+ logger(
+ f"test_before {stack.seq_to_str(result[n],nb_stacks=self.nb_stacks,nb_digits=self.nb_digits)}"
+ )
+
+ result *= 1 - ar_mask
masked_inplace_autoregression(
model,
s = " ".join(seq)
logger(f"example_seq {s}")
- self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
+ self.nb_codes = (max(self.train_input.max(), self.test_input.max()) + 1).item()
def batches(self, split="train", nb_to_use=-1, desc=None):
assert split in {"train", "test"}
self.train_input = self.tensorize(train_sequences)
self.test_input = self.tensorize(test_sequences)
- self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
+ self.nb_codes = (max(self.train_input.max(), self.test_input.max()) + 1).item()
def batches(self, split="train", nb_to_use=-1, desc=None):
assert split in {"train", "test"}
# Make a list of strings from a tensor
def tensor2str(self, x):
- return [" ".join([self.id2token[t.item()] for t in r]) for r in x]
+ def id2token(t):
+ try:
+ return self.id2token[t.item()]
+ except KeyError:
+ return "?"
+
+ return [" ".join([id2token(t) for t in r]) for r in x]
# trim all the tensors in the tuple z to remove as much token from
# left and right in the first tensor. If z is a tuple, all its
for e in self.test_ref_test_errors:
f.write(f"{e}\n")
- self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
+ self.nb_codes = (max(self.train_input.max(), self.test_input.max()) + 1).item()
def batches(self, split="train", desc=None):
assert split in {"train", "test"}