def tensorize(self, descr):
token_descr = [ s.strip().split(' ') for s in descr ]
l = max([ len(s) for s in token_descr ])
- token_descr = [ [ '<nul>' ] * (l - len(s)) + s for s in token_descr ]
- #token_descr = [ s + [ '<nul>' ] * (l - len(s)) for s in token_descr ]
+ #token_descr = [ [ '<nul>' ] * (l - len(s)) + s for s in token_descr ]
+ token_descr = [ s + [ '<nul>' ] * (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)
##############################
-class Residual(nn.Module):
+class WithResidual(nn.Module):
def __init__(self, *f):
super().__init__()
self.f = f[0] if len(f) == 1 else nn.Sequential(*f)
for _ in range(nb_blocks):
trunk_blocks += [
- Residual(
+ WithResidual(
nn.LayerNorm((dim_model,)),
QKVAttention(
dim_in = dim_model,
causal = True, attention_dropout = dropout
),
),
- Residual(
+ WithResidual(
nn.LayerNorm((dim_model,)),
nn.Linear(in_features = dim_model, out_features = dim_hidden),
nn.ReLU(),
return []
seen[x] = (color_id[x], k // width, k % width)
- square_infos = zip(*seen.values())
+ square_infos = tuple(zip(*seen.values()))
square_c = torch.tensor(square_infos[0])
square_i = torch.tensor(square_infos[1])
square_j = torch.tensor(square_infos[2])