docstr: Custom Your Ner Model
  Args:
      vocab_size (`int`): (Only BiLSTM_CRF) vocabulary size used in BiLSTM_CRF
      num_labels (`int`): (Only BiLSTM_CRF)the number of Labels used in BiLSTM_CRF, such as the length of ([B-LOC, I-LOC, B-ORG, I-ORG, B-PER, I-PER, O])
      word2id (`dict`): (Only BiLSTM_CRF) Map word into index for embedding
      id2label (`dict`): (Only BiLSTM_CRF) Map index into Label for decoding
docstr_tok: ["Custom","Your","Ner","Model","Args",":","vocab_size","(","`","int","`",")",":","(","Only","BiLSTM_CRF",")","vocabulary","size","used","in","BiLSTM_CRF","num_labels","(","`","int","`",")",":","(","Only","BiLSTM_CRF",")","the","number","of","Labels","used","in","BiLSTM_CRF",",","such","as","the","length","of","(","[","B-LOC",",","I-LOC",",","B-ORG",",","I-ORG",",","B-PER",",","I-PER",",","O","]",")","word2id","(","`","dict","`",")",":","(","Only","BiLSTM_CRF",")","Map","word","into","index","for","embedding","id2label","(","`","dict","`",")",":","(","Only","BiLSTM_CRF",")","Map","index","into","Label","for","decoding"]
code: def __init__(
      self,
      model_dir: str,
      config,
      vocab_size=None,
      num_labels=None,
      word2id=None,
      id2label=None,
  ):
      """
      Custom Your Ner Model
      Args:
          vocab_size (`int`): (Only BiLSTM_CRF) vocabulary size used in BiLSTM_CRF
          num_labels (`int`): (Only BiLSTM_CRF)the number of Labels used in BiLSTM_CRF, such as the length of ([B-LOC, I-LOC, B-ORG, I-ORG, B-PER, I-PER, O])
          word2id (`dict`): (Only BiLSTM_CRF) Map word into index for embedding
          id2label (`dict`): (Only BiLSTM_CRF) Map index into Label for decoding
      """
      self.cfg = config
      if config.model_name == "lstmcrf":
          assert vocab_size != None
          assert num_labels != None
          assert word2id != None
          assert id2label != None
  
          self.word2id = word2id
          self.id2label = id2label
  
          self.model = torch.load(
              os.path.join(
                  utils.get_original_cwd(),
                  self.cfg.output_dir,
                  self.cfg.model_save_name,
              )
          )
      elif config.model_name == "bert":
          (
              self.model,
              self.tokenizer,
              self.model_config,
          ) = self.load_model(model_dir)
          self.label_map = self.model_config["label_map"]
          self.max_seq_length = self.model_config["max_seq_length"]
          self.label_map = {
              int(k): v for k, v in self.label_map.items()
          }
      else:
          raise NotImplementedError(
              f"model type {self.cfg.model_name} not supported"
          )
  
      self.device = "cuda" if torch.cuda.is_available() else "cpu"
      self.model = self.model.to(self.device)
      self.model.eval()
  
file_path: DeepKE/src/deepke/name_entity_re/standard/models/InferBert.py
imports: import json
  import os
  import torch
  import torch.nn.functional
  from transformers import BertConfig, BertForTokenClassification, BertTokenizer
  from collections import OrderedDict
  from .BiLSTM_CRF import *
  import hydra
  from hydra import utils
  import nltk
  from nltk import word_tokenize
label_desc: Use image node_id 1 to create a new InferNer object  with example: obj = InferNer(model_dir, config, vocab_size, num_labels, word2id, id2label)