code: def mask_adaptive_logsoftmax(
      hidden,
      target,
      n_token,
      d_embed,
      d_proj,
      cutoffs,
      params,
      tie_projs,
      initializer=None,
      proj_initializer=None,
      div_val=1,
      scope="adaptive_softmax",
      proj_same_dim=True,
      return_mean=True,
      **kwargs,
  ):
      def _logit(x, W, b, proj):
          y = x
          if proj is not None:
              y = tf.einsum("ibd,ed->ibe", y, proj)
          return tf.einsum("ibd,nd->ibn", y, W) + b
  
      params_W, params_projs = params[0], params[1]
  
      def _gather_logprob(logprob, target):
          lp_size = tf.shape(logprob)
          r = tf.range(lp_size[0])
          idx = tf.stack([r, target], 1)
          return tf.gather_nd(logprob, idx)
  
      with tf.variable_scope(scope):
          if len(cutoffs) == 0:
              print("no adaptive")
              softmax_b = tf.get_variable(
                  "bias", [n_token], initializer=tf.zeros_initializer()
              )
              output = _logit(hidden, params_W, softmax_b, params_projs)
              output_ = tf.nn.softmax(output, dim=2)
              nll = tf.nn.sparse_softmax_cross_entropy_with_logits(
                  labels=target, logits=output
              )
          else:
              cutoff_ends = [0] + cutoffs + [n_token]
              nll = tf.zeros_like(target, dtype=tf.float32)
              for i in range(len(cutoff_ends) - 1):
                  with tf.variable_scope("cutoff_{}".format(i)):
                      l_idx, r_idx = cutoff_ends[i], cutoff_ends[i + 1]
                      mask = (target >= l_idx) & (target < r_idx)
                      mask_idx = tf.where(mask)
                      cur_target = tf.boolean_mask(target, mask) - l_idx
                      cur_d_embed = d_embed // (div_val**i)
  
                      if div_val == 1:
                          cur_W = params_W[l_idx:r_idx]
                      else:
                          cur_W = params_W[i]
                      cur_b = tf.get_variable(
                          "b",
                          [r_idx - l_idx],
                          initializer=tf.zeros_initializer(),
                      )
                      if tie_projs[i]:
                          if div_val == 1:
                              cur_proj = params_projs
                          else:
                              cur_proj = params_projs[i]
                      else:
                          if (
                              div_val == 1 or not proj_same_dim
                          ) and d_proj == cur_d_embed:
                              cur_proj = None
                          else:
                              cur_proj = tf.get_variable(
                                  "proj",
                                  [cur_d_embed, d_proj],
                                  initializer=proj_initializer,
                              )
                      if i == 0:
                          cluster_W = tf.get_variable(
                              "cluster_W",
                              [len(cutoffs), d_embed],
                              initializer=tf.zeros_initializer(),
                          )
                          cluster_b = tf.get_variable(
                              "cluster_b",
                              [len(cutoffs)],
                              initializer=tf.zeros_initializer(),
                          )
                          cur_W = tf.concat([cur_W, cluster_W], 0)
                          cur_b = tf.concat([cur_b, cluster_b], 0)
  
                          head_logit = _logit(
                              hidden, cur_W, cur_b, cur_proj
                          )
                          head_logprob = tf.nn.log_softmax(head_logit)
                          cur_head_logprob = tf.boolean_mask(
                              head_logprob, mask
                          )
                          cur_logprob = _gather_logprob(
                              cur_head_logprob, cur_target
                          )
                      else:
                          cur_head_logprob = tf.boolean_mask(
                              head_logprob, mask
                          )
                          cur_hidden = tf.boolean_mask(hidden, mask)
                          tail_logit = tf.squeeze(
                              _logit(
                                  cur_hidden[None],
                                  cur_W,
                                  cur_b,
                                  cur_proj,
                              ),
                              0,
                          )
                          tail_logprob = tf.nn.log_softmax(tail_logit)
                          cur_logprob = cur_head_logprob[
                              :, cutoff_ends[1] + i - 1
                          ] + _gather_logprob(tail_logprob, cur_target)
                      nll += tf.scatter_nd(
                          mask_idx,
                          -cur_logprob,
                          tf.to_int64(tf.shape(nll)),
                      )
      if return_mean:
          nll = tf.reduce_mean(nll)
      return nll, output_
  
file_path: delta/gcompiler/example/python/nlp_transformer/model.py
imports: import tensorflow
label_desc: Use image node_id 8 for calling a global function with example usage: mask_adaptive_logsoftmax(hidden, target, n_token, d_embed, d_proj, cutoffs, params, tie_projs, initializer, proj_initializer, div_val, scope, proj_same_dim, return_mean) and returns: nll,  output_, unknown, tf