GLUE数据集

此博客介绍了一个用于下载和格式化GLUE数据集(包括CoLA, SST, MRPC等任务)的Python脚本,包括对MRPC数据的特殊处理步骤。脚本提供了从原始源获取数据并进行必要的预处理的方法,确保数据集可用于模型训练。
摘要由CSDN通过智能技术生成

网盘链接:
链接:https://pan.baidu.com/s/1DGlGexQkBHUKY4wxZrn5wA
提取码:yuhu
数据集目录:
在这里插入图片描述

脚本代码:(需要科学上网)

''' Script for downloading all GLUE data.
Note: for legal reasons, we are unable to host MRPC.
You can either use the version hosted by the SentEval team, which is already tokenized,
or you can download the original data from (https://download.microsoft.com/download/D/4/6/D46FF87A-F6B9-4252-AA8B-3604ED519838/MSRParaphraseCorpus.msi) and extract the data from it manually.
For Windows users, you can run the .msi file. For Mac and Linux users, consider an external library such as 'cabextract' (see below for an example).
You should then rename and place specific files in a folder (see below for an example).
mkdir MRPC
cabextract MSRParaphraseCorpus.msi -d MRPC
cat MRPC/_2DEC3DBE877E4DB192D17C0256E90F1D | tr -d $'\r' > MRPC/msr_paraphrase_train.txt
cat MRPC/_D7B391F9EAFF4B1B8BCE8F21B20B1B61 | tr -d $'\r' > MRPC/msr_paraphrase_test.txt
rm MRPC/_*
rm MSRParaphraseCorpus.msi
1/30/19: It looks like SentEval is no longer hosting their extracted and tokenized MRPC data, so you'll need to download the data from the original source for now.
2/11/19: It looks like SentEval actually *is* hosting the extracted data. Hooray!
'''
import io
import os
import sys
import shutil
import argparse
import tempfile
import urllib.request
import zipfile

TASKS = ["CoLA", "SST", "MRPC", "QQP", "STS", "MNLI", "QNLI", "RTE", "WNLI", "diagnostic"]
TASK2PATH = {"CoLA": 'https://dl.fbaipublicfiles.com/glue/data/CoLA.zip',
             "SST": 'https://dl.fbaipublicfiles.com/glue/data/SST-2.zip',
             "QQP": 'https://dl.fbaipublicfiles.com/glue/data/STS-B.zip',
             "STS": 'https://dl.fbaipublicfiles.com/glue/data/QQP-clean.zip',
             "MNLI": 'https://dl.fbaipublicfiles.com/glue/data/MNLI.zip',
             "QNLI": 'https://dl.fbaipublicfiles.com/glue/data/QNLIv2.zip',
             "RTE": 'https://dl.fbaipublicfiles.com/glue/data/RTE.zip',
             "WNLI": 'https://dl.fbaipublicfiles.com/glue/data/WNLI.zip',
             "diagnostic": 'https://dl.fbaipublicfiles.com/glue/data/AX.tsv'}

MRPC_TRAIN = 'https://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_train.txt'
MRPC_TEST = 'https://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_test.txt'


def download_and_extract(task, data_dir):
    print("Downloading and extracting %s..." % task)
    if task == "MNLI":
        print(
            "\tNote (12/10/20): This script no longer downloads SNLI. You will need to manually download and format the data to use SNLI.")
    data_file = "%s.zip" % task
    urllib.request.urlretrieve(TASK2PATH[task], data_file)
    with zipfile.ZipFile(data_file) as zip_ref:
        zip_ref.extractall(data_dir)
    os.remove(data_file)
    print("\tCompleted!")


