v2版本使用factorization_machine出错
Created by: zyz282994112
数据输入为sparse_binary_vector时,代码可以正常运行,将多个sparse_binary_vector concat后,运行时会出“F1122 11:02:32.585233 6142 BaseMatrix.cu:91] Check failed: !b.isSparse() Sparse Matrix/Vector is not supported.F1122 11:02:32.591529 6143 BaseMatrix.cu:91] Check failed: !b.isSparse() Sparse Matrix/Vector is not supported.F1122 11:02:32.596053 6144 BaseMatrix.cu:91] Check failed: !b.isSparse() Sparse Matrix/Vector is not supported.”错误。出错代码片段如下:
def fm_layer(self, input_data, factor_size, fm_param_attr):
first_order = paddle.layer.fc(input=input_data,
size=1,
act=paddle.activation.Linear())
second_order = paddle.layer.factorization_machine(
input=input_data,
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 network(self, is_predict=False):
word_dict_size = self._word_dict_size
vocab_dict_size = self._vocab_dict_size
hidden_size = self._hidden_size
########################
reset_parser()
month = paddle.layer.data(name="month", type=paddle.data_type.sparse_binary_vector(12))
year = paddle.layer.data(name="year", type=paddle.data_type.sparse_binary_vector(2))
vocab = paddle.layer.data(name="vocab", type=paddle.data_type.sparse_binary_vector(vocab_dict_size))
comb_layer = paddle.layer.concat(input=[vocab, month, year])
vocab_layer = self.fm_layer(comb_layer, 16, fm_param_attr=paddle.attr.Param(name="VocabFactors"))
feature_concat_layer = paddle.layer.concat(input=[lstm_max_query, lstm_max_query_time, time_layer, vocab_layer])
feature_concat_layer = paddle.layer.batch_norm(input=feature_concat_layer, act=paddle.activation.Relu())
weight = paddle.layer.data(name="weight", type=paddle.data_type.dense_vector(1))
label = paddle.layer.data(name="label", type=paddle.data_type.integer_value(2))
cost = paddle.layer.classification_cost(input=output, label=label, weight=weight)
return cost