code: def extract_labels(f, one_hot=False, num_classes=10):
      """Extract the labels into a 1D uint8 np array [index].
  
      Args:
        f: A file object that can be passed into a gzip reader.
        one_hot: Does one hot encoding for the result.
        num_classes: Number of classes for the one hot encoding.
  
      Returns:
        labels: a 1D uint8 np array.
  
      Raises:
        ValueError: If the bystream doesn't start with 2049.
      """
      tf.logging.info("Extracting", f.name)
      with gzip.GzipFile(fileobj=f) as bytestream:
          magic = _read32(bytestream)
          if magic != 2049:
              raise ValueError(
                  "Invalid magic number %d in MNIST label file: %s"
                  % (magic, f.name)
              )
          num_items = _read32(bytestream)
          buf = bytestream.read(num_items)
          labels = np.frombuffer(buf, dtype=np.uint8)
          if one_hot:
              return dense_to_one_hot(labels, num_classes)
          return labels
  
file_path: magenta/magenta/models/latent_transfer/local_mnist.py
imports: import gzip
  import os
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: extract_labels(f, one_hot, num_classes) and returns: labels, dense_to_one_hot