code: def _calculate_entity_loss(
      self,
      inputs: tf.Tensor,
      tag_ids: tf.Tensor,
      mask: tf.Tensor,
      sequence_lengths: tf.Tensor,
      tag_name: Text,
      entity_tags: Optional[tf.Tensor] = None,
  ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]:
      tag_ids = tf.cast(tag_ids[:, :, 0], tf.int32)
  
      if entity_tags is not None:
          _tags = self._tf_layers[f"embed.{tag_name}.tags"](entity_tags)
          inputs = tf.concat([inputs, _tags], axis=-1)
  
      logits = self._tf_layers[f"embed.{tag_name}.logits"](inputs)
  
      # should call first to build weights
      pred_ids, _ = self._tf_layers[f"crf.{tag_name}"](
          logits, sequence_lengths
      )
      loss = self._tf_layers[f"crf.{tag_name}"].loss(
          logits, tag_ids, sequence_lengths
      )
      f1 = self._tf_layers[f"crf.{tag_name}"].f1_score(
          tag_ids, pred_ids, mask
      )
  
      return loss, f1, logits
  
imports: import time
  import random
  import tensorflow
  import numpy
  import logging
  import os
  from collections import defaultdict
  from typing import List, Text, Dict, Tuple, Union, Optional, Any, TYPE_CHECKING
  from keras.utils import tf_utils
  from keras import Model
  from rasa.shared.constants import DIAGNOSTIC_DATA
  from rasa.utils.tensorflow.constants import LABEL, IDS, INTENT_CLASSIFICATION, SENTENCE, SEQUENCE_LENGTH, RANDOM_SEED, EMBEDDING_DIMENSION, REGULARIZATION_CONSTANT, SIMILARITY_TYPE, CONNECTION_DENSITY, NUM_NEG, LOSS_TYPE, MAX_POS_SIM, MAX_NEG_SIM, USE_MAX_NEG_SIM, NEGATIVE_MARGIN_SCALE, SCALE_LOSS, LEARNING_RATE, CONSTRAIN_SIMILARITIES, MODEL_CONFIDENCE, RUN_EAGERLY
  from rasa.utils.tensorflow.model_data import RasaModelData, FeatureSignature, FeatureArray
  import rasa.utils.train_utils
  from rasa.utils.tensorflow import layers
  from rasa.utils.tensorflow import rasa_layers
  from rasa.utils.tensorflow.data_generator import RasaDataGenerator, RasaBatchDataGenerator
  from rasa.shared.nlu.constants import TEXT
  from rasa.shared.exceptions import RasaException
  from rasa.utils.tensorflow.types import BatchData, MaybeNestedBatchData
label_desc: Use image node_id 21 for calling the TransformerRasaModel obj's underlying member method code with example usage: obj._calculate_entity_loss(inputs, tag_ids, mask, sequence_lengths, tag_name, entity_tags) and returns: loss,  f1,  logits