code: def joint_bros_decoder(
      hidden,
      targets,
      n_targets,
      config,
      pad_id,
      train=False,
      reuse=None,
      lengths=None,
      use_crf=True,
      **kwargs,
  ):
      """
      A target block that calls both the sequence labeling target block and the
      BROS decoder target block. See each respective function for further details
  
      :param targets: The targets. The [:, 0, :] is assumed to contain the sequence labeling targets,
      and the rest ([:, 1:, :]), is expected to contain the BROS labels. [batch_size, 3, sequence_length]
      :return: dict containing:
          "logits": Dictionary containing "ner_logits", "start_token_logits" and "next_token_logits"
          "losses": Combined sequence labeling and bros loss
      """
  
      # Unpack the targets
      bros_targets, seq_targets = None, None
      if targets is not None:
          bros_targets = targets[:, 1:, :]
          seq_targets = targets[:, 0, :]
  
      # Correct n_targets, subtract number of group labels
      n_targets -= 4
  
      # Unpack class weights
      bros_weights, ner_weights = None, None
      class_weights = kwargs.pop("class_weights")
      if class_weights is not None:
          bros_weights = class_weights[n_targets:]
          ner_weights = class_weights[:n_targets]
  
      bros_dict = bros_decoder(
          hidden,
          bros_targets,
          n_targets,
          config,
          train=train,
          reuse=reuse,
          lengths=lengths,
          class_weights=bros_weights,
          **kwargs,
      )
      seq_dict = sequence_labeler(
          hidden,
          seq_targets,
          n_targets,
          config,
          pad_id,
          multilabel=False,
          train=train,
          reuse=reuse,
          lengths=lengths,
          use_crf=use_crf,
          class_weights=ner_weights,
          **kwargs,
      )
  
      seq_loss = tf.reduce_mean(seq_dict["losses"])
      scaled_seq_loss = config.seq_loss_weight * seq_loss
      scaled_group_loss = config.group_loss_weight * bros_dict["losses"]
      tf.compat.v1.summary.scalar("Sequence Loss", seq_loss)
      tf.compat.v1.summary.scalar("Group Loss", bros_dict["losses"])
      tf.compat.v1.summary.scalar(
          "Scaled Sequence Loss", scaled_seq_loss
      )
      tf.compat.v1.summary.scalar(
          "Scaled Group Loss", scaled_group_loss
      )
  
      return {
          "logits": {
              "ner_logits": seq_dict["logits"],
              "start_token_logits": bros_dict["logits"][
                  "start_token_logits"
              ],
              "next_token_logits": bros_dict["logits"][
                  "next_token_logits"
              ],
          },
          "losses": scaled_seq_loss + scaled_group_loss,
          "predict_params": {
              "sequence_length": lengths,
              "transition_matrix": seq_dict["predict_params"][
                  "transition_matrix"
              ],
          },
      }
  
imports: import math
  import functools
  import tensorflow
  from tensorflow_addons.text.crf import crf_log_likelihood
  from scipy.optimize import linear_sum_assignment
  from finetune.base_models.gpt.featurizer import attn, dropout, norm
  from finetune.util.shapes import shape_list, merge_leading_dims
  from finetune.optimizers.recompute_grads import recompute_grad
  from finetune.errors import FinetuneError
  from finetune.nn.activations import act_fns
  from finetune.nn.nn_utils import norm
  from finetune.nn.target_blocks import sequence_labeler
  from tensorflow.python.framework import function
  from finetune.nn.target_blocks import class_reweighted_grad
  from finetune.base_models.bert.modeling import attention_layer, dropout, create_initializer, layer_norm, gelu
label_desc: Use image node_id 4 for calling a global function with example usage: joint_bros_decoder(hidden, targets, n_targets, config, pad_id, train, reuse, lengths, use_crf) and returns: dict