def __init__(self, data=None, is_labeled=False):
        """Create a Batch from a list of examples."""
        if data is None or len(data) == 0:
            raise ValueError("data is empty")
        self.batch_size = len(data)
        pre_src = [x[0] for x in data]
        pre_segs = [x[2] for x in data]
        pre_clss = [x[3] for x in data]

        src = torch.tensor(self._pad(pre_src, 0))

        pre_labels = None
        labels = None
        if is_labeled:
            pre_labels = [x[1] for x in data]
            labels = torch.tensor(self._pad(pre_labels, 0))
        segs = torch.tensor(self._pad(pre_segs, 0))
        mask = ~(src == 0)

        clss = torch.tensor(self._pad(pre_clss, -1))
        mask_cls = ~(clss == -1)
        clss[clss == -1] = 0

        setattr(self, "clss", clss)
        setattr(self, "mask_cls", mask_cls)
        setattr(self, "src", src)
        setattr(self, "segs", segs)
        setattr(self, "mask", mask)

        src_str = [x[4] for x in data]
        setattr(self, "src_str", src_str)

        if is_labeled:
            setattr(self, "labels", labels)
            tgt_str = [x[5] for x in data]
            setattr(self, "tgt_str", tgt_str)
Create a Batch from a list of examples.
utils_nlp/models/transformers/bertsum/data_loader.py