多目标学习的时候出现out[j] > 0 && out[j] < 1.0错误
Created by: michael200892458
出错信息: I1111 17:21:29.127272 3751 TrainerInternal.cpp:162] Batch=20 samples=2464 AvgCost=0.0870727 CurrentCost=0.0870727 Eval: classification_error_evaluator=0.00745739 CurrentEval: classification_error_evaluator=0.00745739 I1111 17:21:29.127521 3751 TrainerInternal.cpp:179] Pass=7 Batch=20 samples=2464 AvgCost=0.0870727 Eval: classification_error_evaluator=0.00745739 I1111 17:21:29.190271 3751 Tester.cpp:111] Test samples=300 cost=0.455414 Eval: classification_error_evaluator=0.0183333 I1111 17:21:29.190448 3751 GradientMachine.cpp:112] Saving parameters to ./output/pass-00007 I1111 17:21:29.195664 3751 Util.cpp:213] copy trainer_config.py to ./output/pass-00007 ............F1111 17:21:30.308898 3754 Matrix.cpp:3483] Check failed: out[j] > 0 && out[j] < 1.0 *** Check failure stack trace: *** @ 0x7f25996666ed google::LogMessage::Fail() @ 0x7f259966ae50 google::LogMessage::SendToLog() @ 0x7f2599667217 google::LogMessage::Flush() @ 0x7f2599667476 google::LogMessageFatal::~LogMessageFatal() @ 0x783f0e paddle::CpuMatrix::multiBinaryLabelCrossEntropy() @ 0x64c735 paddle::CostLayer::forward() @ 0x5aa50e paddle::NeuralNetwork::forward() @ 0x59ed27 paddle::TrainerThread::forward() @ 0x5a0bac paddle::TrainerThread::computeThread() @ 0x7f25992e62f0 execute_native_thread_routine @ 0x3f0b90610a (unknown) @ 0x3f0b0c5ee3 (unknown)
trainer_config.py from paddle.trainer_config_helpers import *
dict_file = "./data/dict.txt" word_dict = dict() with open(dict_file, 'r') as f: for i, line in enumerate(f): w = line.strip().split()[0] word_dict[w] = i
trn = 'data/train.list' tst = 'data/test.list' process = 'process' define_py_data_sources2(train_list=trn, test_list=tst, module="dataprovider", obj=process, args={"dictionary": word_dict})
batch_size = 128 settings( batch_size=batch_size, learning_rate=2e-3, learning_method=AdamOptimizer(), regularization=L2Regularization(8e-4), gradient_clipping_threshold=25 )
data = data_layer(name="word", size=len(word_dict)) embedding = embedding_layer(input=data, size=128) conv = sequence_conv_pool(input=embedding, context_len=5, hidden_size=512) output = fc_layer(input=conv, size=8, act=SoftmaxActivation())
label = data_layer(name="label", size=8) cls = classification_cost(input=output, label=label, cost='multi_binary_label_cross_entropy') outputs(cls)
dataprovider.py from paddle.trainer.PyDataProvider2 import * UNK_IDX = 0
def initializer(settings, dictionary, **kwargs): settings.word_dict = dictionary settings.input_types = [ integer_value_sequence(len(dictionary)), sparse_binary_vector(8)]
@provider(init_hook=initializer, cache=CacheType.CACHE_PASS_IN_MEM) def process(settings, file_name): n = 0 with open(file_name, 'r') as f: for line in f: fields = line.strip().split('\t') if len(fields) < 5: continue ticketId = fields[0] labelStr = fields[3] labels = [] try: tokens = labelStr.split(',') for token in tokens: value = int(token) labels.append(value) except ValueError: continue
words = fields[2]
words = words.split(" ");
word_slot = [settings.word_dict.get(w, UNK_IDX) for w in words]
n += 1
if n <= 2:
print [word_slot, labels]
yield word_slot, labels
print "process end, n:%d" % n