:param enc_input: (batch_size, n_blocks, emb_dim) :param attn_bias: (batch_size, n_head, n_blocks, n_blocks) :param graph_attn_bias: (batch_size, n_head, n_blocks, n_blocks)
(enc_input, # (batch_size, n_block, emb_dim)
attn_bias, # (batch_size, n_head, n_block, n_block)
graph_attn_bias, # (batch_size, n_head, n_block, n_block)
pos_win,
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='')
| 191 | |
| 192 | |
| 193 | def graph_encoder_layer(enc_input, # (batch_size, n_block, emb_dim) |
| 194 | attn_bias, # (batch_size, n_head, n_block, n_block) |
| 195 | graph_attn_bias, # (batch_size, n_head, n_block, n_block) |
| 196 | pos_win, |
| 197 | n_head, |
| 198 | d_key, |
| 199 | d_value, |
| 200 | d_model, |
| 201 | d_inner_hid, |
| 202 | prepostprocess_dropout, |
| 203 | attention_dropout, |
| 204 | relu_dropout, |
| 205 | hidden_act, |
| 206 | preprocess_cmd="n", |
| 207 | postprocess_cmd="da", |
| 208 | param_initializer=None, |
| 209 | name=''): |
| 210 | """ |
| 211 | :param enc_input: (batch_size, n_blocks, emb_dim) |
| 212 | :param attn_bias: (batch_size, n_head, n_blocks, n_blocks) |
| 213 | :param graph_attn_bias: (batch_size, n_head, n_blocks, n_blocks) |
| 214 | """ |
| 215 | # (batch_size, n_block, d_model) |
| 216 | attn_output = multi_head_structure_attention( |
| 217 | queries=pre_process_layer(out=enc_input, # add layer normalization |
| 218 | process_cmd=preprocess_cmd, |
| 219 | dropout_rate=prepostprocess_dropout, |
| 220 | name=name + '_pre_attn'), |
| 221 | keys=None, |
| 222 | values=None, |
| 223 | attn_bias=attn_bias, |
| 224 | graph_attn_bias=graph_attn_bias, |
| 225 | pos_win=pos_win, |
| 226 | d_key=d_key, |
| 227 | d_value=d_value, |
| 228 | d_model=d_model, |
| 229 | n_head=n_head, |
| 230 | dropout_rate=attention_dropout, |
| 231 | name=name + '_graph_attn' |
| 232 | ) |
| 233 | |
| 234 | # add dropout and residual connection |
| 235 | attn_output = post_process_layer(prev_out=enc_input, |
| 236 | out=attn_output, |
| 237 | process_cmd=postprocess_cmd, |
| 238 | dropout_rate=prepostprocess_dropout, |
| 239 | name=name + '_post_attn') |
| 240 | |
| 241 | ffd_output = positionwise_feed_forward( |
| 242 | x=pre_process_layer(out=attn_output, # add layer normalization |
| 243 | process_cmd=preprocess_cmd, |
| 244 | dropout_rate=prepostprocess_dropout, |
| 245 | name=name + '_pre_ffn'), |
| 246 | d_inner_hid=d_inner_hid, |
| 247 | d_hid=d_model, |
| 248 | dropout_rate=relu_dropout, |
| 249 | hidden_act=hidden_act, |
| 250 | param_initializer=param_initializer, |
no test coverage detected