class_docstr: The dataset used to train the SpeechDLM model as described in the paper:
  https://arxiv.org/pdf/2203.16502.pdf
  
  The input datasets is expected to be a dict over channel names with the values
  being instances of :class:`~fairseq.data.MonolingualDataset`.
  
  Each element of SpeechDLMDataset is a dictionary with the following keys:
      - `id` (int) : index of the item
      - `source` (OrderedDict[str, Tensor of shape (seq_len,)]) : dictionary over
          channels with the values containing the input unit tokens
      - `target_next` (OrderedDict[str, Tensor of shape (seq_len,)]) : dictionary
          over channels with the values containing the next unit tokens (input
          tokens shifted by 1).
          Its value is None if 'next' not in self.targets
      - `target_edge` (OrderedDict[str, Tensor of shape (dedup_seq_len,)]) : dictionary
          over channels with the values containing the edge unit tokens (input tokens
          deduplicated).
          Its value is None if 'edge' not in self.targets
      - `target_duration` (OrderedDict[str, Tensor of shape (dedup_seq_len,)]) :
          dictionary over channels with the values being the durations of the edge units.
          Its value is None if 'duration' not in targets.
      - `target_edge_indices` (OrderedDict[str, Tensor of shape (dedup_seq_len,)]) :
          dictionary over channels with the values being the indices of the edge units
          in the source sequence.
          Its value is None if neither 'edge' or 'duration in targets.
  
  Args:
      datasets (Dict[str, ~fairseq.data.MonolingualDataset]): a dictionary of
          :class:`~fairseq.data.MonolingualDataset` instances.
      targets (List[str]): list of the target types that the SpeechDLM model
          should predict.  Can be one of "next", "edge", "duration".
      shuffle (bool, optional): shuffle the elements before batching
          (default: True).
docstr: Get target in one of ['next', 'edge', 'duration']
  - 'next' is the future unit
  - 'edge' is the edge unit
  - 'duration' is the duration of the edge unit
docstr_tok: ["Get","target","in","one","of","[","'next","'",",","'edge","'",",","'duration","'","]","-","'next","'","is","the","future","unit","-","'edge","'","is","the","edge","unit","-","'duration","'","is","the","duration","of","the","edge","unit"]
code: def _get_target(self, index, channel):
      """Get target in one of ['next', 'edge', 'duration']
      - 'next' is the future unit
      - 'edge' is the edge unit
      - 'duration' is the duration of the edge unit
      """
      if self.targets is not None:
          target = {}
          pad_idx = self.vocab.pad()
          max_dur = self.max_target_durations
          future_target = self.datasets[channel][index]["target"]
          if "edge" in self.targets or "duration" in self.targets:
              edge_units, edge_unit_counts = torch.unique_consecutive(
                  future_target, return_counts=True
              )
              padding_end = edge_units[-1] == pad_idx
              if padding_end:
                  edge_units = edge_units[:-1]
                  edge_unit_counts = edge_unit_counts[:-1]
              edge_indices = torch.cumsum(edge_unit_counts, 0)
              edge_indices = torch.cat(
                  [torch.tensor([0]), edge_indices[:-1]]
              )
              target["edge_indices"] = edge_indices
  
          for t in self.targets:
              if t == "next":
                  target[t] = future_target
              elif t == "edge":
                  target[t] = edge_units
              elif t == "duration":
                  # count the remaining duration of the last edge indices in the next sentence
                  if (
                      not padding_end
                      and index < len(self.datasets[channel]) - 1
                  ):
                      i = 0
                      next_sentence_target = self.datasets[channel][
                          index + 1
                      ]["target"]
                      while (
                          next_sentence_target[i] == edge_units[-1]
                          and edge_unit_counts[-1] + i < max_dur
                      ):
                          i += 1
                      edge_unit_counts[-1] += i
  
                  # cut off to the maximal threshold
                  if max_dur:
                      edge_unit_counts[
                          edge_unit_counts > max_dur
                      ] = max_dur
  
                  target[t] = edge_unit_counts
              else:
                  raise Exception("invalid target " + t)
  
          return target
  
file_path: fairseq/fairseq/data/speech_dlm_dataset.py
imports: from collections import OrderedDict
  import numpy
  import torch
  from fairseq.data import FairseqDataset, MonolingualDataset, data_utils
label_desc: Use image node_id 4 for calling the SpeechDLMDataset obj's underlying member method code with example usage: obj._get_target(index, channel) and returns: target