docstr: load conll ner from file
  
  Args:
      mode (str, optional): train/test/dev. Defaults to 'train'.
  Return:
      outputs (dict)
      raw_words: ['EU', 'rejects', 'German', 'call', 'to', 'boycott', 'British', 'lamb', '.']
      raw_targets: ['B-ORG', 'O', 'B-MISC', 'O', 'O', 'O', 'B-MISC', 'O', 'O']
      entities: [['EU'], ['German'], ['British']]
      entity_tags: ['org', 'misc', 'misc']
      entity_spans: [[0, 1], [2, 3], [6, 7]]
docstr_tok: ["load","conll","ner","from","file","Args",":","mode","(","str",",","optional",")",":","train\/test\/dev",".","Defaults","to","'train","'",".","Return",":","outputs","(","dict",")","raw_words",":","[","'EU","'",",","'rejects","'",",","'German","'",",","'call","'",",","'to","'",",","'boycott","'",",","'British","'",",","'lamb","'",",","'",".","'","]","raw_targets",":","[","'","B-ORG","'",",","'","O","'",",","'","B-MISC","'",",","'","O","'",",","'","O","'",",","'","O","'",",","'","B-MISC","'",",","'","O","'",",","'","O","'","]","entities",":","[","[","'EU","'","]",",","[","'German","'","]",",","[","'British","'","]","]","entity_tags",":","[","'org","'",",","'misc","'",",","'misc","'","]","entity_spans",":","[","[","0",",","1","]",",","[","2",",","3","]",",","[","6",",","7","]","]"]
code: def load_from_file(self, mode="train"):
      """load conll ner from file
  
      Args:
          mode (str, optional): train/test/dev. Defaults to 'train'.
      Return:
          outputs (dict)
          raw_words: ['EU', 'rejects', 'German', 'call', 'to', 'boycott', 'British', 'lamb', '.']
          raw_targets: ['B-ORG', 'O', 'B-MISC', 'O', 'O', 'O', 'B-MISC', 'O', 'O']
          entities: [['EU'], ['German'], ['British']]
          entity_tags: ['org', 'misc', 'misc']
          entity_spans: [[0, 1], [2, 3], [6, 7]]
      """
      load_file = self.data_path[mode]
      logger.info("Loading data from {}".format(load_file))
  
      # extract bio
      split_c = "\t" if "conll" in load_file else " "
      outputs = {
          "raw_words": [],
          "raw_targets": [],
          "entities": [],
          "entity_tags": [],
          "entity_spans": [],
      }
      with open(load_file, "r", encoding="utf-8") as f:
          lines = f.readlines()
          raw_words, raw_targets = [], []
          raw_word, raw_target = [], []
          for line in lines:
              if line != "\n":
                  raw_word.append(line.split(split_c)[0])
                  raw_target.append(line.split(split_c)[1][:-1])
              else:
                  raw_words.append(raw_word)
                  raw_targets.append(raw_target)
                  raw_word, raw_target = [], []
  
      for words, targets in zip(raw_words, raw_targets):
          entities, entity_tags, entity_spans = [], [], []
          start, end, start_flag = 0, 0, False
          for idx, tag in enumerate(targets):
              if tag.startswith("B-"):  # 一个实体开头 另一个实体（I-）结束
                  end = idx
                  if start_flag:  # 另一个实体以I-结束，紧接着当前实体B-出现
                      entities.append(words[start:end])
                      entity_tags.append(targets[start][2:].lower())
                      entity_spans.append([start, end])
                      start_flag = False
                  start = idx
                  start_flag = True
              elif tag.startswith("I-"):  # 实体中间，不是开头也不是结束，end+1即可
                  end = idx
              elif tag.startswith("O"):  # 无实体，可能是上一个实体的结束
                  end = idx
                  if start_flag:  # 上一个实体结束
                      entities.append(words[start:end])
                      entity_tags.append(targets[start][2:].lower())
                      entity_spans.append([start, end])
                      start_flag = False
          if start_flag:  # 句子以实体I-结束，未被添加
              entities.append(words[start : end + 1])
              entity_tags.append(targets[start][2:].lower())
              entity_spans.append([start, end + 1])
              start_flag = False
  
          if len(entities) != 0:
              outputs["raw_words"].append(words)
              outputs["raw_targets"].append(targets)
              outputs["entities"].append(entities)
              outputs["entity_tags"].append(entity_tags)
              outputs["entity_spans"].append(entity_spans)
      return outputs
  
file_path: DeepKE/src/deepke/name_entity_re/few_shot/module/datasets.py
imports: import torch
  from tqdm import tqdm
  import numpy
  from itertools import chain
  from torch.utils.data import Dataset, DataLoader
  from torch.nn.utils.rnn import pad_sequence
  from transformers import BartTokenizer, BertTokenizer
  import logging
label_desc: Use image node_id 2 for calling the ConllNERProcessor obj's underlying member method code with example usage: obj.load_from_file(mode) and returns: outputs