fluid.layers.linear_chain_crf层 维度不匹配问题
Created by: wds2014
在使用ERNIE + CRF时,将ERNIE最后的输出h,h的维度为(batch_size, max_len, num_label),与标签信息label, label的维度为(batch_size, max_len) 送入到 fluid.layers.linear_chain_crf 报如下错误:
关键代码 loss_crf = F.layers.linear_chain_crf(h, labels)
报错信息
C++ Call Stacks (More useful to developers):
0 std::string paddle::platform::GetTraceBackString<std::string const&>(std::string const&, char const*, int) 1 paddle::platform::EnforceNotMet::EnforceNotMet(std::string const&, char const*, int) 2 paddle::operators::LinearChainCRFOp::InferShape(paddle::framework::InferShapeContext*) const 3 paddle::imperative::PreparedOp::Run(paddle::imperative::NameVarBaseMap const&, paddle::imperative::NameVarBaseMap const&, paddle::framework::AttributeMap const&) 4 paddle::imperative::OpBase::Run(paddle::framework::OperatorBase const&, paddle::imperative::NameVarBaseMap const&, paddle::imperative::NameVarBaseMap const&, paddle::framework::AttributeMap const&, paddle::platform::Place const&) 5 paddle::imperative::Tracer::TraceOp(std::string const&, paddle::imperative::NameVarBaseMap const&, paddle::imperative::NameVarBaseMap const&, paddle::framework::AttributeMap, paddle::platform::Place const&, bool)
Error Message Summary:
InvalidArgumentError: The Input(Emission) should be a 2-D tensor. But received: input rank 3, input shape [32, 200, 7]. [Hint: Expected emission_dims.size() == 2, but received emission_dims.size():3 != 2:2.] at (/paddle/paddle/fluid/operators/linear_chain_crf_op.cc:224) [operator < linear_chain_crf > error]
查看paddle开发文档,发现crf层是支持三维tensor输入的,请问下如何解决上述问题???
1)PaddlePaddle版本:paddlepaddle-gpu : 1.8.4.post107 2)Paddle-ernie : 0.0.4.dev1 3)GPU:2080TI 4)系统环境:UBUNTU18.04, python=3.6