pietrolesci
commited on
Commit
•
07695d5
1
Parent(s):
f15dcb1
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Overview
|
2 |
+
|
3 |
+
Original dataset page [here](https://abhilasharavichander.github.io/NLI_StressTest/) and dataset available [here](https://drive.google.com/open?id=1faGA5pHdu5Co8rFhnXn-6jbBYC2R1dhw).
|
4 |
+
|
5 |
+
|
6 |
+
## Dataset curation
|
7 |
+
Added new column `label` with encoded labels with the following mapping
|
8 |
+
|
9 |
+
```
|
10 |
+
{"entailment": 0, "neutral": 1, "contradiction": 2}
|
11 |
+
```
|
12 |
+
|
13 |
+
and the columns with parse information are dropped as they are not well formatted.
|
14 |
+
|
15 |
+
Also, the name of the file from which each instance comes is added in the column `dtype`.
|
16 |
+
|
17 |
+
|
18 |
+
## Code to create the dataset
|
19 |
+
|
20 |
+
```python
|
21 |
+
import pandas as pd
|
22 |
+
from datasets import Dataset, ClassLabel, Value, Features, DatasetDict
|
23 |
+
import json
|
24 |
+
from pathlib import Path
|
25 |
+
|
26 |
+
|
27 |
+
# load data
|
28 |
+
ds = {}
|
29 |
+
for i in path.rglob("<path to folder>/*.jsonl"):
|
30 |
+
print(i)
|
31 |
+
name = str(i).split("/")[0].lower()
|
32 |
+
dtype = str(i).split("/")[1].lower()
|
33 |
+
|
34 |
+
# read data
|
35 |
+
with i.open("r") as fl:
|
36 |
+
df = pd.DataFrame([json.loads(line) for line in fl])
|
37 |
+
|
38 |
+
# select columns
|
39 |
+
df = df.loc[:, ["sentence1", "sentence2", "gold_label"]]
|
40 |
+
|
41 |
+
# add file name as column
|
42 |
+
df["dtype"] = dtype
|
43 |
+
|
44 |
+
# encode labels
|
45 |
+
df["label"] = df["gold_label"].map({"entailment": 0, "neutral": 1, "contradiction": 2})
|
46 |
+
ds[name] = df
|
47 |
+
|
48 |
+
# cast to dataset
|
49 |
+
features = Features(
|
50 |
+
{
|
51 |
+
"sentence1": Value(dtype="string"),
|
52 |
+
"sentence2": Value(dtype="string"),
|
53 |
+
"label": ClassLabel(num_classes=3, names=["entailment", "neutral", "contradiction"]),
|
54 |
+
"dtype": Value(dtype="string"),
|
55 |
+
"gold_label": Value(dtype="string"),
|
56 |
+
}
|
57 |
+
)
|
58 |
+
ds = DatasetDict({k: Dataset.from_pandas(v, features=features) for k, v in ds.items()})
|
59 |
+
ds.push_to_hub("pietrolesci/stress_tests_nli", token="<token>")
|
60 |
+
|
61 |
+
|
62 |
+
# check overlap between splits
|
63 |
+
from itertools import combinations
|
64 |
+
for i, j in combinations(ds.keys(), 2):
|
65 |
+
print(
|
66 |
+
f"{i} - {j}: ",
|
67 |
+
pd.merge(
|
68 |
+
ds[i].to_pandas(),
|
69 |
+
ds[j].to_pandas(),
|
70 |
+
on=["sentence1", "sentence2", "label"],
|
71 |
+
how="inner",
|
72 |
+
).shape[0],
|
73 |
+
)
|
74 |
+
#> numerical_reasoning - negation: 0
|
75 |
+
#> numerical_reasoning - length_mismatch: 0
|
76 |
+
#> numerical_reasoning - spelling_error: 0
|
77 |
+
#> numerical_reasoning - word_overlap: 0
|
78 |
+
#> numerical_reasoning - antonym: 0
|
79 |
+
#> negation - length_mismatch: 0
|
80 |
+
#> negation - spelling_error: 0
|
81 |
+
#> negation - word_overlap: 0
|
82 |
+
#> negation - antonym: 0
|
83 |
+
#> length_mismatch - spelling_error: 0
|
84 |
+
#> length_mismatch - word_overlap: 0
|
85 |
+
#> length_mismatch - antonym: 0
|
86 |
+
#> spelling_error - word_overlap: 0
|
87 |
+
#> spelling_error - antonym: 0
|
88 |
+
#> word_overlap - antonym: 0
|
89 |
+
```
|