code: def minibatch_by_words(pairs, max_words):
      """Group pairs of sequences into minibatches under max_words in size,
      considering padding. The size of a padded batch is the length of its
      longest sequence multiplied by the number of elements in the batch.
      """
      pairs = list(zip(*pairs))
      pairs.sort(key=lambda xy: len(xy[0]), reverse=True)
      batch = []
      for X, Y in pairs:
          batch.append((X, Y))
          n_words = max(len(xy[0]) for xy in batch) * len(batch)
          if n_words >= max_words:
              # We went *over* the cap, so don't emit the batch with this
              # example -- move that example into the next one.
              yield batch[:-1]
              batch = [(X, Y)]
      if batch:
          yield batch
  
imports: from dataclasses import dataclass
  from typing import List, Optional, Tuple, Callable
  import torch
  from pathlib import Path
  from transformers import AutoTokenizer, AutoModel
  import thinc
  from thinc.api import PyTorchWrapper, Softmax, chain, with_array, Model, Config
  from thinc.api import torch2xp, xp2torch, SequenceCategoricalCrossentropy
  from thinc.api import prefer_gpu, use_pytorch_for_gpu_memory
  from thinc.types import Floats2d, ArgsKwargs
  import ml_datasets
  import tqdm
  import typer
label_desc: Use image node_id 8 for calling a global function with example usage: minibatch_by_words(pairs, max_words) without return types