o
    Nim                  	   @   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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Zd	Zd
Zedddg ddddedddZG dd dejjZG dd dejjZdd ZdS )?The General Language Understanding Evaluation (GLUE) benchmark.    )absolute_import)division)print_functionNa  @inproceedings{wang2019glue,
  title={{GLUE}: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding},
  author={Wang, Alex and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R.},
  note={In the Proceedings of ICLR.},
  year={2019}
}

Note that each GLUE dataset has its own citation. Please see the source to see
the correct citation for each contained dataset.zGLUE, the General Language Understanding Evaluation benchmark
(https://gluebenchmark.com/) is a collection of resources for training,
evaluating, and analyzing natural language understanding systems.

zhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2Fmrpc_dev_ids.tsv?alt=media&token=ec5c0836-31d5-48f4-b431-7480817f1adczNhttps://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_train.txtzMhttps://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_test.txt	sentence1	sentence2premise
hypothesis
entailmentneutralcontradiction
gold_labelzhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FMNLI.zip?alt=media&token=50329ea1-e339-40e2-809c-10c40afff3ceMNLIa        @InProceedings{N18-1101,
        author = "Williams, Adina
                  and Nangia, Nikita
                  and Bowman, Samuel",
        title = "A Broad-Coverage Challenge Corpus for
                 Sentence Understanding through Inference",
        booktitle = "Proceedings of the 2018 Conference of
                     the North American Chapter of the
                     Association for Computational Linguistics:
                     Human Language Technologies, Volume 1 (Long
                     Papers)",
        year = "2018",
        publisher = "Association for Computational Linguistics",
        pages = "1112--1122",
        location = "New Orleans, Louisiana",
        url = "http://aclweb.org/anthology/N18-1101"
      }
      @article{bowman2015large,
        title={A large annotated corpus for learning natural language inference},
        author={Bowman, Samuel R and Angeli, Gabor and Potts, Christopher and Manning, Christopher D},
        journal={arXiv preprint arXiv:1508.05326},
        year={2015}
      }z,http://www.nyu.edu/projects/bowman/multinli/)text_featureslabel_classeslabel_columndata_urldata_dircitationurlc                       s2   e Zd ZdZejjddd f fdd	Z  ZS )
GlueConfigzBuilderConfig for GLUE.Nc                 C   s   | S N )xr   r   Q/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/text/glue.py<lambda>g   s    zGlueConfig.<lambda>c	           
         sX   t t| jddtjddi|	 || _|| _|| _|| _	|| _
