code: def score_candidate(
      self,
      text_vecs,
      cand_vecs,
      random_negs=True,
      cand_encs=None,  # pre-computed candidate encoding.
  ):
      # Encode contexts first
      token_idx_ctxt, segment_idx_ctxt, mask_ctxt = to_bert_input(
          text_vecs, self.NULL_IDX
      )
      embedding_ctxt, _ = self.model(
          token_idx_ctxt, segment_idx_ctxt, mask_ctxt, None, None, None
      )
  
      # Candidate encoding is given, do not need to re-compute
      # Directly return the score of context encoding and candidate encoding
      if cand_encs is not None:
          return embedding_ctxt.mm(cand_encs.t())
  
      # Train time. We compare with all elements of the batch
      token_idx_cands, segment_idx_cands, mask_cands = to_bert_input(
          cand_vecs, self.NULL_IDX
      )
      _, embedding_cands = self.model(
          None,
          None,
          None,
          token_idx_cands,
          segment_idx_cands,
          mask_cands,
      )
      if random_negs:
          # train on random negatives
          return embedding_ctxt.mm(embedding_cands.t())
      else:
          # train on hard negatives
          embedding_ctxt = embedding_ctxt.unsqueeze(
              1
          )  # batchsize x 1 x embed_size
          embedding_cands = embedding_cands.unsqueeze(
              2
          )  # batchsize x embed_size x 2
          scores = torch.bmm(
              embedding_ctxt, embedding_cands
          )  # batchsize x 1 x 1
          scores = torch.squeeze(scores)
          return scores
  
imports: import os
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from tqdm import tqdm
  from pytorch_transformers.modeling_bert import BertPreTrainedModel, BertConfig, BertModel
  from pytorch_transformers.tokenization_bert import BertTokenizer
  from blink.common.ranker_base import BertEncoder, get_model_obj
  from blink.common.optimizer import get_bert_optimizer
label_desc: Use image node_id 8 for calling the BiEncoderRanker obj's underlying member method code with example usage: obj.score_candidate(text_vecs, cand_vecs, random_negs, cand_encs) and returns: embedding_ctxt, embedding_ctxt, scores