code: def forward(
      self,
      input_ids,
      token_type_ids=None,
      attention_mask=None,
      valid_ids=None,
  ):
      sequence_output = self.bert(
          input_ids, token_type_ids, attention_mask, head_mask=None
      )[0]
      batch_size, max_len, feat_dim = sequence_output.shape
      valid_output = torch.zeros(
          batch_size,
          max_len,
          feat_dim,
          dtype=torch.float32,
          device="cuda" if torch.cuda.is_available() else "cpu",
      )
      for i in range(batch_size):
          jj = -1
          for j in range(max_len):
              if valid_ids[i][j].item() == 1:
                  jj += 1
                  valid_output[i][jj] = sequence_output[i][j]
      sequence_output = self.dropout(valid_output)
      logits = self.classifier(sequence_output)
      return logits
  
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 1 for calling the BertNer obj's underlying member method code with example usage: obj.forward(input_ids, token_type_ids, attention_mask, valid_ids) and returns: logits