what is the kind of max pooling in this nlp questionhierarchy description

牧云@^-^@ 提交于 2019-12-12 19:11:53

问题


I'm trying to implement this description and that what I did I generated uni_gram & bi_gram & tri_gram of shape(?,15,512) "using padding " & then for each word I concatenate the three feature vector (?,3,512) and then I apply to them Globalmaxpooling1D I do not know if I implemented it well or not so can any one help me ?

Q = Input(shape=(15,))
V = Input(shape=(512,196))

word_level = Embedding ( vocab_size , 512 , input_length=max_length)(Q)

uni_gram = Conv1D( 512 , kernel_size = 1 , activation='tanh' , 
padding='same' )(word_level)
bi_gram  = Conv1D( 512 , kernel_size = 2 , activation='tanh' , 
padding='same' )(word_level)
tri_gram = Conv1D( 512 , kernel_size = 3 , activation='tanh' , 
padding='same' )(word_level)

phrases = []

for w in range(0,max_length):

Uni =uni_gram [:,w,:]
Uni= tf.reshape(Uni , [-1,1,512 ])

Bi = bi_gram [:,w,:]
Bi = tf.reshape(Bi , [-1,1,512 ])

Tri= tri_gram [:,w,:]
Tri = tf.reshape( Tri , [-1,1,512 ])

Uni_Bi_Tri  =  Concatenate(axis=1)([ Uni, Bi , Tri ])
Best_phrase = GlobalMaxPooling1D()(Uni_Bi_Tri)
Best_phrase = tf.reshape( Best_phrase , [-1,1,512 ])
phrases.append(Best_phrase)

来源:https://stackoverflow.com/questions/49371157/what-is-the-kind-of-max-pooling-in-this-nlp-questionhierarchy-description

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!