← Lesson
The Embedding Table
Joeven
Run
Reset
Python loads on first run
stoi = {"<pad>": 0, "refund": 1, "invoice": 2, "please": 3, "now": 4} itos = {i: t for t, i in stoi.items()} table = [ [0.0, 0.0, 0.0], [0.1, 0.0, 0.9], [0.0, 0.1, 0.8], [0.5, 0.5, 0.1], [0.4, 0.6, 0.0], ] def encode(text): return [stoi[w] for w in text.split()] ids = encode("please refund invoice") vecs = [table[i] for i in ids] print("ids", ids) print("tokens", [itos[i] for i in ids]) for i, v in zip(ids, vecs): print(itos[i], v) pooled = [sum(row[d] for row in vecs) / len(vecs) for d in range(3)] print("mean pool", [round(x, 3) for x in pooled]) pad_row = table[0] print("pad row", pad_row) print("width", len(table[1]), "vocab", len(table))
Run to execute this in your browser. Nothing is sent to a server.