调用动态图实现的Linear_chain_crf的问题
Created by: yaweisun
实现该接口的文件如下: https://github.com/PaddlePaddle/models/blob/develop/dygraph/lac/sequence_labeling.py 运行的环境是aistudio高级版,paddlepaddle 1.7.1, python 3.7 我调用的代码如下:
linear_chain_crf = Linear_chain_crf(
param_attr=fluid.ParamAttr(
name='linear_chain_crfw', learning_rate=LR),
size=num_labels)
crf_cost = linear_chain_crf(emission, label=label, length=MAX_SEQLEN)
emission.shape和label.shape均为[16, 400, 5]。其中16是batch_size,400是序列最大长度,5是序列标注的类别数量。 执行之后报错,没有找到该接口对输入参数的具体要求,因而想咨询一下这是出现这个问题的原因。报错信息如下:
> ---------------------------------------EnforceNotMet Traceback (most recent call last)<ipython-input-36-85157a21fed9> in <module>
> ----> 1 linear_chain_crf(emission, label=label, length=128)
> /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in __call__(self, *inputs, **kwargs)
> 302 self._built = True
> 303
> --> 304 outputs = self.forward(*inputs, **kwargs)
> 305 return outputs
> 306
> ~/ernie/sequence_labeling.py in forward(self, input, label, length)
> 177 },
> 178 attrs={
> --> 179 "is_test": self._is_test,
> 180 })
> 181 return log_likelihood
> /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layer_object_helper.py in append_op(self, type, inputs, outputs, attrs, stop_gradient)
> 50 outputs=outputs,
> 51 attrs=attrs,
> ---> 52 stop_gradient=stop_gradient)
> 53
> 54 def _multiple_input(self, inputs_in):
> /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py in append_op(self, *args, **kwargs)
> 2514 kwargs.get("outputs", {}), attrs
> 2515 if attrs else {},
> -> 2516 kwargs.get("stop_gradient", False))
> 2517 else:
> 2518 op_desc = self.desc.append_op()
> /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/tracer.py in trace_op(self, type, inputs, outputs, attrs, stop_gradient)
> 37 self.trace(type, inputs, outputs, attrs,
> 38 framework._current_expected_place(), self._train_mode and
> ---> 39 not stop_gradient)
> 40
> 41 def train_mode(self):
> EnforceNotMet:
>
> --------------------------------------------
> C++ Call Stacks (More useful to developers):
> --------------------------------------------
> 0 std::string paddle::platform::GetTraceBackString<std::string>(std::string&&, char const*, int)
> 1 paddle::platform::EnforceNotMet::EnforceNotMet(paddle::platform::ErrorSummary const&, char const*, int)
>
> ----------------------
> Error Message Summary:
> ----------------------
> Error: Python object is not type of St10shared_ptrIN6paddle10imperative7VarBaseEE at (/paddle/paddle/fluid/pybind/imperative.cc:158)