embeddingbag_offsets_base.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/axis_set.hpp"
8 #include "ngraph/op/util/index_reduction.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace util
15  {
16  /// \brief Returns embeddings for given indices
17  class NGRAPH_API EmbeddingBagOffsetsBase : public Op
18  {
19  public:
20  static constexpr NodeTypeInfo type_info{"EmbeddingBagOffsetsBase", 3};
21  const NodeTypeInfo& get_type_info() const override { return type_info; }
22  /// \brief Constructs a EmbeddingBagOffsetsBase operation.
24  /// \brief Constructs a EmbeddingBagOffsetsBase operation.
25  ///
26  /// EmbeddingBagOffsetsBase constructs an output tensor by replacing every index in
27  /// a
28  /// given
29  /// input tensor with a row (from the weights matrix) at that index
30  ///
31  /// \param emb_table tensor containing the embedding lookup table of the module of
32  /// shape [num_emb, emb_dim1, emb_dim2, ...] and of type T
33  /// \param tensor of shape [num_indices] and of type T_IND. Required
34  /// \param offsets tensor of shape [batch] and of type T_IND containing the starting
35  /// index positions of each "bag" in indices. Required.
36  /// \param per_sample_weigths tensor of the same shape as indices and of type T.
37  /// Each value in this tensor are multiplied with each
38  /// value pooled from embedding table for each index. Optional.
39  /// \param default_index scalar of type T_IND containing default index in embedding
40  /// table to fill empty "bags". If not provided empty "bags"
41  /// are filled with zeros. Optional.
42 
44  const Output<Node>& indices,
45  const Output<Node>& offsets,
46  const Output<Node>& default_index,
47  const Output<Node>& per_sample_weights);
48 
49  EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
50  const Output<Node>& indices,
51  const Output<Node>& offsets,
52  const Output<Node>& default_index);
53 
54  EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
55  const Output<Node>& indices,
56  const Output<Node>& offsets);
57 
58  void validate_and_infer_types() override;
59  bool visit_attributes(AttributeVisitor& visitor) override;
60 
61  private:
62  static constexpr int EMB_TABLE = 0;
63  static constexpr int INDICES = 1;
64  static constexpr int OFFSETS = 2;
65  static constexpr int DEFAULT_INDEX = 3;
66  static constexpr int PER_SAMPLE_WEIGHTS = 4;
67  };
68  } // namespace util
69  } // namespace op
70 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Returns embeddings for given indices.
Definition: embeddingbag_offsets_base.hpp:18
EmbeddingBagOffsetsBase()=default
Constructs a EmbeddingBagOffsetsBase operation.
EmbeddingBagOffsetsBase(const Output< Node > &emb_table, const Output< Node > &indices, const Output< Node > &offsets, const Output< Node > &default_index, const Output< Node > &per_sample_weights)
Constructs a EmbeddingBagOffsetsBase operation.
const NodeTypeInfo & get_type_info() const override
Definition: embeddingbag_offsets_base.hpp:21
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27