code: def compute_length_metrics(
      all_target_lens: List[int],
      all_target_length_preds: List[List[int]],
      select_length_beam,
      log_per_label_metrics: bool = True,
  ):
      length_metrics = {}
      length_report = {}
      if all_target_length_preds:
          all_length_pred_agg = {}
          beam = len(all_target_length_preds[0])
          for i in range(beam):
              all_length_pred_agg[i] = []
          for label, preds in zip(
              all_target_lens, all_target_length_preds
          ):
              for l in range(beam):
                  if label in preds[0 : l + 1]:
                      all_length_pred_agg[l].append(label)
                  else:
                      all_length_pred_agg[l].append(preds[0])
          for i in range(beam):
              length_metrics[i] = accuracy_score(
                  all_target_lens, all_length_pred_agg[i]
              )
  
          max_len = max(
              all_target_lens + all_length_pred_agg[select_length_beam]
          )
          all_pairs = [
              LabelPrediction(
                  [
                      1 if idx == pred else 0
                      for idx in range(max_len + 1)
                  ],
                  pred,
                  expect,
              )
              for pred, expect in zip(
                  all_length_pred_agg[select_length_beam],
                  all_target_lens,
              )
          ]
  
          length_report = compute_classification_metrics(
              all_pairs,
              [str(l) for l in range(max_len + 1)],
              0.0,  # Placeholder loss
              log_per_label_metrics=log_per_label_metrics,
          )
  
      return length_metrics, length_report
  
file_path: pytext/pytext/metrics/mask_metrics.py
imports: from typing import Dict, List, NamedTuple, Optional, Sequence
  from pytext.metrics import ClassificationMetrics, compute_classification_metrics, LabelPrediction
  from pytext.metrics.intent_slot_metrics import compute_all_metrics, compute_frame_accuracy, FrameAccuraciesByDepth, FramePredictionPair, IntentSlotMetrics, Node
  from sklearn.metrics import accuracy_score
label_desc: Use image node_id 1 for calling a global function with example usage: compute_length_metrics(all_target_lens, all_target_length_preds, select_length_beam, log_per_label_metrics) and returns: length_metrics,  length_report