code: def forward(
      self,
      input_ids,
      spans,
      spans_mask,
      spans_ner_label=None,
      token_type_ids=None,
      attention_mask=None,
  ):
      spans_embedding = self._get_span_embeddings(
          input_ids,
          spans,
          token_type_ids=token_type_ids,
          attention_mask=attention_mask,
      )
      ffnn_hidden = []
      hidden = spans_embedding
      for layer in self.ner_classifier:
          hidden = layer(hidden)
          ffnn_hidden.append(hidden)
      logits = ffnn_hidden[-1]
  
      if spans_ner_label is not None:
          loss_fct = CrossEntropyLoss(reduction="sum")
          if attention_mask is not None:
              active_loss = spans_mask.view(-1) == 1
              active_logits = logits.view(-1, logits.shape[-1])
              active_labels = torch.where(
                  active_loss,
                  spans_ner_label.view(-1),
                  torch.tensor(loss_fct.ignore_index).type_as(
                      spans_ner_label
                  ),
              )
              loss = loss_fct(active_logits, active_labels)
          else:
              loss = loss_fct(
                  logits.view(-1, logits.shape[-1]),
                  spans_ner_label.view(-1),
              )
          return loss, logits, spans_embedding
      else:
          return logits, spans_embedding, spans_embedding
  
imports: import os
  import sys
  import torch
  from torch import nn
  import torch.nn.functional
  from torch.nn import CrossEntropyLoss
  from allennlp.nn.util import batched_index_select
  from allennlp.nn import util
  from allennlp.modules import FeedForward
  import numpy
  from transformers import BertTokenizer, BertPreTrainedModel, BertModel
  from transformers import AlbertTokenizer, AlbertPreTrainedModel, AlbertModel
  import os
  import json
  import logging
label_desc: Use image node_id 3 for calling the BertForEntity obj's underlying member method code with example usage: obj.forward(input_ids, spans, spans_mask, spans_ner_label, token_type_ids, attention_mask) and returns: loss,  logits,  spans_embedding, logits,  spans_embedding,  spans_embedding