训练中报错:paddle.fluid.core.EnforceNotMet: Enforce failed. Expected ids_dims[ids_rank - 1] == 1, but received ids_dims[ids_rank - 1]:128 != 1:1.
Created by: hweidream
` def train(conf_dict, data_reader, use_cuda=False, is_local=True): label_dict_len = data_reader.get_dict_size('label_dict') # 输入 # data layer word = fluid.layers.data( name='word_data', shape=[1], dtype='int64', lod_level=1) postag = fluid.layers.data( name='token_dist', shape=[1], dtype='int64', lod_level=1) # label z = fluid.layers.data( name='target', shape=[1], dtype='int64', lod_level=1) target = fluid.layers.fill_constant_batch_size_like(z, shape=[-1, label_dict_len], dtype='int64', value=0)
# 网络结构
# embedding + lstm
feature_out = db_lstm(**locals())
#多标签分类损失函数
class_cost = fluid.layers.sigmoid_cross_entropy_with_logits(x=feature_out, \
label=target)
avg_cost = fluid.layers.mean(class_cost)
# 优化方法
sgd_optimizer = fluid.optimizer.AdamOptimizer(
learning_rate=2e-3, )
# regularization=fluid.regularizer.L2Decay(regularization_coeff=8e-4))
sgd_optimizer.minimize(avg_cost)
train_batch_reader = paddle.batch(
paddle.reader.shuffle(data_reader.get_train_reader(), buf_size=8192),
batch_size=conf_dict['batch_size'])
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
feeder = fluid.DataFeeder(feed_list=[word, postag, target], place=place)
exe = fluid.Executor(place)
def train_loop(main_program, trainer_id=0):
exe.run(fluid.default_startup_program())
`