pietrolesci
commited on
Commit
•
f07459a
1
Parent(s):
ecafb18
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Overview
|
2 |
+
|
3 |
+
Original dataset [here](https://github.com/aylai/MultiPremiseEntailment).
|
4 |
+
|
5 |
+
|
6 |
+
## Dataset curation
|
7 |
+
Same data and splits as the original. The following columns have been added:
|
8 |
+
|
9 |
+
- `premise`: concatenation of `premise1`, `premise2`, `premise3`, and `premise4`
|
10 |
+
- `label`: encoded `gold_label` with the following mapping `{"entailment": 0, "neutral": 1, "contradiction": 2}`
|
11 |
+
|
12 |
+
|
13 |
+
## Code to create the dataset
|
14 |
+
|
15 |
+
```python
|
16 |
+
import pandas as pd
|
17 |
+
from datasets import Features, Value, ClassLabel, Dataset, DatasetDict
|
18 |
+
from pathlib import Path
|
19 |
+
|
20 |
+
|
21 |
+
# read data
|
22 |
+
path = Path(".")
|
23 |
+
datasets = {}
|
24 |
+
for dataset_path in path.rglob("*.txt"):
|
25 |
+
df = pd.read_csv(dataset_path, sep="\t")
|
26 |
+
datasets[dataset_path.name.split("_")[1].split(".")[0]] = df
|
27 |
+
|
28 |
+
|
29 |
+
ds = {}
|
30 |
+
for name, df_ in datasets.items():
|
31 |
+
df = df_.copy()
|
32 |
+
|
33 |
+
# fix parsing error for dev split
|
34 |
+
if name == "dev":
|
35 |
+
# fix parsing error
|
36 |
+
df.loc[df["contradiction_judgments"] == "3 contradiction", "contradiction_judgments"] = 3
|
37 |
+
df.loc[df["gold_label"].isna(), "gold_label"] = "contradiction"
|
38 |
+
|
39 |
+
# check no nan
|
40 |
+
assert df.isna().sum().sum() == 0
|
41 |
+
|
42 |
+
# fix dtypes
|
43 |
+
for col in ("entailment_judgments", "neutral_judgments", "contradiction_judgments"):
|
44 |
+
df[col] = df[col].astype(int)
|
45 |
+
|
46 |
+
# fix premise column
|
47 |
+
for i in range(1, 4 + 1):
|
48 |
+
df[f"premise{i}"] = df[f"premise{i}"].str.split("/", expand=True)[1]
|
49 |
+
df["premise"] = df[[f"premise{i}" for i in range(1, 4 + 1)]].agg(" ".join, axis=1)
|
50 |
+
|
51 |
+
# encode labels
|
52 |
+
df["label"] = df["gold_label"].map({"entailment": 0, "neutral": 1, "contradiction": 2})
|
53 |
+
|
54 |
+
# cast to dataset
|
55 |
+
features = Features({
|
56 |
+
"premise1": Value(dtype="string", id=None),
|
57 |
+
"premise2": Value(dtype="string", id=None),
|
58 |
+
"premise3": Value(dtype="string", id=None),
|
59 |
+
"premise4": Value(dtype="string", id=None),
|
60 |
+
"premise": Value(dtype="string", id=None),
|
61 |
+
"hypothesis": Value(dtype="string", id=None),
|
62 |
+
"entailment_judgments": Value(dtype="int32"),
|
63 |
+
"neutral_judgments": Value(dtype="int32"),
|
64 |
+
"contradiction_judgments": Value(dtype="int32"),
|
65 |
+
"gold_label": Value(dtype="string"),
|
66 |
+
"label": ClassLabel(num_classes=3, names=["entailment", "neutral", "contradiction"]),
|
67 |
+
})
|
68 |
+
|
69 |
+
ds[name] = Dataset.from_pandas(df, features=features)
|
70 |
+
|
71 |
+
# push to hub
|
72 |
+
ds = DatasetDict(ds)
|
73 |
+
ds.push_to_hub("mpe", token="<token>")
|
74 |
+
```
|