docstr: If gold_mention_bounds is set, returns mention embeddings of passed-in mention bounds
  Otherwise, uses top-scoring mentions
docstr_tok: ["If","gold_mention_bounds","is","set",",","returns","mention","embeddings","of","passed-in","mention","bounds","Otherwise",",","uses","top-scoring","mentions"]
code: def forward(
      self,
      token_idx_ctxt,
      segment_idx_ctxt,
      mask_ctxt,
      token_idx_cands,
      segment_idx_cands,
      mask_cands,
      gold_mention_bounds=None,
      gold_mention_bounds_mask=None,
      num_cand_mentions=50,
      topK_threshold=-4.5,
      get_mention_scores=True,
  ):
      """
      If gold_mention_bounds is set, returns mention embeddings of passed-in mention bounds
      Otherwise, uses top-scoring mentions
      """
      embedding_ctxt = (
          embedding_cands
      ) = (
          top_mention_mask
      ) = (
          top_mention_logits
      ) = (
          top_mention_bounds
      ) = (
          all_mention_mask
      ) = (
          all_mention_logits
      ) = all_mention_bounds = max_num_pred_mentions = None
  
      context_outs = None
      cand_outs = None
      if token_idx_ctxt is not None:
          context_outs = self.forward_ctxt(
              token_idx_ctxt,
              segment_idx_ctxt,
              mask_ctxt,
              gold_mention_bounds=gold_mention_bounds,
              gold_mention_bounds_mask=gold_mention_bounds_mask,
              num_cand_mentions=num_cand_mentions,
              topK_threshold=topK_threshold,
              get_mention_scores=get_mention_scores,
          )
      if token_idx_cands is not None:
          cand_outs = self.forward_candidate(
              token_idx_cands, segment_idx_cands, mask_cands
          )
      return context_outs, cand_outs
  
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 8 for calling the BiEncoderModule obj's underlying member method code with example usage: obj.forward(token_idx_ctxt, segment_idx_ctxt, mask_ctxt, token_idx_cands, segment_idx_cands, mask_cands, gold_mention_bounds, gold_mention_bounds_mask, num_cand_mentions, topK_threshold, get_mention_scores) and returns: context_outs,  cand_outs