def format_mrpc(data_dir, path_to_data):
    print("Processing MRPC...")
    mrpc_dir = os.path.join(data_dir, "MRPC")
    if not os.path.isdir(mrpc_dir):
        os.mkdir(mrpc_dir)
    if path_to_data:
        mrpc_train_file = os.path.join(path_to_data, "msr_paraphrase_train.txt")
        mrpc_test_file = os.path.join(path_to_data, "msr_paraphrase_test.txt")
    else:
        try:
            mrpc_train_file = os.path.join(mrpc_dir, "msr_paraphrase_train.txt")
            mrpc_test_file = os.path.join(mrpc_dir, "msr_paraphrase_test.txt")
            urllib.request.urlretrieve(MRPC_TRAIN, mrpc_train_file)
            urllib.request.urlretrieve(MRPC_TEST, mrpc_test_file)
        except urllib.error.HTTPError:
            print("Error downloading MRPC")
            return
    assert os.path.isfile(mrpc_train_file), "Train data not found at %s" % mrpc_train_file
    assert os.path.isfile(mrpc_test_file), "Test data not found at %s" % mrpc_test_file

    with io.open(mrpc_test_file, encoding='utf-8') as data_fh, \
            io.open(os.path.join(mrpc_dir, "test.tsv"), 'w', encoding='utf-8') as test_fh:
        header = data_fh.readline()
        test_fh.write("index\t#1 ID\t#2 ID\t#1 String\t#2 String\n")
        for idx, row in enumerate(data_fh):
            label, id1, id2, s1, s2 = row.strip().split('\t')
            test_fh.write("%d\t%s\t%s\t%s\t%s\n" % (idx, id1, id2, s1, s2))

    try:
        urllib.request.urlretrieve(TASK2PATH["MRPC"], os.path.join(mrpc_dir, "dev_ids.tsv"))
    except KeyError or urllib.error.HTTPError:
        print("\tError downloading standard development IDs for MRPC. You will need to manually split your data.")
        return

    dev_ids = []
    with io.open(os.path.join(mrpc_dir, "dev_ids.tsv"), encoding='utf-8') as ids_fh:
        for row in ids_fh:
            dev_ids.append(row.strip().split('\t'))

    with io.open(mrpc_train_file, encoding='utf-8') as data_fh, \
            io.open(os.path.join(mrpc_dir, "train.tsv"), 'w', encoding='utf-8') as train_fh, \
            io.open(os.path.join(mrpc_dir, "dev.tsv"), 'w', encoding='utf-8') as dev_fh:
        header = data_fh.readline()
        train_fh.write(header)
        dev_fh.write(header)
        for row in data_fh:
            label, id1, id2, s1, s2 = row.strip().split('\t')
            if [id1, id2] in dev_ids:
                dev_fh.write("%s\t%s\t%s\t%s\t%s\n" % (label, id1, id2, s1, s2))
            else:
                train_fh.write("%s\t%s\t%s\t%s\t%s\n" % (label, id1, id2, s1, s2))

    print("\tCompleted!")


def download_diagnostic(data_dir):
    print("Downloading and extracting diagnostic...")
    if not os.path.isdir(os.path.join(data_dir, "diagnostic")):
        os.mkdir(os.path.join(data_dir, "diagnostic"))
    data_file = os.path.join(data_dir, "diagnostic", "diagnostic.tsv")
    urllib.request.urlretrieve(TASK2PATH["diagnostic"], data_file)
    print("\tCompleted!")
    return


def get_tasks(task_names):
    task_names = task_names.split(',')
    if "all" in task_names:
        tasks = TASKS
    else:
        tasks = []
        for task_name in task_names:
            assert task_name in TASKS, "Task %s not found!" % task_name
            tasks.append(task_name)
    return tasks


def main(arguments):
    parser = argparse.ArgumentParser()
    parser.add_argument('--data_dir', help='directory to save data to', type=str, default='glue_data')
    parser.add_argument('--tasks', help='tasks to download data for as a comma separated string',
                        type=str, default='all')
    parser.add_argument('--path_to_mrpc',
                        help='path to directory containing extracted MRPC data, msr_paraphrase_train.txt and msr_paraphrase_text.txt',
                        type=str, default='')
    args = parser.parse_args(arguments)

    if not os.path.isdir(args.data_dir):
        os.mkdir(args.data_dir)
    tasks = get_tasks(args.tasks)

    for task in tasks:
        if task == 'MRPC':
            format_mrpc(args.data_dir, args.path_to_mrpc)
        elif task == 'diagnostic':
            download_diagnostic(args.data_dir)
        else:
            download_and_extract(task, args.data_dir)


