class_docstr: 数据处理函数
class_docstr_tok: ["\u6570\u636e\u5904\u7406\u51fd\u6570"]
code: def __init__(self, data_path, tokenizer, max_len, max_src_len):
      # prompt_text = "你现在是一个信息抽取模型，请你帮我抽取出关系内容为\"性能故障\", \"部件故障\", \"组成\"和 \"检测工具\"的相关三元组，三元组内部用\"_\"连接，三元组之间用\\n分割。文本："
  
      max_tgt_len = max_len - max_src_len - 3
      self.all_data = []
      with open(data_path, "r", encoding="utf-8") as fh:
          for i, line in enumerate(fh):
              sample = json.loads(line.strip())
              src_tokens = tokenizer.tokenize(sample["input"])
              prompt_tokens = tokenizer.tokenize(sample["instruction"])
  
              if len(src_tokens) > max_src_len - len(prompt_tokens):
                  src_tokens = src_tokens[
                      : max_src_len - len(prompt_tokens)
                  ]
  
              tgt_tokens = tokenizer.tokenize(sample["output"])
              if len(tgt_tokens) > max_tgt_len:
                  tgt_tokens = tgt_tokens[:max_tgt_len]
              tokens = (
                  prompt_tokens
                  + src_tokens
                  + ["[gMASK]", "<sop>"]
                  + tgt_tokens
                  + ["<eop>"]
              )
              input_ids = tokenizer.convert_tokens_to_ids(tokens)
              context_length = input_ids.index(tokenizer.bos_token_id)
              mask_position = context_length - 1
              labels = [-100] * context_length + input_ids[
                  mask_position + 1 :
              ]
  
              pad_len = max_len - len(input_ids)
              input_ids = input_ids + [tokenizer.pad_token_id] * pad_len
              labels = labels + [-100] * pad_len
  
              self.all_data.append(
                  {
                      "text": sample["input"],
                      "answer": sample["output"],
                      "input_ids": input_ids,
                      "labels": labels,
                  }
              )
  
file_path: DeepKE/example/llm/InstructKGC/src/finetuning_pt.py
imports: import argparse
  import os
  from shutil import copy
  import json
  import torch
  from torch.nn.utils.rnn import pad_sequence
  from torch.utils.data import Dataset, RandomSampler, DataLoader
  import deepspeed
  from transformers import AutoConfig, AutoTokenizer, AutoModel
label_desc: Use image node_id 1 to create a new Seq2SeqDataSet object from inherited base classes: Dataset with example: obj = Seq2SeqDataSet(data_path, tokenizer, max_len, max_src_len)