:param enc_words_output: # (batch_size*n_blocks, n_tokens, emb_dim) :param src_words_slf_attn_bias: (batch_size*n_block, n_head, n_tokens, n_tokens) :param src_sents_slf_attn_bias: (batch_size, n_head, n_block, n_block) :param graph_attn_bias: (batch_size, n_head, n_block, n_blo
(enc_words_output,
src_words_slf_attn_bias,
src_sents_slf_attn_bias,
graph_attn_bias,
pos_win,
graph_layers,
n_head,
d_key,
d_value,
d_model,
d_inner_hid,
prepostprocess_dropout,
attention_dropout,
relu_dropout,
hidden_act,
preprocess_cmd="n",
postprocess_cmd="da",
param_initializer=None,
name='graph_encoder')
| 258 | |
| 259 | |
| 260 | def graph_encoder(enc_words_output, |
| 261 | src_words_slf_attn_bias, |
| 262 | src_sents_slf_attn_bias, |
| 263 | graph_attn_bias, |
| 264 | pos_win, |
| 265 | graph_layers, |
| 266 | n_head, |
| 267 | d_key, |
| 268 | d_value, |
| 269 | d_model, |
| 270 | d_inner_hid, |
| 271 | prepostprocess_dropout, |
| 272 | attention_dropout, |
| 273 | relu_dropout, |
| 274 | hidden_act, |
| 275 | preprocess_cmd="n", |
| 276 | postprocess_cmd="da", |
| 277 | param_initializer=None, |
| 278 | name='graph_encoder'): |
| 279 | """ |
| 280 | :param enc_words_output: # (batch_size*n_blocks, n_tokens, emb_dim) |
| 281 | :param src_words_slf_attn_bias: (batch_size*n_block, n_head, n_tokens, n_tokens) |
| 282 | :param src_sents_slf_attn_bias: (batch_size, n_head, n_block, n_block) |
| 283 | :param graph_attn_bias: (batch_size, n_head, n_block, n_block) |
| 284 | :return: |
| 285 | """ |
| 286 | # (batch_size, n_block, d_model) |
| 287 | sents_vec = self_attention_pooling_layer(enc_input=enc_words_output, |
| 288 | attn_bias=src_words_slf_attn_bias, |
| 289 | n_head=n_head, |
| 290 | d_key=d_key, |
| 291 | d_value=d_value, |
| 292 | d_model=d_model, |
| 293 | d_inner_hid=d_inner_hid, |
| 294 | prepostprocess_dropout=prepostprocess_dropout, |
| 295 | attention_dropout=attention_dropout, |
| 296 | relu_dropout=relu_dropout, |
| 297 | n_block=src_sents_slf_attn_bias.shape[2], |
| 298 | preprocess_cmd="n", |
| 299 | postprocess_cmd="da", |
| 300 | name=name + '_pooling') |
| 301 | |
| 302 | enc_input = sents_vec # (batch_size, n_block, d_model) |
| 303 | |
| 304 | for i in range(graph_layers): |
| 305 | # (batch_size, n_block, emb_dim) |
| 306 | enc_output = graph_encoder_layer( |
| 307 | enc_input=enc_input, # (batch_size, n_block, emb_dim) |
| 308 | attn_bias=src_sents_slf_attn_bias, # (batch_size, n_head, n_block, n_block) |
| 309 | graph_attn_bias=graph_attn_bias, # (batch_size, n_head, n_block, n_block) |
| 310 | pos_win=pos_win, |
| 311 | n_head=n_head, |
| 312 | d_key=d_key, |
| 313 | d_value=d_value, |
| 314 | d_model=d_model, |
| 315 | d_inner_hid=d_inner_hid, |
| 316 | prepostprocess_dropout=prepostprocess_dropout, |
| 317 | attention_dropout=attention_dropout, |
no test coverage detected