code: def predict(self, text: str):
      input_ids, input_mask, segment_ids, valid_ids = self.preprocess(
          text
      )
      input_ids = torch.tensor(
          [input_ids], dtype=torch.long, device=self.device
      )
      input_mask = torch.tensor(
          [input_mask], dtype=torch.long, device=self.device
      )
      segment_ids = torch.tensor(
          [segment_ids], dtype=torch.long, device=self.device
      )
      valid_ids = torch.tensor(
          [valid_ids], dtype=torch.long, device=self.device
      )
      with torch.no_grad():
          logits = self.model(
              input_ids, segment_ids, input_mask, valid_ids
          )
      logits = F.softmax(logits, dim=2)
      logits_label = torch.argmax(logits, dim=2)
      logits_label = logits_label.detach().cpu().numpy().tolist()[0]
  
      logits_confidence = [
          values[label].item()
          for values, label in zip(logits[0], logits_label)
      ]
  
      logits = []
      pos = 0
      for index, mask in enumerate(valid_ids[0]):
          if index == 0:
              continue
          if mask == 1:
              logits.append(
                  (
                      logits_label[index - pos],
                      logits_confidence[index - pos],
                  )
              )
          else:
              pos += 1
      logits.pop()
  
      labels = [
          (self.label_map[label], confidence)
          for label, confidence in logits
      ]
      words = list(text)
      assert len(labels) == len(words)
  
      result = []
      for word, (label, confidence) in zip(words, labels):
          if label != "O":
              result.append((word, label))
      return result
  
file_path: DeepKE/example/triple/cnschema/InferBert.py
imports: from __future__ import absolute_import, division, print_function
  import json
  import os
  import torch
  import torch.nn.functional
  from pytorch_transformers import BertConfig, BertForTokenClassification, BertTokenizer
  from collections import OrderedDict
label_desc: Use image node_id 5 for calling the InferNer obj's underlying member method code with example usage: obj.predict(text) and returns: result