[docs]classLogiQA2Dataset(AbstractMCQADataset):""" A dataset class for LogiQA2, a Multiple Choice Question Answering dataset. """def__init__(self,split_set:str)->None:""" Initialize the LogiQA2Dataset. Args: split_set (str): The split set of the dataset (train, validation, or test). Raises: SplitSetError: If an invalid split set is provided. """super().__init__()try:ifsplit_setnotinSPLIT_SETS:raiseSplitSetError(SPLIT_SETS)self.split_set=split_setifsplit_set=="val":split_set="validation"self.dataset=load_dataset(LOGIQA2_DATASET,split=split_set)print(self.dataset)self.contexts,self.questions,self.answers,self.labels=(self.__process_dataset())exceptSplitSetErroraserr:print(err.message)def__process_dataset(self,)->Tuple[List[str],List[str],List[List[str]],List[int]]:""" Process the LogiQA2 dataset. Returns: Tuple[List[str], List[str], List[List[str]], List[int]]: A tuple containing the contexts, questions, answers, and labels of the dataset. """contexts=self.dataset["text"]questions=self.dataset["question"]answers=[item["formatted_options"]foriteminself.dataset]labels=[ord(item["answer_char"])-ord("A")foriteminself.dataset]returncontexts,questions,answers,labelsdef__getitem__(self,index:int)->Tuple[str,str,List[str],int]:""" Get an item from the dataset. Args: index (int): The index of the item. Returns: Tuple[str, str, List[str], int]: A tuple containing the context, question, answers, and label of the item. """return(self.contexts[index],self.questions[index],self.answers[index],self.labels[index],)def__str__(self)->str:""" Get a string representation of the dataset. Returns: str: A string representation of the dataset. """returnf"The {self.split_set} set of LogiQA2 has {self.__len__()} instances"def__len__(self)->int:""" Returns the number of instances in the dataset. Returns: int: The number of instances in the dataset. """returnlen(self.contexts)