如何对NCE参数(Parameter)如何做转置
Created by: qingqing01
可以采用如下方式:
w_param = fluid.layers.create_parameter(shape=[nid_dict_size, 31], dtype='float32', name='nce_w')
b_param = fluid.layers.create_parameter(shape=[nid_dict_size, 31], dtype='float32', name='nce_b')
if is_train:
nid_freq_arr = np.array(nid_freq).astype('float32')
cost = fluid.layers.nce(intput=fc, label=next_id, num_total_classes=nid_dict_size,
sample_weight=weight,
param_attr=fluid.ParamAttr(name='nce_w'),
param_attr=fluid.ParamAttr(name='nce_b'),
num_neg_samples=5)
else:
fc = fluid.layers.matmul(x=fc, y=w_param, tranpose_y=True)
fc_trans = fluid.layers.tranpose(fc, perm=[1,0]) + b_param
fc_trans = fluid.layers.tranpose(fc, perm=[1,0])
prediction = fluid.layers.softmax(fc_trans)
pred_topvalue, pred_topindices = fluid.layers.topk(prediction, k=100)