if __name__ == '__main__': itokens = TokenList(list('0123456789')) otokens = TokenList(list('0123456789abcdefx')) def GenSample(): x = random.randint(0, 99999) y = hex(x); x = str(x) return x, y X, Y = [], [] for _ in range(100000): x, y = GenSample() X.append(list(x)) Y.append(list(y)) X, Y = pad_to_longest(X, itokens), pad_to_longest(Y, otokens) print(X.shape, Y.shape) s2s = Transformer(itokens, otokens, 10, 15) lr_scheduler = LRSchedulerPerStep(256, 4000) s2s.compile('adam') s2s.model.summary() class TestCallback(Callback): def on_epoch_end(self, epoch, logs = None): print('\n') for test in [123, 13245, 33467]: ret = s2s.decode_sequence(str(test)) print(test, ret, hex(test)) print('\n')
x1 = random.randint(0, 99999) x2 = random.randint(0, 99999) x2 = str(x2) y = hex(x1); x1 = str(x1) return x1, x2, y X1, X2, Y = [], [], [] for _ in range(100000): x1, x2, y = GenSample() X1.append(list(x1)) X2.append(list(x1)) Y.append(list(y)) X1, X2, Y = pad_to_longest(X1, itokens1), pad_to_longest(X2, itokens2), pad_to_longest(Y, otokens) print(X1.shape, X2.shape, Y.shape) s2s = Transformer(itokens1, itokens2, otokens, 10, 15) lr_scheduler = LRSchedulerPerStep(256, 4000) s2s.compile('adam') s2s.model.summary() class TestCallback(Callback): def on_epoch_end(self, epoch, logs=None): print('\n') for test in [123, 13245, 33467]: ret = s2s.decode_sequence(str(test)) print(test, ret, hex(test)) print('\n')