class_docstr: Implements simple/classical attention.
class_docstr_tok: ["Implements","simple\/classical","attention","."]
code: def __init__(
      self,
      dim: int = 1,
      attn: str = "cosine",
      residual: bool = False,
      get_weights: bool = True,
  ):
      super().__init__()
      if attn == "cosine":
          self.cosine = nn.CosineSimilarity(dim=dim)
      self.attn = attn
      self.dim = dim
      self.get_weights = get_weights
      self.residual = residual
  
file_path: ParlAI/parlai/agents/transformer/modules/attention.py
imports: import math
  from typing import Dict, Tuple, Optional, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from parlai.core.opt import Opt
  from parlai.core.params import default
  from parlai.utils.torch import neginf
label_desc: Use image node_id 1 to create a new BasicAttention object from inherited base classes: nn with example: obj = BasicAttention(dim, attn, residual, get_weights)