Tensorflow:如何从3暗到2暗线性投影?

时间:2018-08-01 16:04:05

标签: python tensorflow machine-learning keras deep-learning

我正在构建一个模型,其中有很多输入和很多嵌入,因此输入在查找后为2暗,它将变为3暗,然后我将所有输入连接起来,从那里我想要一个线性投影,但要有密集层在这种情况下不起作用:

例如,为了简单起见,我采用3个昏暗的输入,但在实际输入中为2个昏暗的输入,并且在嵌入查找后,它们为3个昏暗的输入:

输入为[批次x时间步长x暗淡]

import tensorflow as tf 
import numpy as np
a= np.random.randint(0,10,[2,3,4])
b= np.random.randint(0,10,[2,3,4])
c= np.random.randint(0,10,[2,3,4])
d= np.random.randint(0,10,[2,3,4]) 

input_a = tf.placeholder(name='a',shape=[2,3,4],dtype=tf.float32)
input_b = tf.placeholder(name='b',shape=[2,3,4],dtype=tf.float32)
input_c = tf.placeholder(name='c',shape=[2,3,4],dtype=tf.float32)
input_d = tf.placeholder(name='d',shape=[2,3,4],dtype=tf.float32)

#actual output is from embedding then concat

concat = tf.concat([input_a,input_b,input_c,input_d],1)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(concat,feed_dict={input_a:a,input_b:b,input_c:c,input_d:d}).shape)


#now from here do linear projection 2x12x4 to 2x100 and then 100x2 so i will get output 2x2 

所以有4个形状为2x3x4的输入,将它们连接起来后,我得到(2,12,4)现在,我想在其中添加投影和一个像这样的隐藏层

2x12x4 ===> dense(2x100) ==> hidden_layer (100x2) ===> 2x2 output 

我可以重塑以下内容:

2x12x4 ==> transpose ( 12x2x4) ==> take last time step ( 2x4 ) ==> 4x100 ==>100x2 ==> 2x2 

但是在这里我正在丢失信息,因为我只采取最后一步,如何在不丢失信息的情况下投影到2d暗淡?

谢谢

0 个答案:

没有答案