code: def get_context_representation_single_mention(
      sample,
      tokenizer,
      max_seq_length,
      mention_key="mention",
      context_key="context",
      ent_start_token=ENT_START_TAG,
      ent_end_token=ENT_END_TAG,
      add_mention_bounds=True,
  ):
      mention_tokens = []
      if sample[mention_key] and len(sample[mention_key]) > 0:
          mention_tokens = tokenizer.tokenize(sample[mention_key])
          to_subtract = 4 if add_mention_bounds else 2
          if len(mention_tokens) > max_seq_length - to_subtract:
              # -4 as 2 for ent_start and ent_end, 2 for [CLS] and [SEP]
              mention_tokens = mention_tokens[
                  : max_seq_length - to_subtract
              ]
          if add_mention_bounds:
              mention_tokens = (
                  [ent_start_token] + mention_tokens + [ent_end_token]
              )
  
      context_left = sample[context_key + "_left"]
      context_right = sample[context_key + "_right"]
      context_left = tokenizer.tokenize(context_left)
      context_right = tokenizer.tokenize(context_right)
  
      left_quota = (max_seq_length - len(mention_tokens)) // 2 - 1
      right_quota = (
          max_seq_length - len(mention_tokens) - left_quota - 2
      )
      left_add = len(context_left)
      right_add = len(context_right)
      if left_add <= left_quota:
          if right_add > right_quota:
              right_quota += left_quota - left_add
      else:
          if right_add <= right_quota:
              left_quota += right_quota - right_add
  
      if left_quota <= 0:
          context_left = []
      if right_quota <= 0:
          context_right = []
      context_tokens = (
          context_left[-left_quota:]
          + mention_tokens
          + context_right[:right_quota]
      )
  
      context_tokens = ["[CLS]"] + context_tokens + ["[SEP]"]
      mention_idxs = [
          len(context_left[-left_quota:]) + 1,
          len(context_left[-left_quota:]) + len(mention_tokens) + 1,
      ]
      input_ids = tokenizer.convert_tokens_to_ids(context_tokens)
      padding = [0] * (max_seq_length - len(input_ids))
      input_ids += padding
      assert len(input_ids) == max_seq_length
  
      return {
          "tokens": context_tokens,
          "ids": input_ids,
          "mention_idxs": mention_idxs,
      }
  
file_path: BLINK/elq/biencoder/data_process.py
imports: import os
  import json
  import logging
  import torch
  from tqdm import tqdm, trange
  from torch.utils.data import DataLoader, TensorDataset
  from pytorch_transformers.tokenization_bert import BertTokenizer
  from blink.biencoder.zeshel_utils import world_to_id
  from elq.common.params import ENT_START_TAG, ENT_END_TAG, ENT_TITLE_TAG
label_desc: Use image node_id 3 for calling a global function with example usage: get_context_representation_single_mention(sample, tokenizer, max_seq_length, mention_key, context_key, ent_start_token, ent_end_token, add_mention_bounds) and returns: dict