3.1 KiB
EmbeddingBagOffsetsSum
@sphinxdirective
.. meta:: :description: Learn about EmbeddingBagOffsetsSum-3 - a sparse operation, which can be performed on three required and two optional input tensors.
Versioned name: EmbeddingBagOffsetsSum-3
Category: Sparse
Short description: Computes sums of "bags" of embeddings, without instantiating the intermediate embeddings.
Detailed description: This is the second case of the PyTorch EmbeddingBag <https://pytorch.org/docs/stable/nn.html#embeddingbag>__ , it has indices in two 1D tensors provided as 2nd and 3rd inputs. For each index in indices this operator gets values from data embedding table and sums all values belonging to each bag. Values in offsets define starting index in indices tensor of each "bag", e.g. offsets with value [0,3,4,4,6] define 5 "bags" containing [3,1,0,2,n-6] elements.
Attributes: EmbeddingBagOffsetsSum operation has no attributes.
Inputs:
- 1:
emb_tabletensor containing the embedding lookup table of the module of shape[num_emb, emb_dim1, emb_dim2, ...]and of type T. Required. - 2:
indicestensor of shape[num_indices]and of type T_IND. Required. - 3:
offsetstensor of shape[batch]and of type T_IND containing the starting index positions of each "bag" inindices. Required. - 4:
default_indexscalar of type T_IND containing default index in embedding table to fill empty "bags". If not provided empty "bags" are filled with zeros. Optional. - 5:
per_sample_weightstensor of the same shape asindicesand of type T. Each value in this tensor are multiplied with each value pooled from embedding table for each index. Optional, default is tensor of ones.
Outputs:
- 1: tensor of shape
[batch, emb_dim1, emb_dim2, ...]and of type T containing embeddings for each bag.
Types
- T: any numeric type.
- T_IND:
int32orint64.
Example
.. code-block:: cpp
<layer ... type="EmbeddingBagOffsetsSum" ... > < !-- emb_table value is: -0.2, -0.6], [-0.1, -0.4], [-1.9, -1.8], [-1., 1.5], [ 0.8, -0.7 --> 5 2 < !-- indices value is: [0, 2, 3, 4] --> 4 < !-- offsets value is: [0, 2, 2] - 3 "bags" containing [2,0,4-2] elements, second "bag" is empty --> 3 < !-- default_index value is: 0 --> < !-- per_sample_weigths value is: [0.5, 0.5, 0.5, 0.5] --> 4 < !-- output value is: -1.05, -1.2], [-0.2, -0.6], [-0.1, 0.4 --> 3 2
@endsphinxdirective