1 #include "caffe2/experiments/operators/sparse_funhash_op.h" 6 REGISTER_CPU_OPERATOR(SparseFunHash, SparseFunHashOp<float, CPUContext>);
9 SparseFunHashGradientOp<float, CPUContext>);
11 OPERATOR_SCHEMA(SparseFunHash)
15 This layer compresses a fully-connected layer for sparse inputs 17 It takes four required inputs and an option fifth input. 18 The first three inputs `scalars`, `indices`, and `segment_ids` are 19 the sparse segmented representation of sparse data, which are the 20 same as the last three inputs of the `SparseSortedSegmentWeightedSum` 21 operator. If the argument `num_segments` is specified, it would be used 22 as the first dimension for the output; otherwise it would be derived 23 from the maximum segment ID. 25 The fourth input is a 1D weight vector. Each entry of the fully-connected 26 layer would be randomly mapped from one of the entries in this vector. 28 When the optional fifth input vector is present, each weight of the 29 fully-connected layer would be the linear combination of K entries 30 randomly mapped from the weight vector, provided the input 31 (length-K vector) serves as the coefficients. 33 .Input(0, "scalars",
"Values of the non-zero entries of the sparse data.")
34 .Input(1,
"indices",
"Indices to the non-zero valued features.")
38 "Segment IDs corresponding to the non-zero entries.")
39 .Input(3,
"weight",
"Weight vector")
43 "Optional coefficients for linear combination of hashed weights.")
47 "Output tensor with the first dimension equal to the number " 49 .Arg(
"num_outputs",
"Number of outputs")
50 .Arg(
"num_segments",
"Number of segments");
52 OPERATOR_SCHEMA(SparseFunHashGradient).NumInputs(5, 6).NumOutputs(2, 3);
54 class GetSparseFunHashGradient :
public GradientMakerBase {
55 using GradientMakerBase::GradientMakerBase;
56 vector<OperatorDef> GetGradientDefs()
override {
57 if (def_.input_size() == 4) {
58 return SingleGradientDef(
59 "SparseFunHashGradient",
61 vector<string>{GO(0), I(0), I(1), I(2), I(3)},
62 vector<string>{GI_V(3), GI_I(3)});
65 return SingleGradientDef(
66 "SparseFunHashGradient",
68 vector<string>{GO(0), I(0), I(1), I(2), I(3), I(4)},
69 vector<string>{GI_V(3), GI_I(3), GI(4)});
73 REGISTER_GRADIENT(SparseFunHash, GetSparseFunHashGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...