[docs]classLogiQADataset(AbstractMCQADataset):""" A dataset class for LogiQA, a multiple-choice question answering dataset. """def__init__(self,split_set:str)->None:""" Initialize the LogiQADataset. Args: split_set (str): The split set of the dataset to use. Raises: SplitSetError: If the split set is not valid. """super().__init__()try:ifsplit_setnotinSPLIT_SETS:raiseSplitSetError(SPLIT_SETS)ifnotos.path.exists(LOGIQA_DATASET_FOLDER):download_dataset(LOGIQA_DATASET_ZIP_URL,LOGIQA_DATASET)self.split_set=split_setself.dataset_path=f"{LOGIQA_DATASET_FOLDER}/{split_set}.txt"(self.contexts,self.questions,self.answers,self.labels,)=self.__read_dataset()exceptSplitSetErroraserr:print(err.message)def__read_dataset(self)->Tuple[List[str],List[str],List[List[str]],List[int]]:""" Read the LogiQA dataset. Returns: Tuple[List[str], List[str], List[List[str]], List[int]]: The dataset as a tuple of lists. """withopen(self.dataset_path,"r",encoding="utf-8")asout:data=out.read().split("\n\n")contexts_list=[]questions_list=[]answers_list=[]labels_list=[]foriindata:tmp_splited_i=i.split("\n")contexts_list.append(tmp_splited_i[1])questions_list.append(tmp_splited_i[2])answers_list.append([tmp_splited_i[3],tmp_splited_i[4],tmp_splited_i[5],tmp_splited_i[6]])labels_list.append(LOGIQA_LABEL_TO_ID[tmp_splited_i[0]])returncontexts_list,questions_list,answers_list,labels_listdef__getitem__(self,index:int)->Tuple[str,str,List[str],int]:""" Get an item from the dataset. Args: index (int): The index of the item to retrieve. Returns: Tuple[str, str, List[str], int]: The item as a tuple of context, question, answers, and label. """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: The string representation of the dataset. """returnf"The {self.split_set} set of LogiQA 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)