17 #include "caffe2/experiments/operators/sparse_funhash_op.h" 22 REGISTER_CPU_OPERATOR(SparseFunHash, SparseFunHashOp<float, CPUContext>);
23 REGISTER_CPU_OPERATOR(
24 SparseFunHashGradient,
25 SparseFunHashGradientOp<float, CPUContext>);
27 OPERATOR_SCHEMA(SparseFunHash)
30 .DisallowInputFillers()
32 This layer compresses a fully-connected layer for sparse inputs 34 It takes four required inputs and an option fifth input. 35 The first three inputs `scalars`, `indices`, and `segment_ids` are 36 the sparse segmented representation of sparse data, which are the 37 same as the last three inputs of the `SparseSortedSegmentWeightedSum` 38 operator. If the argument `num_segments` is specified, it would be used 39 as the first dimension for the output; otherwise it would be derived 40 from the maximum segment ID. 42 The fourth input is a 1D weight vector. Each entry of the fully-connected 43 layer would be randomly mapped from one of the entries in this vector. 45 When the optional fifth input vector is present, each weight of the 46 fully-connected layer would be the linear combination of K entries 47 randomly mapped from the weight vector, provided the input 48 (length-K vector) serves as the coefficients. 50 .Input(0, "scalars",
"Values of the non-zero entries of the sparse data.")
51 .Input(1,
"indices",
"Indices to the non-zero valued features.")
55 "Segment IDs corresponding to the non-zero entries.")
56 .Input(3,
"weight",
"Weight vector")
60 "Optional coefficients for linear combination of hashed weights.")
64 "Output tensor with the first dimension equal to the number " 66 .Arg(
"num_outputs",
"Number of outputs")
67 .Arg(
"num_segments",
"Number of segments");
69 OPERATOR_SCHEMA(SparseFunHashGradient)
72 .DisallowInputFillers();
74 class GetSparseFunHashGradient :
public GradientMakerBase {
75 using GradientMakerBase::GradientMakerBase;
76 vector<OperatorDef> GetGradientDefs()
override {
77 if (def_.input_size() == 4) {
78 return SingleGradientDef(
79 "SparseFunHashGradient",
81 vector<string>{GO(0), I(0), I(1), I(2), I(3)},
82 vector<string>{GI_V(3), GI_I(3)});
85 return SingleGradientDef(
86 "SparseFunHashGradient",
88 vector<string>{GO(0), I(0), I(1), I(2), I(3), I(4)},
89 vector<string>{GI_V(3), GI_I(3), GI(4)});
93 REGISTER_GRADIENT(SparseFunHash, GetSparseFunHashGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...