MCPcopy
hub / github.com/GauravBh1010tt/DeepLearn / bcnn

Function bcnn

Attention_Based_CNN (ABCNN)/model_abcnn.py:144–223  ·  view source on GitHub ↗
(embedding_matrix, dimx=50, dimy=50, nb_filter = 120, embedding_dim = 50, 
                      filter_length = (50,4), depth = 1, shared = 0,
                      opt_params = [0.0008,'adam'])

Source from the content-addressed store, hash-verified

142
143
144def bcnn(embedding_matrix, dimx=50, dimy=50, nb_filter = 120, embedding_dim = 50,
145 filter_length = (50,4), depth = 1, shared = 0,
146 opt_params = [0.0008,'adam']):
147
148#if True:
149 print 'Model Uses BCNN......'
150
151 inpx = Input(shape=(dimx,),dtype='int32',name='inpx')
152 inpy = Input(shape=(dimy,),dtype='int32',name='inpy')
153
154 x = word2vec_embedding_layer(embedding_matrix,train=False)(inpx)
155 y = word2vec_embedding_layer(embedding_matrix,train=False)(inpy)
156
157 x = Permute((2,1))(x)
158 y = Permute((2,1))(y)
159
160 conv1 = Reshape((embedding_dim,dimx,1))(x)
161 conv2 = Reshape((embedding_dim,dimy,1))(y)
162
163 channel_1, channel_2 = [], []
164
165 for dep in range(depth):
166
167 #filter_width = filter_widths[dep]
168
169 #conv1 = ZeroPadding2D((filter_width - 1, 0))(conv1)
170 #conv2 = ZeroPadding2D((filter_width - 1, 0))(conv2)
171
172 if shared:
173 conv = Conv2D(nb_filter=nb_filter, kernel_size = filter_length, activation='relu',
174 data_format = 'channels_last',border_mode="valid")
175 ques = conv(conv1)
176 ans = conv(conv2)
177
178 else:
179 ques = Conv2D(nb_filter=nb_filter, kernel_size = filter_length, activation='relu',
180 data_format = 'channels_last',border_mode="valid")(conv1)
181 ans = Conv2D(nb_filter, kernel_size = filter_length, activation='relu',
182 data_format="channels_last",border_mode="valid")(conv2)
183
184
185 ques = Dropout(0.5)(ques)
186 ans = Dropout(0.5)(ans)
187 channel_1.append(GlobalMaxPooling2D()(ques))
188 channel_2.append(GlobalMaxPooling2D()(ans))
189
190 #channel_1.append(Reshape((ques._keras_shape[2]*ans._keras_shape[3]))(AveragePooling2D(4))(ques))
191 #channel_2.appendFlatten()((AveragePooling2D(4))(ans))
192
193
194 #reg1 = reg2 = 0.00002
195
196 h1 = channel_1.pop(-1)
197 if channel_1:
198 h1 = merge([h1] + channel_1, mode="concat")
199
200 h2 = channel_2.pop(-1)
201 if channel_2:

Callers

nothing calls this directly

Calls 1

word2vec_embedding_layerFunction · 0.90

Tested by

no test coverage detected