code: def process_data(base_path, dataset, min_note=21, note_range=88):
      output = os.path.join(base_path, dataset.filename)
      if os.path.exists(output):
          try:
              with open(output, "rb") as f:
                  return pickle.load(f)
          except (ValueError, UnicodeDecodeError):
              # Assume python env has changed.
              # Recreate pickle file in this env's format.
              os.remove(output)
  
      print("processing raw data - {} ...".format(dataset.name))
      data = pickle.load(urlopen(dataset.url))
      processed_dataset = {}
      for split, data_split in data.items():
          processed_dataset[split] = {}
          n_seqs = len(data_split)
          processed_dataset[split]["sequence_lengths"] = torch.zeros(
              n_seqs, dtype=torch.long
          )
          processed_dataset[split]["sequences"] = []
          for seq in range(n_seqs):
              seq_length = len(data_split[seq])
              processed_dataset[split]["sequence_lengths"][
                  seq
              ] = seq_length
              processed_sequence = torch.zeros((seq_length, note_range))
              for t in range(seq_length):
                  note_slice = (
                      torch.tensor(list(data_split[seq][t])) - min_note
                  )
                  slice_length = len(note_slice)
                  if slice_length > 0:
                      processed_sequence[t, note_slice] = torch.ones(
                          slice_length
                      )
              processed_dataset[split]["sequences"].append(
                  processed_sequence
              )
      pickle.dump(
          processed_dataset, open(output, "wb"), pickle.HIGHEST_PROTOCOL
      )
      print("dumped processed data to %s" % output)
  
file_path: pyro/pyro/contrib/examples/polyphonic_data_loader.py
imports: import os
  import pickle
  from collections import namedtuple
  from urllib.request import urlopen
  import torch
  import torch.nn
  from torch.nn.utils.rnn import pad_sequence
  from pyro.contrib.examples.util import get_data_directory
label_desc: Use image node_id 1 for calling a global function with example usage: process_data(base_path, dataset, min_note, note_range) and returns: pickle