code: def get_mini_batch(
      mini_batch_indices, sequences, seq_lengths, cuda=False
  ):
      # get the sequence lengths of the mini-batch
      seq_lengths = seq_lengths[mini_batch_indices]
      # sort the sequence lengths
      _, sorted_seq_length_indices = torch.sort(seq_lengths)
      sorted_seq_length_indices = sorted_seq_length_indices.flip(0)
      sorted_seq_lengths = seq_lengths[sorted_seq_length_indices]
      sorted_mini_batch_indices = mini_batch_indices[
          sorted_seq_length_indices
      ]
  
      # compute the length of the longest sequence in the mini-batch
      T_max = torch.max(seq_lengths)
      # this is the sorted mini-batch
      mini_batch = sequences[sorted_mini_batch_indices, 0:T_max, :]
      # this is the sorted mini-batch in reverse temporal order
      mini_batch_reversed = reverse_sequences(
          mini_batch, sorted_seq_lengths
      )
      # get mask for mini-batch
      mini_batch_mask = get_mini_batch_mask(
          mini_batch, sorted_seq_lengths
      )
  
      # cuda() here because need to cuda() before packing
      if cuda:
          mini_batch = mini_batch.cuda()
          mini_batch_mask = mini_batch_mask.cuda()
          mini_batch_reversed = mini_batch_reversed.cuda()
  
      # do sequence packing
      mini_batch_reversed = nn.utils.rnn.pack_padded_sequence(
          mini_batch_reversed, sorted_seq_lengths, batch_first=True
      )
  
      return (
          mini_batch,
          mini_batch_reversed,
          mini_batch_mask,
          sorted_seq_lengths,
      )
  
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 6 for calling a global function with example usage: get_mini_batch(mini_batch_indices, sequences, seq_lengths, cuda) and returns: mini_batch,  mini_batch_reversed,  mini_batch_mask,  sorted_seq_lengths