if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))
  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
### 回答1: GLUE(General Language Understanding Evaluation)任务数据集是一个被广泛应用于自然语言处理(NLP)任务评估的标准数据集。它由来自9个不同任务的多个数据集组成,包括情感分类、自然语言推理、命名实体识别等任务。GLUE任务数据集的格式一般如下: 1. 训练集(Training set):用于训练模型的数据集。通常包含大量的语言样本,包括输入句子及其对应的标签或目标。 2. 验证集(Validation set):用于在训练过程中评估模型性能的数据集。通常由从训练集中划分出的一部分样本组成,不参与训练过程,用于调整模型的超参数或进行早期停止等。 3. 测试集(Test set):用于最终评估模型性能的数据集。通常由不参与模型训练和验证的样本组成。在完成模型训练和调参后,使用测试集对模型进行评估,以了解模型的泛化能力和性能。 对于每个任务,GLUE数据集一般包括输入句子或文本数据,以及对应的标签或目标。例如,对于情感分类任务,输入句子是一个句子或文本段落,标签是该文本的情感类别,如正面、负面或中性。 在进行实验或研究时,我们可以使用GLUE数据集进行模型训练、验证和测试,以评估模型在各种NLP任务上的效果。通过对不同任务之间的性能进行比较,可以帮助我们了解和改进模型在不同语义理解任务上的表现,并推动NLP研究和应用的发展。 ### 回答2: GLUE是指General Language Understanding Evaluation,在自然语言处理领域广泛使用的一个基准任务。GLUE任务数据集格式指的是参与GLUE任务的数据集的数据格式要求。 GLUE任务数据集的格式要求如下: 1. 数据集应具有统一的标注格式:数据集中的语料需要按照一致的格式进行标注,以保证不同任务之间的可比性。 2. 输入格式要求:对于多项选择问题的任务,输入数据集应以问题和选项的形式提供。对于分类任务,输入数据集应以文本对或者单个句子的形式提供。 3. 标签格式要求:数据集中每个样本都应标注有相应的标签,用于指示样本所属的类别或是正确的答案。 4. 样本分割要求:数据集应以训练集、开发集和测试集的形式划分,并按照一定比例划分样本。常见的划分比例是70%的训练集、10%的开发集和20%的测试集。 5. 数据集质量要求:数据集应具有高质量的标注和丰富的样本。标注应准确无误,样本应能够涵盖各种语言结构和语义。 6. 数据集大小要求:数据集的规模应足够大,以确保模型能够充分学习和泛化。通常来说,数据集的大小应在几千到几百万条之间。 总之,GLUE任务数据集格式要求数据集的标注、格式、分割和质量都要符合一定的标准,以保证不同任务之间的可比性和模型的准确性和泛化性。 ### 回答3: GLUE(General Language Understanding Evaluation)任务数据集是一个广泛使用的自然语言处理数据集,旨在评估和比较不同模型在各种语言理解任务上的性能。它包含了9个不同的任务,包括自然语言推断、句子对匹配、情感分类等。 GLUE任务数据集的格式可以分为输入和输出两个部分。输入部分通常由两个文本序列组成,例如问题和答案、句子1和句子2等。而输出部分通常是一个标签,表示对应的任务类别。不同的任务可能有不同的标签集,例如True/False表示推断任务中的正确与错误,Positive/Negative表示情感分类任务中的积极与消极等。 在处理GLUE任务数据集时,我们通常需要使用机器学习模型来学习输入文本序列之间的关系,并进行相应的分类、匹配或预测。模型可以利用双向Transformer架构等深度学习方法来提取输入文本的语义信息,并通过训练来优化模型参数。 为了评估模型在GLUE任务数据集上的性能,我们可以使用各种评估指标,例如准确率、精确率、召回率、F1分数等。这些指标可以帮助我们比较不同模型的表现,并选择最优的模型进行进一步应用和研究。 总而言之,GLUE任务数据集提供了一个标准的、多样化的自然语言理解评估平台,帮助研究人员和开发者进行模型的训练和性能比较。通过合理利用这些数据集和方法,我们可以不断推动自然语言处理技术的发展。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

与 或

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值