code: def joint_group_relation_decoder(
      hidden,
      targets,
      n_targets,
      n_groups,
      config,
      pad_id,
      train=False,
      reuse=None,
      lengths=None,
      use_crf=True,
      hidden_size=768,
      num_attention_heads=12,
      intermediate_size=3072,
      intermediate_act_fn=gelu,
      hidden_dropout_prob=0.1,
      attention_probs_dropout_prob=0.1,
      initializer_range=0.02,
      n_layers=3,
      query_size=256,
      **kwargs,
  ):
      """
      A target block that calls both the sequence labeling target block and the
      group relation decoder target block. See each respective function for further details
  
      :param targets: The targets. A dictionary containing the group relation
      targest in the key "groups" and the ner targets in the key "tags"
      :return: dict containing:
      :param class_weights: Class weights as calculated by the target model. Of
      length n_ner_targets + 2, where the last two weights are for the group
      relation model.
      :return: dict containing:
          "logits": Dictionary containing "ner_logits" [batch_size, seq_len]
          and "group_logits" [batch_size, seq_len, n_groups]
          "losses": Combined sequence labeling and group relation loss
      """
      group_relation_targets, seq_targets = None, None
      if targets is not None:
          group_relation_targets = targets["groups"]
          seq_targets = targets["tags"]
  
      # Correct n_targets, subtract number of group labels
      n_targets -= 2
  
      # Unpack class weights
      group_weights, ner_weights = None, None
      class_weights = kwargs.pop("class_weights")
      if class_weights is not None:
          group_weights = class_weights[n_targets:]
          ner_weights = class_weights[:n_targets]
  
      group_relation_dict = group_relation_decoder(
          hidden,
          group_relation_targets,
          n_groups,
          config,
          train=train,
          reuse=reuse,
          lengths=lengths,
          hidden_size=hidden_size,
          num_attention_heads=num_attention_heads,
          intermediate_size=intermediate_size,
          intermediate_act_fn=intermediate_act_fn,
          hidden_dropout_prob=hidden_dropout_prob,
          attention_probs_dropout_prob=attention_probs_dropout_prob,
          initializer_range=initializer_range,
          n_layers=n_layers,
          query_size=query_size,
          class_weights=group_weights,
      )
      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 * group_relation_dict["losses"]
      )
      tf.compat.v1.summary.scalar("Sequence Loss", seq_loss)
      tf.compat.v1.summary.scalar(
          "Group Loss", group_relation_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"],
              "group_logits": group_relation_dict["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 8 for calling a global function with example usage: joint_group_relation_decoder(hidden, targets, n_targets, n_groups, config, pad_id, train, reuse, lengths, use_crf, hidden_size, num_attention_heads, intermediate_size, intermediate_act_fn, hidden_dropout_prob, attention_probs_dropout_prob, initializer_range, n_layers, query_size) and returns: dict