Paddle
Paddle copied to clipboard
跑deepFM模型里面的fm部分出现core
- 问题
跑deepFM模型(https://github.com/PaddlePaddle/models/tree/develop/deep_fm)里面的fm部分,有时候会成功,有时候会出现core,并且有时候是在任务启动的开始就直接core掉,有时候是在任务跑到最后的时候core掉了,做了不同batch_size和num_passes的实验,具体结果如下:
最后两行的实验,都是在运行到最后的时候core掉了,请问是什么原因呢?
-代码
reader如下
import os
import sys
import cPickle
feature_id_list = {2,18,30,37,38,39,40,43,44,47,48}
class Dataset:
def _reader_creator(self, dicts, path, is_infer):
def reader():
slot_feature_dict = dicts['slot_feature_dict']
files = os.listdir(path)
for fi in files:
with open(path+ '/' + fi, "r") as f:
UNK = '<unk>'
for line in f:
line_split = line.rstrip('\n').split('\t')
if len(line_split) < 60:
continue
label = [float(line_split[1])]
sparse_feature = []
for i in range(2, len(line_split)):
if i not in feature_id_list:
continue
slot_id = i-2
if line_split[i] == '':
continue
mini_seg_array = line_split[i].split('-')
count = 0
for mini_seg in mini_seg_array:
count = count + 1
#item_tag top6
if i == 30 or i == 48:
if count > 6:
continue
key = str(slot_id)+":"+mini_seg
if slot_feature_dict.has_key(key):
sparse_feature.append(slot_feature_dict.get(key))
else:
key = str(slot_id)+":"+UNK
if slot_feature_dict.has_key(key):
sparse_feature.append(slot_feature_dict.get(key))
else:
continue
if not is_infer:
yield [sparse_feature] + [label]
else:
yield [sparse_feature]
return reader
def train(self, dicts, path):
return self._reader_creator(dicts, path, False)
def test(self, dicts, path):
return self._reader_creator(dicts, path, False)
def infer(self, dicts, path):
return self._reader_creator(dicts, path, True)
if __name__ == "__main__":
dict_path = sys.argv[1]
train_path = sys.argv[2]
slot_feature_dict_path = dict_path + "/" + "slot_feature_dict.pkl"
with open(slot_feature_dict_path) as f:
slot_feature_dict = cPickle.load(f)
dicts = dict()
dicts['slot_feature_dict'] = slot_feature_dict
dataset = Dataset()
for dat in dataset.train(dicts, train_path)():
print dat
feeding = {
'sparse_input': 0,
'label': 1
}
network如下
import paddle.v2 as paddle
def fm_layer(input, factor_size, fm_param_attr):
first_order = paddle.layer.fc(
input=input, size=1, act=paddle.activation.Linear())
second_order = paddle.layer.factorization_machine(
input=input,
factor_size=factor_size,
act=paddle.activation.Linear(),
param_attr=fm_param_attr)
out = paddle.layer.addto(
input=[first_order, second_order],
act=paddle.activation.Linear(),
bias_attr=False)
return out
def DeepFM(factor_size, sparse_feature_dim, infer=False):
sparse_input = paddle.layer.data(
name="sparse_input",
type=paddle.data_type.sparse_binary_vector(sparse_feature_dim))
sparse_fm = fm_layer(
sparse_input,
factor_size,
fm_param_attr=paddle.attr.Param(name="SparseFeatFactors"))
predict = paddle.layer.fc(
input=sparse_fm,
size=1,
act=paddle.activation.Sigmoid())
if not infer:
label = paddle.layer.data(
name="label", type=paddle.data_type.dense_vector(1))
cost = paddle.layer.multi_binary_label_cross_entropy_cost(
input=predict, label=label)
paddle.evaluator.classification_error(
name="classification_error", input=predict, label=label)
paddle.evaluator.auc(name="auc", input=predict, label=label)
return cost
else:
return predict
网络配置没有问题,可能是和这个issue一样的问题,建议删掉系统之前安装的openblas,然后重新安装最新的paddle