Caffe2 - C++ API
A deep learning, cross platform ML framework
sinusoid_position_encoding_op.cc
1 #include "caffe2/operators/sinusoid_position_encoding_op.h"
2 
3 namespace caffe2 {
4 REGISTER_CPU_OPERATOR(
5  SinusoidPositionEncoding,
6  SinusoidPositionEncodingOp<CPUContext>);
7 
8 OPERATOR_SCHEMA(SinusoidPositionEncoding)
9  .NumInputs(1)
10  .NumOutputs(1)
11  .SetDoc(R"DOC(
12 Calculates a sinusoid position encoding tensor as described
13 in https://arxiv.org/abs/1706.03762. Takes a 2-D tensor
14 (of size M x K) of positions as input, the embedding size
15 as an argument, and outputs a position encoding tensor of
16 size (M x K x embedding_size). Here M is typically the max
17 sequence length and K is typically the batch size.
18 The input tensor must satisfy input[m, 0] == input[m, k] for all k.
19 
20 Encoded as amplitude * SIN(pos/alpha^(i/embedding_size)) if i is even,
21 else amplitude * COS(pos/alpha^(i/embedding_size)). Here, pos is the position,
22 alpha and amplitude are tuning parameters, i is the current dimension for
23 the embedding, and embedding_size is the number of total dimensions in
24 the embedding.
25 )DOC")
26  .Arg(
27  "embedding_size",
28  "Desired embedding size/number of dimensions -- defaults to 100")
29  .Arg("alpha", "Sinusoid tuning parameter -- defaults to 10000")
30  .Arg("amplitude", "Amplitude of Sin/Cos output")
31  .Input(0, "positions", "2-D tensor of positions to be encoded")
32  .Output(0, "output", "3-D tensor representing the positional encoding");
33 
34 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13