code: def get_normalized_cap_label_weights(
      vocab_dict: Dict[str, int], label_counts: Counter
  ):
      """
      label weights automatically calculated from training data, normalized and capped by 1
      """
      normalized_label_weights = {}
      avg_label_count = sum(label_counts.values()) / len(
          label_counts.keys()
      )
      for label in vocab_dict:
          if label in label_counts:
              count = label_counts[label]
              if count > avg_label_count:
                  label_weight = avg_label_count / count
                  normalized_label_weights[label] = label_weight
              else:
                  normalized_label_weights[label] = 1.0
          else:
              normalized_label_weights[label] = 1.0
  
      # initialize
      cap_label_weights_tensor = torch.ones(1, len(vocab_dict.keys()))
      for label, index in vocab_dict.items():
          cap_label_weights_tensor[0][index] = normalized_label_weights[
              label
          ]
  
      return cap_label_weights_tensor
  
file_path: pytext/pytext/utils/label.py
imports: import logging
  from collections import Counter
  from typing import Dict
  import torch
  from pytext.utils.cuda import tensor
  from pytext.utils.typing import WeightingMethod
label_desc: Use image node_id 6 for calling a global function with example usage: get_normalized_cap_label_weights(vocab_dict, label_counts) and returns: cap_label_weights_tensor