def tensorize(self, descr):
token_descr = [s.strip().split(" ") for s in descr]
l = max([len(s) for s in token_descr])
- token_descr = [s + ["<nul>"] * (l - len(s)) for s in token_descr]
+ token_descr = [s + ["#"] * (l - len(s)) for s in token_descr]
id_descr = [[self.token2id[u] for u in s] for s in token_descr]
return torch.tensor(id_descr, device=self.device)
# 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
# elements are trimed according to the triming for the first
- def trim(self, z, token="<nul>"):
+ def trim(self, z, token="#"):
n = self.token2id[token]
if type(z) == tuple:
x = z[0]
nb_train_samples,
nb_test_samples,
batch_size,
- height,
- width,
+ size,
logger=None,
device=torch.device("cpu"),
):
self.device = device
self.batch_size = batch_size
- self.grid_factory = grid.GridFactory(height=height, width=width)
+ self.grid_factory = grid.GridFactory(size=size)
if logger is not None:
logger(
)
# Build the tokenizer
- tokens = {}
+ tokens = set()
for d in [self.train_descr, self.test_descr]:
for s in d:
for t in s.strip().split(" "):
# the same descr
tokens = list(tokens)
tokens.sort()
- tokens = ["<nul>"] + tokens
+ tokens = ["#"] + tokens
self.token2id = dict([(t, n) for n, t in enumerate(tokens)])
self.id2token = dict([(n, t) for n, t in enumerate(tokens)])
- self.t_nul = self.token2id["<nul>"]
+ self.t_nul = self.token2id["#"]
self.t_true = self.token2id["<true>"]
self.t_false = self.token2id["<false>"]