import torch


def DotScorer(dec_out, enc_outs, **kwargs):
    """
    Score for query decoder state and the ith encoder state is given
    by their dot product.

    dec_outs: (trg_seq_len x batch x hid_dim)
    enc_outs: (src_seq_len x batch x hid_dim)

    output: ((trg_seq_len x) batch x src_seq_len)
    """
    score = torch.bmm(
        # (batch x src_seq_len x hid_dim)
        enc_outs.transpose(0, 1),
        # (batch x hid_dim x trg_seq_len)
        dec_out.transpose(0, 1).transpose(1, 2))
    # (batch x src_seq_len x trg_seq_len) => (trg_seq_len x batch x src_seq_len)
    return score.transpose(0, 1).transpose(0, 2)