    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
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
fairseq/data/speech_dlm_dataset.py