docstr: mention_aggregation_type
      `all_avg`: average across tokens in mention
      `fl_avg`: to average across first/last tokens in mention
      `{all/fl}_linear`: for linear layer over mention
      `{all/fl}_mlp` to MLP over mention
docstr_tok: ["mention_aggregation_type","`","all_avg","`",":","average","across","tokens","in","mention","`","fl_avg","`",":","to","average","across","first\/last","tokens","in","mention","`","{","all\/fl","}","_linear","`",":","for","linear","layer","over","mention","`","{","all\/fl","}","_mlp","`","to","MLP","over","mention"]
code: def __init__(
      self,
      mention_aggregation_type,
      ctxt_output_dim,
      cand_output_dim,
      dropout=0.1,
  ):
      """
      mention_aggregation_type
          `all_avg`: average across tokens in mention
          `fl_avg`: to average across first/last tokens in mention
          `{all/fl}_linear`: for linear layer over mention
          `{all/fl}_mlp` to MLP over mention
      """
      super(GetContextEmbedsHead, self).__init__()
      # for aggregating mention outputs of context encoder
      self.mention_aggregation_type = mention_aggregation_type.split(
          "_"
      )
      self.tokens_to_aggregate = self.mention_aggregation_type[0]
      self.aggregate_method = "_".join(
          self.mention_aggregation_type[1:]
      )
      self.dropout = nn.Dropout(dropout)
      if (
          self.mention_aggregation_type == "all_avg"
          or self.mention_aggregation_type == "none"
      ):
          assert ctxt_output_dim == cand_output_dim
  
      if self.aggregate_method == "linear":
          self.mention_agg_linear = nn.Linear(
              ctxt_output_dim * 2, cand_output_dim
          )
      elif self.aggregate_method == "avg_linear":
          self.mention_agg_linear = nn.Linear(
              ctxt_output_dim, cand_output_dim
          )
      elif self.aggregate_method == "mlp":
          self.mention_agg_mlp = nn.Sequential(
              nn.Linear(bert_output_dim, bert_output_dim),
              nn.ReLU(),
              nn.Dropout(0.1),
              nn.Linear(bert_output_dim, output_dim),
          )
      else:
          self.mention_agg_mlp = None
  
imports: import os
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from tqdm import tqdm
  from collections import OrderedDict
  from pytorch_transformers.modeling_bert import BertPreTrainedModel, BertConfig, BertModel
  from pytorch_transformers.tokenization_bert import BertTokenizer
  from elq.common.ranker_base import BertEncoder, get_model_obj
  from blink.common.optimizer import get_bert_optimizer
  from elq.biencoder.allennlp_span_utils import batched_span_select, batched_index_select
  from elq.biencoder.utils import batch_reshape_mask_left
label_desc: Use image node_id 1 to create a new GetContextEmbedsHead object from inherited base classes: nn with example: obj = GetContextEmbedsHead(mention_aggregation_type, ctxt_output_dim, cand_output_dim, dropout)