pietrolesci/copa_nli
收藏Hugging Face2022-04-25 更新2024-03-04 收录
下载链接:
https://hf-mirror.com/datasets/pietrolesci/copa_nli
下载链接
链接失效反馈官方服务:
资源简介:
这是一个完整的自然语言推理(NLI)数据集,源自COPA格式,经过整理转换为NLI格式。数据集包含前提和假设两部分,以及相应的标签,标签通过编码映射为not_entailment(0)和entailment(1)。数据集通过Python脚本生成,并已上传至HuggingFace Hub。
概述
原始数据集可从[此处](https://people.ict.usc.edu/~gordon/copa.html)获取。当前数据集源自[该代码仓库](https://github.com/felipessalvatore/NLI_datasets)。本数据集为完整版本。
# 数据整理流程
其数据整理流程与[该代码仓库](https://github.com/felipessalvatore/NLI_datasets)中采用的流程一致,具体转换如下:
从原始常识合理选择(Choice of Plausible Alternatives, COPA)格式:
| 前提(premise) | 选项1 | 选项2 | 标签 |
|---|---|---|---|
| 我的影子投射在草地上 | 太阳正在升起 | 草地被修剪 | 0 |
转换为自然语言推理(Natural Language Inference, NLI)格式:
| 前提 | 假设(hypothesis) | 标签 |
|---|---|---|
| 我的影子投射在草地上 | 太阳正在升起 | 蕴含(entailment) |
| 我的影子投射在草地上 | 草地被修剪 | 不蕴含(not_entailment) |
此外,标签采用如下映射进行编码:`{"not_entailment": 0, "entailment": 1}`
## 数据集生成代码
python
import pandas as pd
from datasets import Features, Value, ClassLabel, Dataset, DatasetDict, load_dataset
from pathlib import Path
# 读取数据
path = Path("./nli_datasets")
datasets = {}
for dataset_path in path.iterdir():
datasets[dataset_path.name] = {}
for name in dataset_path.iterdir():
df = pd.read_csv(name)
datasets[dataset_path.name][name.name.split(".")[0]] = df
# 合并所有数据划分
df = pd.concat(list(datasets["copa"].values()))
# 编码标签
df["label"] = df["label"].map({"not_entailment": 0, "entailment": 1})
# 转换为数据集对象
features = Features({
"premise": Value(dtype="string", id=None),
"hypothesis": Value(dtype="string", id=None),
"label": ClassLabel(num_classes=2, names=["not_entailment", "entailment"]),
})
ds = Dataset.from_pandas(df, features=features)
ds.push_to_hub("copa_nli", token="<token>")
提供机构:
pietrolesci原始信息汇总
数据集概述
- 原始数据来源:原始数据集链接
- 当前数据集提取自:GitHub仓库链接
- 数据集类型:完整数据集
数据集整理
-
数据格式转换:
-
原始格式:
premise choice1 choice2 label My body cast a shadow over the grass The sun was rising The grass was cut 0 -
转换后的NLI格式:
premise hypothesis label My body cast a shadow over the grass The sun was rising entailment My body cast a shadow over the grass The grass was cut not_entailment
-
-
标签编码映射:
{"not_entailment": 0, "entailment": 1}
数据集生成代码
- 数据读取与合并:使用
pandas读取并合并所有数据分割。 - 标签编码:将标签映射为数字编码。
- 数据集创建:使用
datasets库创建数据集,定义特征如下:premise:字符串类型hypothesis:字符串类型label:类别标签,包含两个类别not_entailment和entailment
- 数据集上传:将数据集上传至Hugging Face Hub,命名为
copa_nli。



