diff --git a/paddle/operators/linear_chain_crf_op.cc b/paddle/operators/linear_chain_crf_op.cc index 0f21ee7264b781dc8e03d77a7e9c4d442dbd5120..9caa2dc742715e2ddd1ef0729146cddc7c1a852d 100644 --- a/paddle/operators/linear_chain_crf_op.cc +++ b/paddle/operators/linear_chain_crf_op.cc @@ -195,8 +195,6 @@ class LinearChainCRFOp : public framework::OperatorWithKernel { // is the sequence number in a mini-batch. The dimension set here should be // resized to its correct size in the function Compute. ctx->SetOutputDim("LogLikelihood", {emission_dims[0], 1}); - - ctx->ShareLoD("Emission", /*->*/ "EmissionExps"); } protected: @@ -402,7 +400,7 @@ class LinearChainCRFGradOp : public framework::OperatorWithKernel { // operator is determined by its input "EmissionExps". framework::DataType IndicateDataType( const framework::ExecutionContext& ctx) const override { - return framework::ToDataType(ctx.Input("EmissionExps")->type()); + return framework::ToDataType(ctx.Input("LogLikelihood")->type()); } }; @@ -562,7 +560,9 @@ REGISTER_OP(linear_chain_crf, ops::LinearChainCRFOp, ops::LinearChainCRFOpMaker, linear_chain_crf_grad, ops::LinearChainCRFGradOp); REGISTER_OP_CPU_KERNEL( linear_chain_crf, - ops::LinearChainCRFOpKernel); + ops::LinearChainCRFOpKernel, + ops::LinearChainCRFOpKernel); REGISTER_OP_CPU_KERNEL( linear_chain_crf_grad, - ops::LinearChainCRFGradOpKernel); + ops::LinearChainCRFGradOpKernel, + ops::LinearChainCRFGradOpKernel); diff --git a/python/paddle/v2/framework/tests/test_linear_chain_crf_op.py b/python/paddle/v2/framework/tests/test_linear_chain_crf_op.py index 4d0cac2ad364eab1217bab6603a6ae276b2649c1..1cc6dc1aaa74eea38d7504d17b13918477588d94 100644 --- a/python/paddle/v2/framework/tests/test_linear_chain_crf_op.py +++ b/python/paddle/v2/framework/tests/test_linear_chain_crf_op.py @@ -32,7 +32,7 @@ class LinearChainCrfForward(object): # alpha is a memo table in dynamic programming to caculate # nomalization factor. self.alpha = np.zeros( - (seq_start_positions[-1], self.tag_num), dtype="float32") + (seq_start_positions[-1], self.tag_num), dtype="float64") self.log_likelihood = np.zeros((self.seq_num, 1)) def _l1_norm(self, x): @@ -92,12 +92,12 @@ class TestLinearChainCrfOp(OpTest): for i in range(SEQ_NUM): lod[-1].append(lod[-1][-1] + random.randint(1, MAX_SEQ_LEN)) emission = np.random.uniform(-1, 1, - [lod[-1][-1], TAG_NUM]).astype("float32") + [lod[-1][-1], TAG_NUM]).astype("float64") emission_row_max = np.amax(emission, axis=1, keepdims=True) emission_exps = np.exp(emission - emission_row_max) transition = np.random.uniform(-0.5, 0.5, - [TAG_NUM + 2, TAG_NUM]).astype("float32") + [TAG_NUM + 2, TAG_NUM]).astype("float64") transition_exps = np.exp(transition) labels = np.random.randint( @@ -128,17 +128,11 @@ class TestLinearChainCrfOp(OpTest): self.check_output() def test_check_grad(self): - self.check_grad( - ["Emission", "Transition"], - "LogLikelihood", - max_relative_error=0.05) + self.check_grad(["Emission", "Transition"], "LogLikelihood") def test_check_grad_ignore_transition(self): self.check_grad( - ["Emission"], - "LogLikelihood", - max_relative_error=0.05, - no_grad_set=set("Transition")) + ["Emission"], "LogLikelihood", no_grad_set=set("Transition")) if __name__ == "__main__":