NeuralNetwork.cpp:199] Check failed: inArgs.size() == dataLayers_.size() (3 vs. 5)
请问为什么Inputs中输入为5, Datalayer也为5,且dataprovider输入也为5,还是会报上面的错
trainer_config.conf配置:
#!/usr/bin/env python
import os
import sys
import math
import paddle.trainer.recurrent_units as recurrent
cluster_config(
fs_name="*",
fs_ugi="*",
train_data_path="*",
test_data_path="*",
output_path="*",
)
simplified_model = True
src_dict_path = get_config_arg("src_dict_path", str)
tgt_dict_path = get_config_arg("tgt_dict_path", str)
generating = get_config_arg("generating", bool, False)
max_words = get_config_arg("max_words", int, 80)
gen_trans_file = get_config_arg("gen_trans_file", str, None)
beam_size = get_config_arg("beam_size", int, 3)
max_frames = 150
source_language_dict_dim = len(open(src_dict_path).readlines())
target_language_dict_dim = len(open(tgt_dict_path).readlines())
dict_for_gen = tgt_dict_path
clipping_thd = 25
word_vec_dim = 512
latent_chain_dim = 512
# default parameters
default_decay_rate(8e-4)
default_num_batches_regularization(1)
default_gradient_clipping_threshold(10)
model_type("recurrent_nn")
args = ["--src_dict_path", src_dict_path,
"--tgt_dict_path", tgt_dict_path,
"--max_words", str(max_words),
]
if generating:
args.append("--generating")
load_data_args = " ".join(args)
print("gen arg for pydata: %s" % (load_data_args), sys.stderr)
TestData(PyData(files = ("gen.list"),
load_data_module = "nmt_provider_first_round",
load_data_object = "processData2",
load_data_args = load_data_args))
Settings(algorithm = "sgd", batch_size = 1, learning_rate = 0)
else:
load_data_args = " ".join(args)
TrainData(PyData(files = ("train.list"),
load_data_module = "nmt_provider_first_round",
load_data_object = "processData2",
load_data_args = load_data_args))
TestData(PyData(files = ("test.list"),
load_data_module = "nmt_provider_first_round",
load_data_object = "processData2",
load_data_args = load_data_args))
Settings(
algorithm = "sgd",
learning_method = "adam",
learning_rate = 5e-4,
do_average_in_cpu = True,
learning_rate_decay_a = 0,
learning_rate_decay_b = 0,
batch_size = 128,
average_window = 0.5,
max_average_window = 2500 * 2,
num_batches_per_send_parameter = 1,
num_batches_per_get_parameter = 1,
)
#################################### network #######################################
def gru_encoder(name, size, input, clipping_thd, simplified_model=False):
recurrent.GatedRecurrentLayerGroup(
name = "annotation_forward",
size = size,
para_prefix="_annotation_forward",
active_type = "tanh",
gate_active_type = "sigmoid",
inputs = [FullMatrixProjection(input,
initial_std = 1 / math.sqrt(size))],
error_clipping_threshold = clipping_thd,
seq_reversed = False
)
recurrent.GatedRecurrentLayerGroup(
name = "annotation_backward",
size = latent_chain_dim * 3,
para_prefix="_annotation_backward",
active_type = "tanh",
gate_active_type = "sigmoid",
inputs = [FullMatrixProjection(input,
initial_std = 1 / math.sqrt(size))],
error_clipping_threshold = clipping_thd,
seq_reversed = True
)
Layer(
inputs = [Input("annotation_forward"), Input("annotation_backward")],
name = name,
active_type = "",
type = "concat"
)
if not simplified_model:
Layer(
name = "annotation_backward_last",
type = "seqfirstins",
active_type = "linear",
bias = False,
inputs = [Input("annotation_backward")]
)
MixedLayer(
name = "annotation_last_projected",
active_type = "tanh",
size = latent_chain_dim,
bias = False,
inputs = FullMatrixProjection("annotation_backward_last"),
)
return "annotation_last_projected"
return None
DataLayer(
name = "source_language_word",
size = source_language_dict_dim,
)
DataLayer(
name = "last_doctor_word",
size = source_language_dict_dim,
)
DataLayer(
name = "last_patient_word",
size = source_language_dict_dim,
)
if generating:
Inputs("source_language_word",
"last_doctor_word",
"last_patient_word",
"sent_id")
Outputs("predict_word")
Layer(
name = "sent_id",
type = "data",
size = 1, #info for printer
)
else:
Inputs("source_language_word",
"last_doctor_word",
"last_patient_word",
"target_language_word",
"target_language_next_word")
Outputs("output")
DataLayer(
name = "target_language_word",
size = target_language_dict_dim,
)
DataLayer(
name = "target_language_next_word",
size = target_language_dict_dim,
)
MixedLayer(
name = "target_embedding",
size = word_vec_dim,
active_type = "",
bias = False,
inputs = TableProjection("target_language_word",
initial_std = 1 / math.sqrt(word_vec_dim),
parameter_name = "_target_language_embedding",
sparse_update = False,)
)
#################################### encoder #######################################
MixedLayer(
name = "source_embedding",
size = word_vec_dim,
active_type = "",
bias = False,
inputs = TableProjection("source_language_word",
initial_std = 0.01,
parameter_name = "_source_language_embedding",
sparse_update = False,)
)
MixedLayer(
name = "last_doctor_embedding",
size = word_vec_dim,
active_type = "",
bias = False,
inputs = TableProjection("last_doctor_word",
initial_std = 0.01,
parameter_name = "_last_doctor_embedding",
sparse_update = False,)
)
MixedLayer(
name = "last_patient_embedding",
size = word_vec_dim,
active_type = "",
bias = False,
inputs = TableProjection("last_patient_word",
initial_std = 0.01,
parameter_name = "_last_patient_embedding",
sparse_update = False,)
)
ConcatenateLayer(
name = "word_caps_vector",
inputs = ["source_embedding",
"last_doctor_embedding",
"last_patient_embedding"]
)
encoder_name = "encoder"
encoder_input = "word_caps_vector"
decoder_init = gru_encoder(
name = encoder_name,
size = latent_chain_dim * 3,
input = encoder_input,
clipping_thd = clipping_thd,
simplified_model = False,
)
#################################### decoder #######################################
.............等等
dataprovider.py
def processData2(obj, file_name):
def split_key_content(text):
words = text.split() # d/p : w1 w2 ......
return words[0], words[2:]
def length_valid(words):
if obj.settings.generating: return True
return 0 < len(words) <= obj.settings.max_words
with open_file(file_name) as fdata:
for line_count, line in enumerate(fdata):
if obj.settings.generating:
dialog = line.rstrip('\n').split('\t')
src_ids = _get_ids(dialog[0].split(), obj.src_dict)
d_last_ids = _get_ids(dialog[1].split(), obj.src_dict)
p_last_ids = _get_ids(dialog[2].split(), obj.src_dict)
if not d_last_ids:
d_last_ids = '<non>'
if not p_last_ids:
p_last_ids = '<non>'
yield src_ids, d_last_ids, p_last_ids, [line_count]
else:
dialog = line.rstrip('\n').split('\t')
if len(dialog) < 4: continue
pwords = dialog[0].split() # patient
if not length_valid(pwords): continue
d_last_round = dialog[1].split() # doctor last round
if not d_last_round:
d_last_round = '<non>'
p_last_round = dialog[2].split() # patient last round
if not p_last_round:
p_last_round = '<non>'
dkey, dwords = split_key_content(dialog[3]) # doctor
if not length_valid(dwords): continue
#get slot ids
src_ids = _get_ids(pwords, obj.src_dict)
d_last_ids = _get_ids(d_last_round, obj.src_dict)
p_last_ids = _get_ids(p_last_round, obj.src_dict)
tgt_ids = [obj.tgt_dict.get(w, UNK_IDX) for w in dwords]
tgt_ids_next = tgt_ids + [obj.tgt_dict[END]]
tgt_ids = [obj.tgt_dict[START]] + tgt_ids
print src_ids, d_last_ids, p_last_ids, tgt_ids, tgt_ids_next
yield src_ids, d_last_ids, p_last_ids, tgt_ids, tgt_ids_next
@0YuanZhang0 麻烦给出来一些报错日志。特别是dataprovider里面那个print是不是确实print出来了。
单纯从这个错误来看,就是DataProvider给出来的数据和数据层的数量不一致。可能的原因是
- DataProvider里面的input_types/slots是不是写错了。
- DataProvider的文件是不是跑错了?
yield的数据打出之后 是5个list,如: [0, 10, 5, 35, 22, 69, 26, 7, 86, 48, 15, 11, 5, 313, 41, 1264, 141, 86, 7, 10, 5, 177, 8, 40, 22, 3838, 54, 26, 7, 86, 48, 15, 11, 5, 17, 936, 199, 355, 12, 86, 80, 7, 6, 54, 29, 45, 17, 684, 128, 7, 953, 40, 18555, 856, 704, 2380, 1] [0, 10, 5, 177, 8, 40, 22, 3838, 54, 26, 7, 86, 48, 15, 1] [0, 11, 5, 17, 936, 199, 355, 12, 86, 80, 7, 6, 54, 29, 45, 17, 684, 128, 7, 953, 40, 18555, 856, 704, 2380, 1] [0, 446, 114, 7, 15, 12, 2973, 64, 1938, 54, 15] [446, 114, 7, 15, 12, 2973, 64, 1938, 54, 15, 1]
DataProvider里面的input_types/slots是不是写错了。
麻烦check一下这个。
这个错误是因为定义的输出数据和实际的输入数据不匹配。具体一点是settings.input_types设置的输入个数和 data_layer的个数不匹配,希望对你能有一点帮助。
谢谢,问题已解决