code: def _convert_to_tensors(
      self, data: Any, in_context_samples: List[Any] = []
  ):
      answer_placeholders = []
  
      def _put_placeholder(data: Any, path: List[str] = []):
          if isinstance(data, dict):
              ret = {}
              for k, v in data.items():
                  ret[k] = _put_placeholder(v, path + [k])
              return ret
          else:
              answer_placeholders.append(path)
              return "<ans_{}>".format(len(answer_placeholders))
  
      data["<ans>"] = _put_placeholder(data["<ans>"])
      (
          input_ids,
          input_id_subs,
          context,
          segment_ids,
          segment_rel,
          n_segments,
          table_states,
      ) = convert_data_to_id(
          self.tokenizer, data, shuffle_answer=False, max_depth=8
      )
  
      sub_ans_map: Dict[int, int] = {}
      for fake_id, token_sub in table_states["token_id_table"][
          "<ans>"
      ].items():
          token = table_states["ext_table"][fake_id]
          if token.startswith("<ans_") and token.endswith(">"):
              ans_id = int(token[5:-1])
              sub_ans_map[token_sub] = ans_id
  
      tmp_input_ids = []
      tmp_input_sub = []
      tmp_input_seg = []
  
      predict_segments: List[Tuple[int, int]] = []
      for i in range(input_ids.shape[0]):
          if context[i] == 0:
              if input_ids[i] == self.tokenizer.encoder["<ans>"]:
                  # is ans
                  # (segment_id, ans_id)
                  predict_segments.append(
                      (segment_ids[i], sub_ans_map[input_id_subs[i]])
                  )
          else:
              tmp_input_ids.append(input_ids[i])
              tmp_input_sub.append(input_id_subs[i])
              tmp_input_seg.append(segment_ids[i])
  
      if len(predict_segments) == 0:
          raise ValueError("No answer to predict")
  
      input_ids = np.array(tmp_input_ids, dtype=np.int32)
      input_id_subs = np.array(tmp_input_sub, dtype=np.int32)
      context = np.full_like(tmp_input_ids, 1, dtype=np.int8)
      segment_ids = np.array(tmp_input_seg, dtype=np.int32)
      sample_ids = np.zeros(input_ids.shape, dtype=np.int32)
      segment_rel_offset = np.zeros(input_ids.shape, dtype=np.int32)
      num_segments = np.full(
          input_ids.shape, n_segments, dtype=np.int32
      )
  
      for i, sample in enumerate(in_context_samples):
          (
              sample_input_ids,
              sample_id_subs,
              _,
              sample_segments,
              sample_rel,
              n_segments,
              table_states,
          ) = convert_data_to_id(
              self.tokenizer, sample, table_states, max_depth=8
          )
          input_ids = np.concatenate(
              [input_ids, sample_input_ids], axis=0
          )
          input_id_subs = np.concatenate(
              [input_id_subs, sample_id_subs], axis=0
          )
          context = np.concatenate(
              [context, np.ones(sample_input_ids.shape, dtype=np.int8)],
              axis=0,
          )
          segment_ids = np.concatenate(
              [segment_ids, sample_segments], axis=0
          )
          segment_rel_offset = np.concatenate(
              [
                  segment_rel_offset,
                  np.full(
                      sample_input_ids.shape,
                      segment_rel.shape[0],
                      dtype=np.int32,
                  ),
              ],
              axis=0,
          )
          segment_rel = np.concatenate(
              [segment_rel, sample_rel], axis=0
          )
          sample_ids = np.concatenate(
              [
                  sample_ids,
                  np.full(
                      sample_input_ids.shape, i + 1, dtype=np.int32
                  ),
              ],
              axis=0,
          )
          num_segments = np.concatenate(
              [
                  num_segments,
                  np.full(
                      sample_input_ids.shape, n_segments, dtype=np.int32
                  ),
              ],
              axis=0,
          )
      input_pos = np.arange(input_ids.shape[0], dtype=np.int32)
  
      return (
          input_ids,
          input_id_subs,
          input_pos,
          context,
          segment_ids,
          segment_rel_offset,
          segment_rel,
          sample_ids,
          num_segments,
          predict_segments,
          answer_placeholders,
          table_states["ext_table"],
          table_states["token_id_table"],
      )
  
file_path: DeepKE/example/llm/CPM-Bee/src/cpm_live/generation/bee.py
imports: from typing import Any, Dict, List, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from .generation_utils import BeamHypotheses, apply_repetition_penalty
  from ..tokenizers.bee import CPMBeeTokenizer
  from ..models.bee import CPMBee
  from ..training_tasks.bee.pretrain import convert_data_to_id
  from ..utils import pad
label_desc: Use image node_id 2 for calling the CPMBeeGeneration obj's underlying member method code with example usage: obj._convert_to_tensors(data, in_context_samples) and returns: input_ids,  input_id_subs,  input_pos,  context,  segment_ids,  segment_rel_offset,  segment_rel,  sample_ids,  num_segments,  predict_segments,  answer_placeholders,  table_states,  table_states, ret, str