Hi jack_ma,
I would advise you to read carefully the paper Attention is all you Need: https://arxiv.org/abs/1706.03762 1 if you want to build your own attention module from scratch.
Basically, the multi head attention takes as inputs queries, keys and values that are mapped from a sequence of embeddings (of words for instance). The keys are conveying information about the nature of the embeddings, the values encode the content itself while the queries indicate the information the embeddings need (https://arxiv.org/abs/1911.07757 1). I hope this provides some intuition about the triplet query - key - value and on how the attention module can learn which embeddings in the sequence to focus on.