class_docstr: Poly-encoder model.
  
  See https://arxiv.org/abs/1905.01969 for more details
class_docstr_tok: ["Poly-encoder","model",".","See","https",":","\/\/arxiv.org\/abs\/1905.01969","for","more","details"]
docstr: Apply attention.
  
  :param attention_layer:
      nn.Module attention layer to use for the attention
  :param queries:
      the queries for attention
  :param keys:
      the keys for attention
  :param values:
      the values for attention
  :param mask:
      mask for the attention keys
  
  :return:
      the result of applying attention to the values, with weights computed
      wrt to the queries and keys.
docstr_tok: ["Apply","attention",".",":","param","attention_layer",":","nn.Module","attention","layer","to","use","for","the","attention",":","param","queries",":","the","queries","for","attention",":","param","keys",":","the","keys","for","attention",":","param","values",":","the","values","for","attention",":","param","mask",":","mask","for","the","attention","keys",":","return",":","the","result","of","applying","attention","to","the","values",",","with","weights","computed","wrt","to","the","queries","and","keys","."]
code: def attend(self, attention_layer, queries, keys, values, mask):
      """
      Apply attention.
  
      :param attention_layer:
          nn.Module attention layer to use for the attention
      :param queries:
          the queries for attention
      :param keys:
          the keys for attention
      :param values:
          the values for attention
      :param mask:
          mask for the attention keys
  
      :return:
          the result of applying attention to the values, with weights computed
          wrt to the queries and keys.
      """
      if keys is None:
          keys = values
      if isinstance(attention_layer, PolyBasicAttention):
          return attention_layer(
              queries, keys, mask_ys=mask, values=values
          )
      elif isinstance(attention_layer, MultiHeadAttention):
          return attention_layer(queries, keys, values, mask)[0]
      else:
          raise Exception("Unrecognized type of attention")
  
imports: from parlai.core.params import ParlaiParser
  from typing import Any, Dict, Optional, Tuple
  import torch
  from parlai.core.opt import Opt
  from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.core.torch_agent import Batch
  from parlai.utils.misc import recursive_getattr
  from parlai.utils.logging import logging
  from .biencoder import AddLabelFixedCandsTRA
  from .modules import BasicAttention, MultiHeadAttention, TransformerEncoder
  from .transformer import TransformerRankerAgent
label_desc: Use image node_id 4 for calling the PolyEncoderModule obj's underlying member method code with example usage: obj.attend(attention_layer, queries, keys, values, mask) and returns: attention_layer, attention_layer