conj_nli / README.md
pietrolesci's picture
Update README.md
32fef37
|
raw
history blame
2.05 kB

Overview

The original dataset can be found here. It has been proposed in ConjNLI: Natural Language Inference Over Conjunctive Sentences.

This dataset is a stress test for natural language inference over conjunctive sentences, where the premise differs from the hypothesis by conjuncts removed, added, or replaced.

Dataset curation

No curation is performed. This dataset is "as-is". The label mapping is the usual {"entailment": 0, "neutral": 1, "contradiction": 2} used in NLI datasets.

Code to create the dataset

import pandas as pd
from datasets import Dataset, ClassLabel, Value, Features, DatasetDict

# download data from repo https://github.com/swarnaHub/ConjNLI
paths = {
    "train": "<path_to_folder>/ConjNLI-master/data/NLI/adversarial_train_15k.tsv",
    "dev": "<path_to_folder>/ConjNLI-master/data/NLI/conj_dev.tsv",
    "test": "<path_to_folder>/ConjNLI-master/data/NLI/conj_test.tsv",
}

if __name__ =="__main__":
    dataset_splits = {}    
    for split, path in paths.items():
        
        # read dataset split
        df = pd.read_csv(paths[split], sep="\t")
    
        # encode labels using the default mapping used by other nli datasets
        # i.e, entailment: 0, neutral: 1, contradiction: 2
        df.columns = df.columns.str.lower()
        if not "test" in path:
            df["label"] = df["label"].map({"entailment": 0, "neutral": 1, "contradiction": 2})
        else:
            df["label"] = -1
    
        # cast to dataset
        features = Features({
            "premise": Value(dtype="string", id=None),
            "hypothesis": Value(dtype="string", id=None),
            "label": ClassLabel(num_classes=3, names=["entailment", "neutral", "contradiction"]),
        })
        dataset = Dataset.from_pandas(df, features=features)
        dataset_splits[split] = dataset
    
    conj_nli = DatasetDict(dataset_splits)
    conj_nli.push_to_hub("pietrolesci/conj_nli", token="<token>")