o
    Ni                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlm  m	Z
 ddlmZ dZdZdd	d
dZG dd dejjZdS )The Cosmos QA dataset.    )absolute_import)division)print_functionNa  @inproceedings{huang-etal-2019-cosmos,
    title = "Cosmos {QA}: Machine Reading Comprehension with Contextual Commonsense Reasoning",
    author = "Huang, Lifu  and
      Le Bras, Ronan  and
      Bhagavatula, Chandra  and
      Choi, Yejin",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)",
    year = "2019",
    url = "https://www.aclweb.org/anthology/D19-1243"
}
a  Cosmos QA is a large-scale dataset of 35.6K problems that require
 commonsense-based reading comprehension, formulated as multiple-choice
 questions. It focuses on reading between the lines over a diverse collection
 of people's everyday narratives, asking questions concerning on the likely
 causes or effects of events that require reasoning beyond the exact text
 spans in the context.
zJhttps://raw.githubusercontent.com/wilburOne/cosmosqa/master/data/train.csvzJhttps://raw.githubusercontent.com/wilburOne/cosmosqa/master/data/valid.csvzKhttps://raw.githubusercontent.com/wilburOne/cosmosqa/master/data/test.jsonl)train
validationtestc                   @   s4   e Zd ZdZejdZdd Zdd Z	dd Z
d	S )
CosmosQAr   z1.0.0c                 C   sj   t jj| tt jt j t j t j t j t j t j t jjg ddt j dd dtdS )N)0123)names)contextquestionanswer0answer1answer2answer3labelidz#https://wilburone.github.io/cosmos/)builderdescriptionfeaturessupervised_keyshomepagecitation)	tfdscoreDatasetInfo_DESCRIPTIONr   FeaturesDictText
ClassLabel	_CITATION)self r&   d/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/question_answering/cosmos_qa.py_info@   s"   zCosmosQA._infoc                 C   s   | t}dd | D S )zReturns SplitGenerators.c                 S   s$   g | ]\}}t jj|d |idqS )	file_path)name
gen_kwargs)r   r   SplitGenerator).0splitr)   r&   r&   r'   
<listcomp>Y   s    z.CosmosQA._split_generators.<locals>.<listcomp>)download_SPLIT_DOWNLOAD_URLitems)r%   
dl_manager
file_pathsr&   r&   r'   _split_generatorsU   s   
zCosmosQA._split_generatorsc                 c   s    t jj|?}|dr$|D ]}t|}d|d< |d |fV  qntj|dd}|D ]}|d |fV  q-W d   dS W d   dS 1 sJw   Y  dS )z:This function returns the examples in the raw (text) form.z.jsonlr   r   ,)	delimiterN)	tfiogfileGFileendswithjsonloadscsv
DictReader)r%   r)   flinerowreaderr&   r&   r'   _generate_examples_   s   

	"zCosmosQA._generate_examplesN)__name__
__module____qualname____doc__r   r   VersionVERSIONr(   r5   rF   r&   r&   r&   r'   r	   <   s    
r	   )rJ   
__future__r   r   r   r@   r>   tensorflow.compat.v2compatv2r9   tensorflow_datasets.public_api
public_apir   r$   r    r1   r   GeneratorBasedBuilderr	   r&   r&   r&   r'   <module>   s   