|| _|| _|| _dS )a  BuilderConfig for GLUE.

    Args:
      text_features: `dict[string, string]`, map from the name of the feature
        dict for each text field to the name of the column in the tsv file
      label_column: `string`, name of the column in the tsv file corresponding
        to the label
      data_url: `string`, url to download the zip file from
      data_dir: `string`, the path to the folder containing the tsv files in the
        downloaded zip
      citation: `string`, citation for the data set
      url: `string`, url for information about the data set
      label_classes: `list[string]`, the list of classes if the label is
        categorical. If not provided, then the label will be of type
        `tf.float32`.
      process_label: `Function[string, any]`, function taking in the raw value
        of the label and processing it to the form required by the label feature
      **kwargs: keyword arguments forwarded to super.
    versionz1.0.0z6New split API (https://tensorflow.org/datasets/splits)Nr   )superr   __init__tfdscoreVersionr   r   r   r   r   r   r   process_label)
selfr   r   r   r   r   r   r   r$   kwargs	__class__r   r   r    ^   s    
zGlueConfig.__init__)	__name__
__module____qualname____doc__r!   r"   disallow_positional_argsr    __classcell__r   r   r'   r   r   [   s    r   c                   @   s  e Zd ZdZededddiddgddd	ed
dd	ededddiddgdddeddd	ededdddddgdddeddd	ed ed!d"d#d$d%d&gd'd(d)ed*d+d	ed,ed-d.d/dd0d1d2ed3d4ejd5	edbd6ed7d8e	edbd9ed:d8e	edbd;ed<d8e	ed=ed>d?dd@dAdBgddCdDedEdFd	edGedHd.d/ddAdBgddIdJedKdLd	edMedNd.d/ddBdAgddOdPedQdRd	edSedTd.d/dUg dVddWdddXd	gZ
dYdZ Zd[d\ Zdcd^d_Zd`da Zd]S )dGluer   colaa              The Corpus of Linguistic Acceptability consists of English
            acceptability judgments drawn from books and journal articles on
            linguistic theory. Each example is a sequence of words annotated
            with whether it is a grammatical English sentence.sentenceunacceptable
acceptableis_acceptablezhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FCoLA.zip?alt=media&token=46d5e637-3411-4188-bc44-5809b5bfb5f4CoLAa              @article{warstadt2018neural,
              title={Neural Network Acceptability Judgments},
              author={Warstadt, Alex and Singh, Amanpreet and Bowman, Samuel R},
              journal={arXiv preprint arXiv:1805.12471},
              year={2018}
            }zhttps://nyu-mll.github.io/CoLA/)	namedescriptionr   r   r   r   r   r   r   sst2a4              The Stanford Sentiment Treebank consists of sentences from movie reviews and
            human annotations of their sentiment. The task is to predict the sentiment of a
            given sentence. We use the two-way (positive/negative) class split, and use only
            sentence-level labels.negativepositivelabelzhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FSST-2.zip?alt=media&token=aabc5f6b-e466-44a2-b9b4-cf6337f84ac8zSST-2a              @inproceedings{socher2013recursive,
              title={Recursive deep models for semantic compositionality over a sentiment treebank},
              author={Socher, Richard and Perelygin, Alex and Wu, Jean and Chuang, Jason and Manning, Christopher D and Ng, Andrew and Potts, Christopher},
              booktitle={Proceedings of the 2013 conference on empirical methods in natural language processing},
              pages={1631--1642},
              year={2013}
            }z-https://nlp.stanford.edu/sentiment/index.htmlmrpca              The Microsoft Research Paraphrase Corpus (Dolan & Brockett, 2005) is a corpus of
            sentence pairs automatically extracted from online news sources, with human annotations
            for whether the sentences in the pair are semantically equivalent. )r   r   not_equivalent
equivalentQualityMRPCaQ              @inproceedings{dolan2005automatically,
              title={Automatically constructing a corpus of sentential paraphrases},
              author={Dolan, William B and Brockett, Chris},
              booktitle={Proceedings of the Third International Workshop on Paraphrasing (IWP2005)},
              year={2005}
            }z>https://www.microsoft.com/en-us/download/details.aspx?id=52398qqpz            The Quora Question Pairs2 dataset is a collection of question pairs from the
            community question-answering website Quora. The task is to determine whether a
            pair of questions are semantically equivalent.	question1	question2)rC   rD   not_duplicate	duplicateis_duplicatezhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FQQP.zip?alt=media&token=700c6acf-160d-4d89-81d1-de4191d02cb5QQPaI            @online{WinNT,
            author = {Iyer, Shankar and Dandekar, Nikhil and Csernai, Kornel},
            title = {First Quora Dataset Release: Question Pairs},
            year = 2017,
            url = {https://data.quora.com/First-Quora-Dataset-Release-Question-Pairs},
            urldate = {2019-04-03}
          }zAhttps://data.quora.com/First-Quora-Dataset-Release-Question-Pairsstsba*              The Semantic Textual Similarity Benchmark (Cer et al., 2017) is a collection of
            sentence pairs drawn from news headlines, video and image captions, and natural
            language inference data. Each pair is human-annotated with a similarity score
            from 1 to 5.r   r   scorezhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FSTS-B.zip?alt=media&token=bddb94a7-8706-4e0d-a694-1109e12273b5zSTS-Ban              @article{cer2017semeval,
              title={Semeval-2017 task 1: Semantic textual similarity-multilingual and cross-lingual focused evaluation},
              author={Cer, Daniel and Diab, Mona and Agirre, Eneko and Lopez-Gazpio, Inigo and Specia, Lucia},
              journal={arXiv preprint arXiv:1708.00055},
              year={2017}
            }z4http://ixa2.si.ehu.es/stswiki/index.php/STSbenchmark)	r6   r7   r   r   r   r   r   r   r$   mnlia)              The Multi-Genre Natural Language Inference Corpus is a crowdsourced
            collection of sentence pairs with textual entailment annotations. Given a premise sentence
            and a hypothesis sentence, the task is to predict whether the premise entails the hypothesis
            (entailment), contradicts the hypothesis (contradiction), or neither (neutral). The premise sentences are
            gathered from ten different sources, including transcribed speech, fiction, and government reports.
            We use the standard test set, for which we obtained private labels from the authors, and evaluate
            on both the matched (in-domain) and mismatched (cross-domain) section. We also use and recommend
            the SNLI corpus as 550k examples of auxiliary training data.)r6   r7   mnli_mismatchedz          The mismatched validation and test splits from MNLI.
          See the "mnli" BuilderConfig for additional information.mnli_matchedz~          The matched validation and test splits from MNLI.
          See the "mnli" BuilderConfig for additional information.qnlia              The Stanford Question Answering Dataset is a question-answering
            dataset consisting of question-paragraph pairs, where one of the sentences in the paragraph (drawn
            from Wikipedia) contains the answer to the corresponding question (written by an annotator). We
            convert the task into sentence pair classification by forming a pair between each question and each
            sentence in the corresponding context, and filtering out pairs with low lexical overlap between the
            question and the context sentence. The task is to determine whether the context sentence contains
            the answer to the question. This modified version of the original task removes the requirement that
            the model select the exact answer, but also removes the simplifying assumptions that the answer
            is always present in the input and that lexical overlap is a reliable cue.question)rO   r1   r   not_entailmentzhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FQNLIv2.zip?alt=media&token=6fdcf570-0fc5-4631-8456-9505272d1601QNLIa?              @article{rajpurkar2016squad,
              title={Squad: 100,000+ questions for machine comprehension of text},
              author={Rajpurkar, Pranav and Zhang, Jian and Lopyrev, Konstantin and Liang, Percy},
              journal={arXiv preprint arXiv:1606.05250},
              year={2016}
            }z+https://rajpurkar.github.io/SQuAD-explorer/rtea              The Recognizing Textual Entailment (RTE) datasets come from a series of annual textual
            entailment challenges. We combine the data from RTE1 (Dagan et al., 2006), RTE2 (Bar Haim
            et al., 2006), RTE3 (Giampiccolo et al., 2007), and RTE5 (Bentivogli et al., 2009).4 Examples are
            constructed based on news and Wikipedia text. We convert all datasets to a two-class split, where
            for three-class datasets we collapse neutral and contradiction into not entailment, for consistency.zhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FRTE.zip?alt=media&token=5efa7e85-a0bb-4f19-8ea2-9e1840f077fbRTEa              @inproceedings{dagan2005pascal,
              title={The PASCAL recognising textual entailment challenge},
              author={Dagan, Ido and Glickman, Oren and Magnini, Bernardo},
              booktitle={Machine Learning Challenges Workshop},
              pages={177--190},
              year={2005},
              organization={Springer}
            }
            @inproceedings{bar2006second,
              title={The second pascal recognising textual entailment challenge},
              author={Bar-Haim, Roy and Dagan, Ido and Dolan, Bill and Ferro, Lisa and Giampiccolo, Danilo and Magnini, Bernardo and Szpektor, Idan},
              booktitle={Proceedings of the second PASCAL challenges workshop on recognising textual entailment},
              volume={6},
              number={1},
              pages={6--4},
              year={2006},
              organization={Venice}
            }
            @inproceedings{giampiccolo2007third,
              title={The third pascal recognizing textual entailment challenge},
              author={Giampiccolo, Danilo and Magnini, Bernardo and Dagan, Ido and Dolan, Bill},
              booktitle={Proceedings of the ACL-PASCAL workshop on textual entailment and paraphrasing},
              pages={1--9},
              year={2007},
              organization={Association for Computational Linguistics}
            }
            @inproceedings{bentivogli2009fifth,
              title={The Fifth PASCAL Recognizing Textual Entailment Challenge.},
              author={Bentivogli, Luisa and Clark, Peter and Dagan, Ido and Giampiccolo, Danilo},
              booktitle={TAC},
              year={2009}
            }z9https://aclweb.org/aclwiki/Recognizing_Textual_Entailmentwnlia,              The Winograd Schema Challenge (Levesque et al., 2011) is a reading comprehension task
            in which a system must read a sentence with a pronoun and select the referent of that pronoun from
            a list of choices. The examples are manually constructed to foil simple statistical methods: Each
            one is contingent on contextual information provided by a single word or phrase in the sentence.
            To convert the problem into sentence pair classification, we construct sentence pairs by replacing
            the ambiguous pronoun with each possible referent. The task is to predict if the sentence with the
            pronoun substituted is entailed by the original sentence. We use a small evaluation set consisting of
            new examples derived from fiction books that was shared privately by the authors of the original
            corpus. While the included training set is balanced between two classes, the test set is imbalanced
            between them (65% not entailment). Also, due to a data quirk, the development set is adversarial:
            hypotheses are sometimes shared between training and development examples, so if a model memorizes the
            training examples, they will predict the wrong label on corresponding development set
            example. As with QNLI, each example is evaluated separately, so there is not a systematic correspondence
            between a model's score on this task and its score on the unconverted original task. We
            call converted dataset WNLI (Winograd NLI).zhttps://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2FWNLI.zip?alt=media&token=068ad0a0-ded7-4bd7-99a5-5e00222e0fafWNLIaZ              @inproceedings{levesque2012winograd,
              title={The winograd schema challenge},
              author={Levesque, Hector and Davis, Ernest and Morgenstern, Leora},
              booktitle={Thirteenth International Conference on the Principles of Knowledge Representation and Reasoning},
              year={2012}
            }z@https://cs.nyu.edu/faculty/davise/papers/WinogradSchemas/WS.htmlaxae              A manually-curated evaluation dataset for fine-grained analysis of
            system performance on a broad range of linguistic phenomena. This
            dataset evaluates sentence understanding through Natural Language
            Inference (NLI) problems. Use a model trained on MulitNLI to produce
            predictions for this dataset.r   r   zhttps://bit.ly/2BOtOJ7z%https://gluebenchmark.com/diagnosticsc                 C   sz   dd t | jjD }| jjrtjj| jjd|d< ntj	|d< tj
|d< tjj| ttj|| jj| jjd t dS )Nc                 S   s   i | ]}|t j qS r   )r!   featuresText).0text_featurer   r   r   
<dictcomp>  s    
zGlue._info.<locals>.<dictcomp>)namesr;   idx
)builderr7   rW   homepager   )sixiterkeysbuilder_configr   r   r!   rW   
ClassLabeltffloat32int32r"   DatasetInfo_GLUE_DESCRIPTIONFeaturesDictr   r   _GLUE_CITATION)r%   rW   r   r   r   _info  s    


z
Glue._infoc              
   C   s  | j jdkr|| j j}tjjtjj|dddgS | j jdkr-d }|t	t
td}n|| j j}tj|| j j}d }tjjtjjtj|pKddd	|d
d}| j jdkry|td|dddtd|dddtd|dddtd|dddgS | j jdkrtd|dddtd|dddgS | j jdkrtd|dddtd|dddgS |tjjtjjtj|pddd|d
dtjjtjjtj|pddd|d
dgS )NrV   test)	data_filesplitr6   
gen_kwargsr<   )dev_idstrainrm   r=   z	train.tsvrs   rn   ro   
mrpc_filesrK   validation_matcheddevT)matchedvalidation_mismatchedFtest_matchedtest_mismatchedrM   
validationrL   zdev.tsvztest.tsv)rc   r6   downloadr   r!   r"   SplitGeneratorSplitTEST_MRPC_DEV_IDS_MRPC_TRAIN
_MRPC_TESTdownload_and_extractospathjoinr   TRAIN_mnli_split_generator
VALIDATION)r%   
dl_managerrn   r   ru   dl_dirtrain_splitr   r   r   _split_generators  s~   	

zGlue._split_generatorsNc                 #   s|   | j jdkr| j||d}|D ]	}|d |fV  qd S | j j}| j j}| j jdko-|dk}tjj|}	t	j
|	dt	jd}
|rJt	j|	dt	jd}
t|
D ]]\} |r] d  d	 d
  fddt| j jD }||d< | j j v r | j j }|r||vr|rt|nd }|||d< n|d|d< t|D ]}|d u r nq|d |fV  qNW d    d S 1 sw   Y  d S )Nr<   )ru   ro   r]   r0   rm   		delimiterquoting      )r1   r4   c                    s   i | ]	\}}| | qS r   r   )rY   featcolrowr   r   r[     s    z+Glue._generate_examples.<locals>.<dictcomp>r;   )rc   r6   _generate_example_mrpc_filesr$   r   re   iogfileGFilecsv
DictReader
QUOTE_NONEreader	enumeratera   	iteritemsr   r   int
itervalues)r%   rn   ro   ru   examplesexampler$   r   is_cola_non_testfr   nr;   valuer   r   r   _generate_examples  sL   
"zGlue._generate_examplesc           	      c   sv   |dkr?t jj|d '}tj|dtjd}t|D ]\}}|d |d d|dV  qW d    d S 1 s8w   Y  d S t jj|d }tj|dtjd}d	d
 |D }W d    n1 scw   Y  t jj|d @}|	d tj|dtjd}t|D ]$\}}|d |d g|v }||dkkr|d |d t
|d |dV  qW d    d S 1 sw   Y  d S )Nrm   r   r   z	#1 Stringz	#2 Stringr   )r   r   r;   r]   rr   c                 S   s   g | ]
}|d  |d gqS )r   r   r   )rY   r   r   r   r   
<listcomp>6  s    z5Glue._generate_example_mrpc_files.<locals>.<listcomp>rs   r   z#1 IDz#2 IDrw   r@   )re   r   r   r   r   r   r   r   r   seekr   )	r%   ru   ro   r   r   r   r   rr   is_row_in_devr   r   r   r   (  s<   
"


"z!Glue._generate_example_mrpc_filesr   r   )r)   r*   r+   r,   r   textwrapdedentnprf   _MNLI_BASE_KWARGSBUILDER_CONFIGSrl   r   r   r   r   r   r   r   r/      s   !3#   
F2r/   c                 C   s2   t jj| tj|d||rdndf |d ddS )Nz	%s_%s.tsvrx   
mismatchedrt   rp   )r!   r"   r~   r   r   r   )r6   r   ro   rx   r   r   r   r   G  s   r   ) r,   
__future__r   r   r   r   r   r   numpyr   ra   tensorflow.compat.v2compatv2re   tensorflow_datasets.public_api
public_apir!   rk   ri   r   r   r   dictr   r   r"   BuilderConfigr   GeneratorBasedBuilderr/   r   r   r   r   r   <module>   sB   $0   ?