|
|
|
@ -32,11 +32,16 @@ class LookupTableOp : public framework::OperatorWithKernel {
|
|
|
|
|
|
|
|
|
|
auto table_dims = ctx->GetInputDim("W");
|
|
|
|
|
auto ids_dims = ctx->GetInputDim("Ids");
|
|
|
|
|
int ids_rank = ids_dims.size();
|
|
|
|
|
|
|
|
|
|
PADDLE_ENFORCE_EQ(ids_dims.size(), 2);
|
|
|
|
|
PADDLE_ENFORCE_EQ(ids_dims[1], 1);
|
|
|
|
|
PADDLE_ENFORCE_EQ(table_dims.size(), 2);
|
|
|
|
|
PADDLE_ENFORCE_EQ(ids_dims[ids_rank - 1], 1,
|
|
|
|
|
"The last dimension of the 'Ids' tensor must be 1.");
|
|
|
|
|
|
|
|
|
|
ctx->SetOutputDim("Out", {ids_dims[0], table_dims[1]});
|
|
|
|
|
auto output_dims =
|
|
|
|
|
framework::vectorize(framework::slice_ddim(ids_dims, 0, ids_rank - 1));
|
|
|
|
|
output_dims.push_back(table_dims[1]);
|
|
|
|
|
ctx->SetOutputDim("Out", framework::make_ddim(output_dims));
|
|
|
|
|
|
|
|
|
|
if (ctx->GetOutputsVarType("Out")[0] ==
|
|
|
|
|
framework::proto::VarType::LOD_TENSOR) {
|
|
|
|
@ -61,8 +66,7 @@ class LookupTableOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
AddInput("Ids",
|
|
|
|
|
"An input with type int32 or int64 "
|
|
|
|
|
"contains the ids to be looked up in W. "
|
|
|
|
|
"Ids must be a column vector with rank = 2. "
|
|
|
|
|
"The 2nd dimension size must be 1.");
|
|
|
|
|
"The last dimension size must be 1.");
|
|
|
|
|
AddOutput("Out", "The lookup results, which have the same type as W.");
|
|
|
|
|
AddAttr<bool>("is_sparse",
|
|
|
|
|
"(boolean, default false) "
|
|
|
|
|