code: def calculate_metrics(args):
      with open(args.file, encoding="utf-8") as of:
          samples = of.read()
      pattern = "=" * 40 + r" SAMPLE \d+ " + "=" * 40 + "\n"
      samples = re.split(pattern, samples)[1:]
  
      num_samples = (
          args.num_samples if args.num_samples else len(samples)
      )
      assert num_samples <= len(samples), (
          f"The requested number of samples {num_samples} is greater than "
          f"total number of samples {len(samples)}"
      )
      samples = samples[:num_samples]
      num_bleu_samples = (
          args.num_bleu_samples
          if args.num_bleu_samples
          else num_samples
      )
      assert num_bleu_samples <= num_samples, (
          f"The requested number of samples {num_bleu_samples} for "
          f"calculating self-BLEU is greater than number of samples {num_samples}."
      )
      seed = args.seed if args.seed is not None else 0
      random.seed(seed)
  
      _, tokenizer, _, _ = get_pretrained_gpt2(
          load_backbone=False, load_lm=False
      )
      sample_ids = tokenizer.encode(samples, output_type=int)
      if sample_ids[-1] == tokenizer.vocab.eos_id:
          sample_ids.pop()
  
      self_bleu4 = calculate_self_bleu4(sample_ids, num_bleu_samples)
      zipf_coefficient = calculate_zipf_coefficient(
          sample_ids, tokenizer
      )
      repetition = calculate_repetition(sample_ids)
      print(
          "Self BLEU 4: {}\n"
          "Zipf coefficient: {}\n"
          "Repetition: {}\n".format(
              self_bleu4, zipf_coefficient, repetition
          )
      )
  
file_path: gluon-nlp/scripts/generation/calculate_metrics.py
imports: import os
  import re
  import argparse
  from nltk.translate.bleu_score import sentence_bleu
  from collections import Counter
  import operator
  import numpy
  from scipy import stats
  import random
  from tqdm import tqdm
  from functools import partial
  from multiprocessing.pool import Pool
  from gluonnlp.models.gpt2 import get_pretrained_gpt2
label_desc: Use image node_id 6 for calling a global function with example usage: calculate_metrics(args) without return types