madara (6) [Avatar] Offline
#1
HI

You can optimize ‘pud_trunc’ function in pag 186 by only a simple list comprehension
(instead of 16 line of inefficient e redundant code):



def pad_trunc2(data, maxlen, emb_dim):

    return [smp[:maxlen] + [[0.] * emb_dim] * (maxlen - len(smp)) for smp in data]



hobs (58) [Avatar] Offline
#2
That's definitely much better! We may leave the more verbose version int he text, in case it helps people that don't think in comprehensions like you do. But we'll definitely mention your improved version in a sidenote.