code: def split_into_batches(data, batch_size):
      """
      Returns a list of intervals so that each interval is either <= batch_size or one element long.
  
      Long elements are not dropped from the intervals.
      data is a list of lists
      batch_size is how long to make each batch
      return value is a list of pairs, start_idx end_idx
      """
      intervals = []
      interval_start = 0
      interval_size = 0
      for idx, line in enumerate(data):
          if len(line) > batch_size:
              # guess we'll just hope the model can handle a batch of this size after all
              if interval_size > 0:
                  intervals.append((interval_start, idx))
              intervals.append((idx, idx + 1))
              interval_start = idx + 1
              interval_size = 0
          elif len(line) + interval_size > batch_size:
              # this line puts us over batch_size
              intervals.append((interval_start, idx))
              interval_start = idx
              interval_size = len(line)
          else:
              interval_size = interval_size + len(line)
      if interval_size > 0:
          # there's some leftover
          intervals.append((interval_start, len(data)))
      return intervals
  
imports: import argparse
  from collections import Counter
  from contextlib import contextmanager
  import gzip
  import json
  import logging
  import lzma
  import os
  import random
  import re
  import sys
  import unicodedata
  import zipfile
  import torch
  import numpy
  from stanza.models.common.constant import lcode2lang
  import stanza.models.common.seq2seq_constant
  from stanza.resources.default_packages import TRANSFORMER_NICKNAMES
  import stanza.utils.conll18_ud_eval
  from stanza.utils.conll18_ud_eval import UDError
label_desc: Use image node_id 24 for calling a global function with example usage: split_into_batches(data, batch_size) and returns: intervals