Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2021 Jijoong Moon <jijoong.moon@samsung.com>
4 : *
5 : * @file embedding.h
6 : * @date 04 March 2021
7 : * @brief This is Embedding Layer Class of Neural Network
8 : * @see https://github.com/nnstreamer/nntrainer
9 : * @author Jijoong Moon <jijoong.moon@samsung.com>
10 : * @bug No known bugs except for NYI items
11 : *
12 : */
13 :
14 : #ifndef __EMBEDDING_H__
15 : #define __EMBEDDING_H__
16 : #ifdef __cplusplus
17 :
18 : #include <common_properties.h>
19 : #include <layer_impl.h>
20 :
21 : namespace nntrainer {
22 :
23 : /**
24 : * @class EmbeddingLayer
25 : * @brief EmbeddingLayer
26 : * @todo Support setBatch for EmbeddingLayer
27 : */
28 : class EmbeddingLayer : public LayerImpl {
29 : public:
30 : /**
31 : * @brief Constructor of Embedding Layer
32 : */
33 : EmbeddingLayer();
34 :
35 : /**
36 : * @brief Destructor of Embedding Layer
37 : */
38 42 : ~EmbeddingLayer() = default;
39 :
40 : /**
41 : * @brief Move constructor.
42 : * @param[in] EmbeddingLayer &&
43 : */
44 : EmbeddingLayer(EmbeddingLayer &&rhs) noexcept = default;
45 :
46 : /**
47 : * @brief Move assignment operator.
48 : * @parma[in] rhs EmbeddingLayer to be moved.
49 : */
50 : EmbeddingLayer &operator=(EmbeddingLayer &&rhs) = default;
51 :
52 : /**
53 : * @copydoc Layer::finalize(InitLayerContext &context)
54 : */
55 : void finalize(InitLayerContext &context) override;
56 :
57 : /**
58 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
59 : */
60 : void forwarding(RunLayerContext &context, bool training) override;
61 :
62 : /**
63 :  * @copydoc Layer::incremental_forwarding(RunLayerContext &context, unsigned
64 :  * int from, unsigned int to, bool training)
65 :  */
66 : void incremental_forwarding(RunLayerContext &context, unsigned int from,
67 : unsigned int to, bool training) override;
68 :
69 : /**
70 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
71 : */
72 : void calcDerivative(RunLayerContext &context) override;
73 :
74 : /**
75 : * @copydoc Layer::calcGradient(RunLayerContext &context)
76 : */
77 : void calcGradient(RunLayerContext &context) override;
78 :
79 : /**
80 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
81 : * method)
82 : */
83 : void exportTo(Exporter &exporter,
84 : const ml::train::ExportMethods &method) const override;
85 :
86 : /**
87 : * @copydoc Layer::getType()
88 : */
89 64 : const std::string getType() const override { return EmbeddingLayer::type; };
90 :
91 : /**
92 : * @copydoc Layer::supportBackwarding()
93 : */
94 4 : bool supportBackwarding() const override { return false; }
95 :
96 : using Layer::setProperty;
97 :
98 : /**
99 : * @copydoc Layer::setProperty(const PropertyType type, const std::string
100 : * &value)
101 : */
102 : void setProperty(const std::vector<std::string> &values) override;
103 :
104 : static constexpr const char *type = "embedding";
105 :
106 : private:
107 : std::tuple<props::InDim, props::OutDim> embedding_props;
108 : unsigned int weight_idx;
109 : };
110 : } // namespace nntrainer
111 :
112 : #endif /* __cplusplus */
113 : #endif /* __EMBEDDING_H__ */
|