operator < linear_chain_crf > error : Expected static_cast<size_t>(*std::max_element(lbl, lbl + seq_length)) < tag_num, but received static_cast<size_t>(*std::max_element(lbl, lbl + seq_length)):22 >= tag_num:7. An invalid tag label that execesses the ...
Created by: Melonzhou
paddle-cpu-1.6.0 组网部分: `def create_net(slots, is_inference=False): """create net""" text_a = slots[0] text_a_mask = slots[1] text_a_lens = slots[2] label_a = slots[3] label_a_mask = slots[4] label_a_lens = slots[5]
unpad_words_emb = fluid.layers.sequence_unpad(text_a, length=text_a_lens)
unpad_labels = fluid.layers.sequence_unpad(label_a, length=label_a_lens)
word_emb_dim = 768
grnn_hidden_dim = 768
emb_lr = 5
crf_lr = 0.2
bigru_num = 2
init_bound = 0.1
vocab_size = 17964
num_labels = 7
def _bigru_layer(input_feature):
"""
define the bidirectional gru layer
"""
pre_gru = fluid.layers.fc(
input=input_feature,
size=grnn_hidden_dim * 3,
param_attr=fluid.ParamAttr(
initializer=fluid.initializer.Uniform(
low=-init_bound, high=init_bound),
regularizer=fluid.regularizer.L2DecayRegularizer(
regularization_coeff=1e-4)))
gru = fluid.layers.dynamic_gru(
input=pre_gru,
size=grnn_hidden_dim,
param_attr=fluid.ParamAttr(
initializer=fluid.initializer.Uniform(
low=-init_bound, high=init_bound),
regularizer=fluid.regularizer.L2DecayRegularizer(
regularization_coeff=1e-4)))
pre_gru_r = fluid.layers.fc(
input=input_feature,
size=grnn_hidden_dim * 3,
param_attr=fluid.ParamAttr(
initializer=fluid.initializer.Uniform(
low=-init_bound, high=init_bound),
regularizer=fluid.regularizer.L2DecayRegularizer(
regularization_coeff=1e-4)))
gru_r = fluid.layers.dynamic_gru(
input=pre_gru_r,
size=grnn_hidden_dim,
is_reverse=True,
param_attr=fluid.ParamAttr(
initializer=fluid.initializer.Uniform(
low=-init_bound, high=init_bound),
regularizer=fluid.regularizer.L2DecayRegularizer(
regularization_coeff=1e-4)))
bi_merge = fluid.layers.concat(input=[gru, gru_r], axis=1)
return bi_merge
word_embedding = fluid.layers.embedding(
input=unpad_words_emb,
size=[vocab_size, word_emb_dim],
dtype='float32',
param_attr=fluid.ParamAttr(
learning_rate=emb_lr,
name="word_emb",
initializer=fluid.initializer.Uniform(
low=-init_bound, high=init_bound)))
input_feature = word_embedding
for i in range(bigru_num):
bigru_output = _bigru_layer(input_feature)
input_feature = bigru_output
emission = fluid.layers.fc(
size=num_labels,
input=bigru_output,
param_attr=fluid.ParamAttr(
initializer=fluid.initializer.Uniform(
low=-init_bound, high=init_bound),
regularizer=fluid.regularizer.L2DecayRegularizer(
regularization_coeff=1e-4)))
crf_cost = fluid.layers.linear_chain_crf(
input=emission,
label=unpad_labels,
param_attr=fluid.ParamAttr(
name='crfw',
learning_rate=crf_lr))
crf_decode = fluid.layers.crf_decoding(
input=emission, param_attr=fluid.ParamAttr(name='crfw'))
if is_inference:
feed_targets_name = [text_a.name, text_a_lens.name]
output_targets_name = [crf_decode]
return feed_targets_name, output_targets_name
avg_cost = fluid.layers.mean(x=crf_cost)
graph_vars = collections.OrderedDict()
graph_vars["loss"] = avg_cost
graph_vars["sequence_label_infer"] = crf_decode
graph_vars["label"] = unpad_labels
(precision, recall, f1_score, num_infer_chunks, num_label_chunks, num_correct_chunks) = fluid.layers.chunk_eval( input=graph_vars["sequence_label_infer"], label=graph_vars["label"], chunk_scheme="plain", num_chunk_types=51)
graph_vars["precision"] = precision
graph_vars["recall"] = recall
graph_vars["f1_score"] = f1_score
graph_vars["num_infer_chunks"] = num_infer_chunks
graph_vars["num_label_chunks"] = num_label_chunks
graph_vars["num_correct_chunks"] = num_correct_chunks
`
Error Message Summary:
PaddleCheckError: Expected static_cast<size_t>(*std::max_element(lbl, lbl + seq_length)) < tag_num, but received static_cast<size_t>(*std::max_element(lbl, lbl + seq_length)):22 >= tag_num:7. An invalid tag label that execesses the largest tag number. at [/home/teamcity/work/ef54dc8a5b211854/paddle/fluid/operators/linear_chain_crf_op.h:207] [operator < linear_chain_crf > error]
没理解这个22和7是从哪里来的