ERNIE 接 CRF 层报错(序列标注任务)
Created by: SunnyGJing
做序列标注任务。 修改了ERNIE的sequence_label.py文件,把模型ernie+fc+softmax换成ernie+fc+crf 结果报错了,如下: (求解决方案,谢谢)
C++ Callstacks: Enforce failed. Expected emission_weights->NumLevels() == 1UL, but received emission_weights->NumLevels():0 != 1UL:1. The Input(Emission) should be a sequence. at [/paddle/paddle/fluid/operators/crf_decoding_op.h:39]
我的代码:
enc_out = ernie.get_sequence_output()
feature_out = fluid.layers.fc( input=enc_out, size=args.num_labels, num_flatten_dims=2,
param_attr=fluid.ParamAttr( name="cls_seq_label_out_w",
initializer=fluid.initializer.TruncatedNormal(scale=0.02)),
bias_attr=fluid.ParamAttr( name="cls_seq_label_out_b", initializer=fluid.initializer.Constant(0.)))
feature_out = fluid.layers.flatten(feature_out, axis=2)
ret_labels = fluid.layers.flatten(labels, axis=2)
crf_cost = fluid.layers.linear_chain_crf( input=feature_out, label=ret_labels,
param_attr=fluid.ParamAttr(name='crfw', learning_rate=1e-3))
loss = fluid.layers.mean(x=crf_cost)
crf_decode = fluid.layers.crf_decoding( input=feature_out, param_attr=fluid.ParamAttr(name='crfw'))
ret_infers = fluid.layers.flatten(crf_decode, axis=2)