EmbeddingBag: Pooled Lookups

easy
Unit 8 · Attention0/3 to milestone

EmbeddingBag looks up a variable number of ids per example and pools them, without building a padded tensor.

The input is a flat list of ids plus offsets marking where each bag starts (PyTorch's format). Implement embedding_bag(table, ids, offsets, mode="mean") with mode in "sum", "mean", "max". An empty bag returns a row of zeros.

#embeddings#recommenders2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
EmbeddingBag: Pooled Lookups · TechGradify