def __getitem__()

in notebooks/packed_bert/utils/packing/dataset_templates.py [0:0]


    def __getitem__(self, index):
        input_ids = self.input_ids[index]
        attention_masks = self.attention_mask[index]
        token_type_ids = self.token_type_ids[index]
        position_ids = self.position_ids[index]

        start_positions = self.start_positions[index] if self.start_positions is not None else None
        end_positions = self.end_positions[index] if self.end_positions is not None else None

        offset_mapping = self.offset_mapping[index] if self.offset_mapping is not None else None
        example_ids = self.example_ids[index] if self.example_ids is not None else None

        sample = {
            "input_ids": input_ids,
            "attention_mask": attention_masks,
            "token_type_ids": token_type_ids,
            "position_ids": position_ids,
        }

        if self.start_positions is not None and self.end_positions is not None:
            sample["start_positions"] = start_positions
            sample["end_positions"] = end_positions

        if self.offset_mapping is not None and self.example_ids is not None:
            sample["offset_mapping"] = offset_mapping
            sample["example_ids"] = example_ids

        return sample