ファクタリング機械の分野知覚深い理解

Benpianコード郭FFMの詳細な分析

図計算TensorFlow

図着信データを算出します

self.label = tf.placeholder(shape=(None), dtype=tf.float32)
self.features=tf.placeholder(shape=(None,hparams.feature_nums), dtype=tf.int32)

図パラメータ算出

self.emb_v1=tf.get_variable(shape=[hparams.hash_ids,1],
                                    initializer=initializer,name='emb_v1')
self.emb_v2=tf.get_variable(shape=[hparams.hash_ids,hparams.feature_nums,hparams.k],
                                    initializer=initializer,name='emb_v2') # fm中是二维的,这里是三维的

計算グラフの構築

# models/ffm.py build_graph()
#lr
emb_inp_v1=tf.gather(self.emb_v1, self.features) # shape = [batch_size, attr_nums, 1]
        w1=tf.reduce_sum(emb_inp_v1,[-1,-2])
        
# 交叉项
# self.features shape = [batch_size, attr_nums]
emb_inp_v2=tf.gather(self.emb_v2, self.features) # shape = [batch_size, attr_nums, attr_nums, k] # 每个attr从属于一个场
emb_inp_v2=tf.reduce_sum(emb_inp_v2*tf.transpose(emb_inp_v2,[0,2,1,3]),-1) # shape=[batch_size, attr_nums, attr_nums]
temp=[]
for i in range(hparams.feature_nums):
    if i!=0:
        temp.append(emb_inp_v2[:,i,:i]) # 取下三角
w2=tf.reduce_sum(tf.concat(temp,-1),-1) # 所有下三角的元素concat成一个列表

おすすめ

転載: www.cnblogs.com/ZeroTensor/p/11307187.html