The layer to be stacked in decoder part. The structure of this module is similar to that in the encoder part except a multi-head attention is added to implement encoder-decoder attention.
(dec_input,
enc_output,
slf_attn_bias,
dec_enc_attn_bias,
n_head,
d_key,
d_value,
d_model,
d_inner_hid,
prepostprocess_dropout,
attention_dropout,
relu_dropout,
preprocess_cmd,
postprocess_cmd,
cache=None)
| 380 | |
| 381 | |
| 382 | def decoder_layer(dec_input, |
| 383 | enc_output, |
| 384 | slf_attn_bias, |
| 385 | dec_enc_attn_bias, |
| 386 | n_head, |
| 387 | d_key, |
| 388 | d_value, |
| 389 | d_model, |
| 390 | d_inner_hid, |
| 391 | prepostprocess_dropout, |
| 392 | attention_dropout, |
| 393 | relu_dropout, |
| 394 | preprocess_cmd, |
| 395 | postprocess_cmd, |
| 396 | cache=None): |
| 397 | """ The layer to be stacked in decoder part. |
| 398 | The structure of this module is similar to that in the encoder part except |
| 399 | a multi-head attention is added to implement encoder-decoder attention. |
| 400 | """ |
| 401 | slf_attn_output = multi_head_attention( |
| 402 | pre_process_layer(dec_input, preprocess_cmd, prepostprocess_dropout), |
| 403 | None, |
| 404 | None, |
| 405 | slf_attn_bias, |
| 406 | d_key, |
| 407 | d_value, |
| 408 | d_model, |
| 409 | n_head, |
| 410 | attention_dropout, |
| 411 | cache) |
| 412 | slf_attn_output = post_process_layer( |
| 413 | dec_input, |
| 414 | slf_attn_output, |
| 415 | postprocess_cmd, |
| 416 | prepostprocess_dropout, ) |
| 417 | enc_attn_output = multi_head_attention( |
| 418 | pre_process_layer(slf_attn_output, preprocess_cmd, |
| 419 | prepostprocess_dropout), |
| 420 | enc_output, |
| 421 | enc_output, |
| 422 | dec_enc_attn_bias, |
| 423 | d_key, |
| 424 | d_value, |
| 425 | d_model, |
| 426 | n_head, |
| 427 | attention_dropout, ) |
| 428 | enc_attn_output = post_process_layer( |
| 429 | slf_attn_output, |
| 430 | enc_attn_output, |
| 431 | postprocess_cmd, |
| 432 | prepostprocess_dropout, ) |
| 433 | ffd_output = positionwise_feed_forward( |
| 434 | pre_process_layer(enc_attn_output, preprocess_cmd, |
| 435 | prepostprocess_dropout), |
| 436 | d_inner_hid, |
| 437 | d_model, |
| 438 | relu_dropout, ) |
| 439 | dec_output = post_process_layer( |
no test coverage detected